mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(engine): start a new Find round when the search criteria change (#15007)
Clear the remembered round origin together with the cursor when the find text or an option differs, and on a zero-hit Change All, so a new query cannot stop at the layer an earlier round started in. Adds changed_query_starts_a_new_round_and_reaches_the_old_origin.
This commit is contained in:
1 parent
e1f734166c
commit
5c7db90e2a
2 files changed
+18
No files matched your search
@@ -88,6 +88,7 @@ pub(super) fn find_replace(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let count: usize = plan.iter().map(|(_, m)| m.len()).sum();
|
||||
if count == 0 {
|
||||
s.edit_state.find_cursor = None;
|
||||
s.edit_state.find_start = None;
|
||||
return Ok(json!({"count": 0, "layers": 0}));
|
||||
}
|
||||
s.edit("Replace All Text", |doc, _| {
|
||||
@@ -114,7 +115,9 @@ pub(super) fn find_replace(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
.as_ref()
|
||||
.is_some_and(|c| c.find == find && c.case_sensitive == case && c.whole_word == whole && c.forward == forward && c.all_layers == all_layers);
|
||||
if !same_query {
|
||||
// A new query starts a new round: forget both the cursor and the round origin.
|
||||
s.edit_state.find_cursor = None;
|
||||
s.edit_state.find_start = None;
|
||||
}
|
||||
let cursor = s.edit_state.find_cursor.as_ref().map(|c| (c.layer, c.start, c.end));
|
||||
let mut changed = None;
|
||||
|
||||
@@ -153,6 +153,21 @@ fn find_next_single_layer_and_change_all_preserved() {
|
||||
assert_eq!((r["count"].as_u64(), r["layers"].as_u64()), (Some(8), Some(4)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changed_query_starts_a_new_round_and_reaches_the_old_origin() {
|
||||
let (mut s, [t1, t2, ..], _) = make_order_doc();
|
||||
s.execute("layer.select", json!({"layer": t1.0})).unwrap();
|
||||
// The round starts at T1: four hits there, then the match in T2.
|
||||
for _ in 0..4 {
|
||||
assert_eq!(find_next(&mut s, true, true).map(|h| h.0), Some(t1));
|
||||
}
|
||||
assert_eq!(find_next(&mut s, true, true), Some((t2, 4, 7, "cat".into())));
|
||||
|
||||
// A query that matches only in the old origin (T1) must be reachable from the cursor in T2.
|
||||
let r = s.execute("edit.findAndReplaceText", json!({"find": "CAT", "action": "find", "forward": true, "allLayers": true, "caseSensitive": true})).unwrap();
|
||||
assert_eq!((r["found"]["layer"].as_u64(), r["found"]["text"].as_str()), (Some(t1.0), Some("CAT")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_next_from_top_pixel_layer_wraps_to_bottom_type_layer() {
|
||||
let (mut s, [t1, ..], top_pixel) = make_order_doc();
|
||||
|
||||
Reference in new issue
Block a user