Improve invalidation on on ambiguous find results
When searching for a multi-line string, the search is invalidated
until the end of the file. Otherwise, it is only invalidated until
the end of the line.
@@ -19,7 +19,7 @@ use serde_json::value::Value;
use xi_rope::rope::{Rope, LinesMetric, RopeInfo};
use xi_rope::delta::Delta;
-use xi_rope::tree::Cursor;
+use xi_rope::tree::{Cursor, Metric};
use xi_rope::breaks::{Breaks, BreaksInfo, BreaksMetric, BreaksBaseMetric};
use xi_rope::interval::Interval;
use xi_rope::spans::Spans;
@@ -720,8 +720,22 @@ impl View {
self.occurrences = Some(occurrences);
if let Some(invalidate_from) = invalidate_from {
self.valid_search.union_one_range(start, invalidate_from);
- // invalidate all search results from the point of the ambigious search result
+
+ // test whether the search string contains newlines
+ let is_multi_line = LinesMetric::next(self.search_string.as_ref().unwrap(), 0).is_some();
+ if is_multi_line {
+ // invalidate all search results from the point of the ambigious search result until
+ // the end of the file
self.valid_search.delete_range(invalidate_from, text_len);
+ } else {
+ // find end of line
+ let mut cursor = Cursor::new(&text, invalidate_from);
+ if let Some(end_of_line) = cursor.next::<LinesMetric>() {
+ // invalidate until end of line
+ self.valid_search.delete_range(invalidate_from, end_of_line);
+ }
+ }
+
// continue with the find for the current region
self.update_find(text, invalidate_from, end, false, false);
} else {
