Compare commits

...
Author SHA1 Message Date
Martin BallandClaude Sonnet 5.5 8dbfa312f4 #8986: vertical-text arrows continue across pages and stop at a table cell's edge
turned_line searches the adjacent page when the page's flow has no next/previous line, and
clamps the initial goal with caret_limit like caret_on. With no adjacent line inside a table
cell or text box, Left/Right stop instead of falling back to lr_along and leaving it. Adds a
command-level typing test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-05 04:43:09 +00:00
3 changed files with 47 additions and 16 deletions
+3 -1
View File
@@ -128,7 +128,7 @@ fn turn(s: &mut Session) -> Option<TextDirection> {
}
/// Vertical text: to the next (`next`) or previous line, at the same distance along it. With no
/// such line in the caret's flow (a table cell's only line, the last column), Left/Right step along
/// such line in the caret's flow, Left/Right stop in a table cell or text box and otherwise step along
/// the text as they did before (`is_left`: backwards).
fn line_step(s: &mut Session, v: &Value, next: bool, is_left: bool) -> CmdResult {
let ext = extend(v);
@@ -145,6 +145,8 @@ fn line_step(s: &mut Session, v: &Value, next: bool, is_left: bool) -> CmdResult
s.goal_x = Some(g);
p
}
// Inside a table cell or text box the caret stops at the edge rather than leaving it.
None if from.path.0.len() > 1 => return sel_result(s),
None => return lr_along(s, v, is_left),
};
let gx = s.goal_x;
+16
View File
@@ -4812,3 +4812,19 @@ fn enter_in_a_drop_cap_paragraph_makes_a_normal_paragraph() {
assert_eq!(second.drop_cap_font, None, "{position}");
}
}
/// #8986: in top-to-bottom text Left/Right change line (lines stack leftwards), keeping the
/// distance along the line, and stop at the first/last line of a table cell.
#[test]
fn arrows_in_vertical_text_change_line_and_stop_in_a_cell() {
let mut d = wordcraft_doc::Document::from_text("abc\ndef");
d.last_section.text_direction = wordcraft_doc::props::TextDirection::Down;
let mut s = Session::new(d);
s.sel = crate::Selection::caret(Pos::body(0, 1));
run(&mut s, "caret.left", json!({}));
assert_eq!(s.sel.focus, Pos::body(1, 1), "Left goes to the next, leftward line");
run(&mut s, "caret.right", json!({}));
assert_eq!(s.sel.focus, Pos::body(0, 1));
run(&mut s, "caret.left", json!({"extend": true}));
assert!(!s.sel.is_collapsed(), "Shift+Left extends over the line change");
}
+28 -15
View File
@@ -801,25 +801,38 @@ impl DocLayout {
/// caret's flow on the page.
pub fn turned_line(&self, pos: &Pos, goal: Option<f32>, next: bool, page_hint: usize) -> Option<(Pos, f32)> {
let c = self.caret_on(pos, page_hint)?;
let lines: Vec<(&Path, &std::sync::Arc<ParaLayout>, usize)> = items_of(self.pages.get(c.page)?, pos.story)
.filter_map(|it| match it {
Placed::Lines { story, path, para, l0, l1, turn, .. }
if *story == pos.story && turn.is_turned() && path.parent() == pos.path.parent() =>
{
Some((path, para, *l0, *l1))
}
_ => None,
})
.flat_map(|(path, para, l0, l1)| (l0..l1).map(move |li| (path, para, li)))
.collect();
let flow = |pi: usize| -> Option<Vec<(&Path, &std::sync::Arc<ParaLayout>, usize)>> {
Some(
items_of(self.pages.get(pi)?, pos.story)
.filter_map(|it| match it {
Placed::Lines { story, path, para, l0, l1, turn, .. }
if *story == pos.story && turn.is_turned() && path.parent() == pos.path.parent() =>
{
Some((path, para, *l0, *l1))
}
_ => None,
})
.flat_map(|(path, para, l0, l1)| (l0..l1).map(move |li| (path, para, li)))
.collect(),
)
};
let lines = flow(c.page)?;
let here = lines.iter().position(|(path, para, li)| *path == &pos.path && *li == para.line_of(pos.off))?;
let (path, para, li) = lines.get(if next { here + 1 } else { here.checked_sub(1)? })?;
// Past the page's first/last line, the flow goes on at the adjacent page's last/first.
let target = if next { lines.get(here + 1).copied() } else { here.checked_sub(1).and_then(|i| lines.get(i).copied()) }.or_else(|| {
let other = flow(if next { c.page + 1 } else { c.page.checked_sub(1)? })?;
if next { other.first().copied() } else { other.last().copied() }
});
let (path, para, li) = target?;
let gx = match goal {
Some(g) => g,
None => lines[here].1.x_of(lines[here].2, pos.off)?,
None => {
let x = lines[here].1.x_of(lines[here].2, pos.off)?;
lines[here].1.caret_limit(lines[here].2).map_or(x, |m| x.min(m))
}
};
let off = para.off_at_x(*li, gx);
Some((Pos { story: pos.story, path: (*path).clone(), off }, gx))
let off = para.off_at_x(li, gx);
Some((Pos { story: pos.story, path: path.clone(), off }, gx))
}
/// The position one line up (`dir < 0`) or down from `pos`, keeping `goal_x` (page x).