Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,10 @@ impl TextBuffer {

fn find_select_next(&mut self, search: &mut ActiveSearch, offset: usize, wrap: bool) {
if search.buffer_generation != self.buffer.generation() {
unsafe { search.regex.set_text(&search.text) };
unsafe { search.regex.set_text(&search.text, offset) };
search.buffer_generation = self.buffer.generation();
}

if search.next_search_offset != offset {
search.next_search_offset = offset;
} else if search.next_search_offset != offset {
search.next_search_offset = offset;
search.regex.reset(offset);
}
Expand Down
9 changes: 6 additions & 3 deletions src/icu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,20 @@ impl Regex {
/// # Safety
///
/// The caller must ensure that the given `Text` outlives the `Regex` instance.
pub unsafe fn set_text(&mut self, text: &Text) {
pub unsafe fn set_text(&mut self, text: &Text, offset: usize) {
let f = assume_loaded();
let mut status = icu_ffi::U_ZERO_ERROR;
unsafe { (f.uregex_setUText)(self.0, text.0 as *const _ as *mut _, &mut status) };
// `uregex_setUText` resets the regex to the start of the text.
// Because of this, we must also call `uregex_reset64`.
unsafe { (f.uregex_reset64)(self.0, offset as i64, &mut status) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting the offset to the start of the match cause us to deadlock if you Find "a" replace with "a"? Do we need somehow to skip the matched section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the caller specifies the "current offset" which is past the replaced range.

}

/// Sets the regex to the absolute offset in the underlying text.
pub fn reset(&mut self, index: usize) {
pub fn reset(&mut self, offset: usize) {
let f = assume_loaded();
let mut status = icu_ffi::U_ZERO_ERROR;
unsafe { (f.uregex_reset64)(self.0, index as i64, &mut status) };
unsafe { (f.uregex_reset64)(self.0, offset as i64, &mut status) };
}
}

Expand Down