mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-08 18:51:35 +00:00
Merge pull request #5328 from dotCooCoo/fix/select-same-nonempty-text
Exclude empty runs from matching text selections
This commit is contained in:
@@ -325,7 +325,7 @@ fn first_text_style(s: &Session) -> Option<CharStyle> {
|
||||
fn same_text(s: &mut Session, cmd: &str, eq: fn(&CharStyle, &CharStyle) -> bool) -> Result<Value> {
|
||||
let r = first_text_style(s).ok_or_else(|| bad(cmd, "select a text object"))?;
|
||||
let ids = candidates(s, |n| match &n.kind {
|
||||
NodeKind::Text(t) => t.runs.iter().any(|run| eq(&run.style, &r)),
|
||||
NodeKind::Text(t) => t.runs.iter().any(|run| !run.text.is_empty() && eq(&run.style, &r)),
|
||||
_ => false,
|
||||
})?;
|
||||
finish_same(s, cmd, ids)
|
||||
|
||||
@@ -1991,6 +1991,19 @@ fn select_same_text_fill_and_stroke_color_needs_both_to_match() {
|
||||
assert!(s.execute("select.same.textFillAndStrokeColor", &json!({})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_same_character_colors_ignore_empty_text() {
|
||||
let mut s = session();
|
||||
let a = id_of(&s.execute("text.create", &json!({"x": 0, "y": 20, "text": "a"})).unwrap());
|
||||
let b = id_of(&s.execute("text.create", &json!({"x": 0, "y": 40, "text": "b"})).unwrap());
|
||||
let empty = id_of(&s.execute("text.create", &json!({"x": 0, "y": 60, "text": ""})).unwrap());
|
||||
for cmd in ["select.same.textFillColor", "select.same.textStrokeColor", "select.same.textFillAndStrokeColor"] {
|
||||
sel(&mut s, &[a]);
|
||||
s.execute(cmd, &json!({})).unwrap();
|
||||
assert_eq!(selected(&s), vec![a, b], "{cmd}: empty object {empty:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_same_link_block_series_selects_the_frames_of_a_thread() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user