1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-08 16:35:49 +03:00

fix search_forward/search_back should finally match to the cursor position

Этот коммит содержится в:
rhysd
2022-07-08 10:06:26 +09:00
родитель 5b08d16214
Коммит 8008c0ebda

Просмотреть файл

@@ -1430,7 +1430,7 @@ impl<'a> TextArea<'a> {
}
#[cfg(feature = "search")]
pub fn search_forward(&mut self, match_current: bool) -> bool {
pub fn search_forward(&mut self, match_cursor: bool) -> bool {
let pat = if let Some(pat) = &self.search_pat {
pat
} else {
@@ -1440,7 +1440,7 @@ impl<'a> TextArea<'a> {
let current_line = &self.lines[row];
// Search current line after cursor
let start_col = if match_current { col } else { col + 1 };
let start_col = if match_cursor { col } else { col + 1 };
if let Some((i, _)) = current_line.char_indices().nth(start_col) {
if let Some(m) = pat.find_at(current_line, i) {
let col = start_col + current_line[i..m.start()].chars().count();
@@ -1468,10 +1468,9 @@ impl<'a> TextArea<'a> {
}
// Search current line before cursor
if col > 0 {
let col_idx = current_line
.char_indices()
.nth(col - 1)
.nth(col)
.map(|(i, _)| i)
.unwrap_or(current_line.len());
if let Some(m) = pat.find(current_line) {
@@ -1482,13 +1481,12 @@ impl<'a> TextArea<'a> {
return true;
}
}
}
false
}
#[cfg(feature = "search")]
pub fn search_back(&mut self, match_current: bool) -> bool {
pub fn search_back(&mut self, match_cursor: bool) -> bool {
let pat = if let Some(pat) = &self.search_pat {
pat
} else {
@@ -1499,7 +1497,7 @@ impl<'a> TextArea<'a> {
// Search current line before cursor
if col > 0 {
let start_col = if match_current { col } else { col - 1 };
let start_col = if match_cursor { col } else { col - 1 };
if let Some((i, _)) = current_line.char_indices().nth(start_col) {
if let Some(m) = pat
.find_iter(current_line)
@@ -1532,7 +1530,7 @@ impl<'a> TextArea<'a> {
}
// Search current line after cursor
if let Some((i, _)) = current_line.char_indices().nth(col + 1) {
if let Some((i, _)) = current_line.char_indices().nth(col) {
if let Some(m) = pat
.find_iter(current_line)
.skip_while(|m| m.start() < i)