зеркало из
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
Этот коммит содержится в:
@@ -1430,7 +1430,7 @@ impl<'a> TextArea<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "search")]
|
#[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 {
|
let pat = if let Some(pat) = &self.search_pat {
|
||||||
pat
|
pat
|
||||||
} else {
|
} else {
|
||||||
@@ -1440,7 +1440,7 @@ impl<'a> TextArea<'a> {
|
|||||||
let current_line = &self.lines[row];
|
let current_line = &self.lines[row];
|
||||||
|
|
||||||
// Search current line after cursor
|
// 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((i, _)) = current_line.char_indices().nth(start_col) {
|
||||||
if let Some(m) = pat.find_at(current_line, i) {
|
if let Some(m) = pat.find_at(current_line, i) {
|
||||||
let col = start_col + current_line[i..m.start()].chars().count();
|
let col = start_col + current_line[i..m.start()].chars().count();
|
||||||
@@ -1468,10 +1468,9 @@ impl<'a> TextArea<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search current line before cursor
|
// Search current line before cursor
|
||||||
if col > 0 {
|
|
||||||
let col_idx = current_line
|
let col_idx = current_line
|
||||||
.char_indices()
|
.char_indices()
|
||||||
.nth(col - 1)
|
.nth(col)
|
||||||
.map(|(i, _)| i)
|
.map(|(i, _)| i)
|
||||||
.unwrap_or(current_line.len());
|
.unwrap_or(current_line.len());
|
||||||
if let Some(m) = pat.find(current_line) {
|
if let Some(m) = pat.find(current_line) {
|
||||||
@@ -1482,13 +1481,12 @@ impl<'a> TextArea<'a> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "search")]
|
#[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 {
|
let pat = if let Some(pat) = &self.search_pat {
|
||||||
pat
|
pat
|
||||||
} else {
|
} else {
|
||||||
@@ -1499,7 +1497,7 @@ impl<'a> TextArea<'a> {
|
|||||||
|
|
||||||
// Search current line before cursor
|
// Search current line before cursor
|
||||||
if col > 0 {
|
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((i, _)) = current_line.char_indices().nth(start_col) {
|
||||||
if let Some(m) = pat
|
if let Some(m) = pat
|
||||||
.find_iter(current_line)
|
.find_iter(current_line)
|
||||||
@@ -1532,7 +1530,7 @@ impl<'a> TextArea<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search current line after cursor
|
// 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
|
if let Some(m) = pat
|
||||||
.find_iter(current_line)
|
.find_iter(current_line)
|
||||||
.skip_while(|m| m.start() < i)
|
.skip_while(|m| m.start() < i)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user