mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-03 22:40:27 +00:00
Merge pull request #8599
This commit is contained in:
@@ -92,6 +92,11 @@ const NOT_ONE_LINE: [char; 7] = {
|
||||
|
||||
/// The raw text of the selection when it is one run of one paragraph without breaks, pictures or fields.
|
||||
fn one_line_selection(s: &Session) -> Option<&str> {
|
||||
// A column (block) selection has both ends in one paragraph but holds a piece of each line it
|
||||
// covers: it isn't one line of text (#8581).
|
||||
if s.column_segments().is_some_and(|segs| !segs.is_empty()) {
|
||||
return None;
|
||||
}
|
||||
let (a, b) = s.sel.ordered();
|
||||
if a.story != b.story || a.path != b.path {
|
||||
return None;
|
||||
|
||||
@@ -1653,6 +1653,38 @@ fn a_link_keeps_a_selection_it_cannot_retype() {
|
||||
assert_eq!(s.doc.field_ranges(StoryRef::Body).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_column_selection_in_one_paragraph_is_not_one_line() {
|
||||
// A column (block) selection over the wrapped lines of one paragraph: both its ends are in
|
||||
// that paragraph, but it holds a piece of each line, so Word shows <<Selection in Document>>
|
||||
// for it and the text to display can't retype it (#8581).
|
||||
let mut s = typed("alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigma tau");
|
||||
let (first, second) = {
|
||||
let l = s.layout();
|
||||
let len = s.doc.para_at(&Pos::body(0, 0)).unwrap().text.len();
|
||||
let mut top = None;
|
||||
let mut first = None;
|
||||
let mut second = None;
|
||||
for off in 0..=len {
|
||||
let Some(c) = l.caret_on(&Pos::body(0, off), 0) else { continue };
|
||||
if top.is_some_and(|t| t != c.top) && second.is_none() {
|
||||
second = Some(off + 10);
|
||||
break;
|
||||
}
|
||||
if top.is_none() {
|
||||
top = Some(c.top);
|
||||
first = Some(off);
|
||||
}
|
||||
}
|
||||
(first.expect("the paragraph is laid out"), second.expect("the paragraph wraps"))
|
||||
};
|
||||
run(&mut s, "select.column", json!({"anchor": Pos::body(0, first), "focus": Pos::body(0, second)}));
|
||||
let segs = s.column_segments().expect("the block is one paragraph's lines").to_vec();
|
||||
assert_eq!(segs.len(), 2, "the block holds a piece of each of the paragraph's two lines");
|
||||
assert!(segs.iter().all(|(a, b)| a.path == segs[0].0.path && b.path == segs[0].0.path), "both pieces are in one paragraph");
|
||||
assert!(!crate::cmd::insert::selection_is_one_line(&s), "a column selection is not one line of text");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_then_selecting_then_typing_are_two_undo_steps() {
|
||||
// #419: a selection that moves the insertion point ends the typing group, like a caret move.
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user