mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-05 04:07:03 -06:00
Merge pull request #9176
This commit is contained in:
@@ -4876,3 +4876,81 @@ fn enter_in_a_drop_cap_paragraph_makes_a_normal_paragraph() {
|
||||
assert_eq!(second.drop_cap_font, None, "{position}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #8986: Up/Down step along vertical lines and Left/Right cross stacked lines (preserving
|
||||
/// goal distance, collapsing or extending selections, and falling back along the line when
|
||||
/// there is no adjacent line in the flow) for both `tbRl` (`"down"`) and `btLr` (`"up"`).
|
||||
#[test]
|
||||
fn arrow_keys_navigate_vertical_text() {
|
||||
use wordcraft_doc::Path;
|
||||
|
||||
let set = |s: &mut Session, anchor: Pos, focus: Pos| {
|
||||
s.sel = crate::Selection { anchor, focus };
|
||||
s.goal_x = None;
|
||||
};
|
||||
|
||||
// 1. Top-to-bottom (`tbRl`): Down advances, Up retreats; Left goes to next line, Right to previous.
|
||||
let mut doc = typed("abcd\nx\nabcd");
|
||||
run(&mut doc, "layout.textDirection", json!({"value": "down"}));
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(0, 1));
|
||||
run(&mut doc, "caret.down", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(0, 2), "tbRl Down advances along the line");
|
||||
run(&mut doc, "caret.up", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(0, 1), "tbRl Up moves back along the line");
|
||||
|
||||
set(&mut doc, Pos::body(0, 3), Pos::body(0, 3));
|
||||
run(&mut doc, "caret.left", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(1, 1), "tbRl Left steps to the shorter next line");
|
||||
run(&mut doc, "caret.left", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(2, 3), "tbRl Left keeps goal distance across the short middle line");
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(1, 1), "tbRl Right steps to the previous line");
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(0, 3), "tbRl Right returns to offset 3 with preserved goal distance");
|
||||
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(2, 2));
|
||||
run(&mut doc, "caret.left", json!({}));
|
||||
assert!(doc.sel.is_collapsed() && doc.sel.focus == Pos::body(2, 2), "tbRl Left collapses selection to end");
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(2, 2));
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert!(doc.sel.is_collapsed() && doc.sel.focus == Pos::body(0, 1), "tbRl Right collapses selection to start");
|
||||
|
||||
set(&mut doc, Pos::body(1, 1), Pos::body(1, 1));
|
||||
run(&mut doc, "caret.left", json!({"extend": true}));
|
||||
assert_eq!((&doc.sel.anchor, &doc.sel.focus), (&Pos::body(1, 1), &Pos::body(2, 1)), "extend=true keeps anchor across lines");
|
||||
|
||||
// 2. Bottom-to-top (`btLr`): Up advances, Down retreats; Right goes to next line, Left to previous.
|
||||
run(&mut doc, "layout.textDirection", json!({"value": "up"}));
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(0, 1));
|
||||
run(&mut doc, "caret.up", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(0, 2), "btLr Up advances along the line");
|
||||
run(&mut doc, "caret.down", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(0, 1), "btLr Down moves back along the line");
|
||||
|
||||
set(&mut doc, Pos::body(0, 3), Pos::body(0, 3));
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(1, 1), "btLr Right steps to the shorter next line");
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(2, 3), "btLr Right keeps goal distance across the short middle line");
|
||||
run(&mut doc, "caret.left", json!({}));
|
||||
assert_eq!(doc.sel.focus, Pos::body(1, 1), "btLr Left steps to the previous line");
|
||||
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(2, 2));
|
||||
run(&mut doc, "caret.left", json!({}));
|
||||
assert!(doc.sel.is_collapsed() && doc.sel.focus == Pos::body(0, 1), "btLr Left collapses selection to start");
|
||||
set(&mut doc, Pos::body(0, 1), Pos::body(2, 2));
|
||||
run(&mut doc, "caret.right", json!({}));
|
||||
assert!(doc.sel.is_collapsed() && doc.sel.focus == Pos::body(2, 2), "btLr Right collapses selection to end");
|
||||
|
||||
// 3. Single-line vertical table cell fallback: Left/Right stay inside the cell and step along its text.
|
||||
let mut tbl = s();
|
||||
run(&mut tbl, "insert.table", json!({"rows": 1, "cols": 2}));
|
||||
run(&mut tbl, "text.insert", json!({"text": "abc"}));
|
||||
run(&mut tbl, "table.textDirection", json!({"value": "down"}));
|
||||
let cell0 = |off| Pos { story: StoryRef::Body, path: Path(vec![0, 0, 0, 0]), off };
|
||||
set(&mut tbl, cell0(2), cell0(2));
|
||||
run(&mut tbl, "caret.left", json!({}));
|
||||
assert_eq!(tbl.sel.focus, cell0(1), "single-line vertical cell Left falls back backwards along text");
|
||||
run(&mut tbl, "caret.right", json!({}));
|
||||
assert_eq!(tbl.sel.focus, cell0(2), "single-line vertical cell Right falls back forwards along text");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user