define shared iters

This commit is contained in:
yggverse 2024-12-16 16:25:39 +02:00
parent a445c4c6a2
commit 4c572fada6

View File

@ -104,13 +104,17 @@ fn find(
// Init matches holder // Init matches holder
let mut result = Vec::new(); let mut result = Vec::new();
// Get iters
let buffer_start = buffer.start_iter();
let buffer_end = buffer.end_iter();
// Cleanup previous search highlights // Cleanup previous search highlights
buffer.remove_tag(&tag.current, &buffer.start_iter(), &buffer.end_iter()); buffer.remove_tag(&tag.current, &buffer_start, &buffer_end);
buffer.remove_tag(&tag.found, &buffer.start_iter(), &buffer.end_iter()); buffer.remove_tag(&tag.found, &buffer_start, &buffer_end);
// Begin new search // Begin new search
let mut next = buffer.start_iter(); let mut next = buffer_start;
while let Some((start, end)) = next.forward_search( while let Some((match_start, match_end)) = next.forward_search(
subject, subject,
match is_match_case { match is_match_case {
true => TextSearchFlags::TEXT_ONLY, true => TextSearchFlags::TEXT_ONLY,
@ -118,9 +122,9 @@ fn find(
}, },
None, // unlimited None, // unlimited
) { ) {
buffer.apply_tag(&tag.found, &start, &end); buffer.apply_tag(&tag.found, &match_start, &match_end);
next = end; next = match_end;
result.push((start, end)); result.push((match_start, match_end));
} }
result result
} }