зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 00:15:50 +03:00
search rest of current line on search_forward/search_back
Этот коммит содержится в:
@@ -1437,17 +1437,15 @@ impl<'a> TextArea<'a> {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let (row, col) = self.cursor;
|
let (row, col) = self.cursor;
|
||||||
|
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 line = &self.lines[row];
|
if let Some((i, _)) = current_line.char_indices().nth(start_col) {
|
||||||
let start_col = if match_current { col } else { col + 1 };
|
if let Some(m) = pat.find_at(current_line, i) {
|
||||||
if let Some((i, _)) = line.char_indices().nth(start_col) {
|
let col = start_col + current_line[i..m.start()].chars().count();
|
||||||
if let Some(m) = pat.find_at(line, i) {
|
self.cursor = (row, col);
|
||||||
let col = start_col + line[i..m.start()].chars().count();
|
return true;
|
||||||
self.cursor = (row, col);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1469,6 +1467,23 @@ impl<'a> TextArea<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search current line before cursor
|
||||||
|
if col > 0 {
|
||||||
|
let col_idx = current_line
|
||||||
|
.char_indices()
|
||||||
|
.nth(col - 1)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.unwrap_or(current_line.len());
|
||||||
|
if let Some(m) = pat.find(current_line) {
|
||||||
|
let i = m.start();
|
||||||
|
if i <= col_idx {
|
||||||
|
let col = current_line[..i].chars().count();
|
||||||
|
self.cursor = (row, col);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1480,14 +1495,18 @@ impl<'a> TextArea<'a> {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let (row, col) = self.cursor;
|
let (row, col) = self.cursor;
|
||||||
|
let current_line = &self.lines[row];
|
||||||
|
|
||||||
// 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_current { col } else { col - 1 };
|
||||||
let line = &self.lines[row];
|
if let Some((i, _)) = current_line.char_indices().nth(start_col) {
|
||||||
if let Some((i, _)) = line.char_indices().nth(start_col) {
|
if let Some(m) = pat
|
||||||
if let Some(m) = pat.find_iter(line).take_while(|m| m.start() <= i).last() {
|
.find_iter(current_line)
|
||||||
let col = line[..m.start()].chars().count();
|
.take_while(|m| m.start() <= i)
|
||||||
|
.last()
|
||||||
|
{
|
||||||
|
let col = current_line[..m.start()].chars().count();
|
||||||
self.cursor = (row, col);
|
self.cursor = (row, col);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1496,7 +1515,7 @@ impl<'a> TextArea<'a> {
|
|||||||
|
|
||||||
// Search lines before cursor
|
// Search lines before cursor
|
||||||
for (i, line) in self.lines[..row].iter().enumerate().rev() {
|
for (i, line) in self.lines[..row].iter().enumerate().rev() {
|
||||||
if let Some(m) = pat.find(line) {
|
if let Some(m) = pat.find_iter(line).last() {
|
||||||
let col = line[..m.start()].chars().count();
|
let col = line[..m.start()].chars().count();
|
||||||
self.cursor = (i, col);
|
self.cursor = (i, col);
|
||||||
return true;
|
return true;
|
||||||
@@ -1505,13 +1524,26 @@ impl<'a> TextArea<'a> {
|
|||||||
|
|
||||||
// Search lines after cursor (wrap)
|
// Search lines after cursor (wrap)
|
||||||
for (i, line) in self.lines[row + 1..].iter().enumerate().rev() {
|
for (i, line) in self.lines[row + 1..].iter().enumerate().rev() {
|
||||||
if let Some(m) = pat.find(line) {
|
if let Some(m) = pat.find_iter(line).last() {
|
||||||
let col = line[..m.start()].chars().count();
|
let col = line[..m.start()].chars().count();
|
||||||
self.cursor = (row + 1 + i, col);
|
self.cursor = (row + 1 + i, col);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search current line after cursor
|
||||||
|
if let Some((i, _)) = current_line.char_indices().nth(col + 1) {
|
||||||
|
if let Some(m) = pat
|
||||||
|
.find_iter(current_line)
|
||||||
|
.skip_while(|m| m.start() < i)
|
||||||
|
.last()
|
||||||
|
{
|
||||||
|
let col = col + 1 + current_line[i..m.start()].chars().count();
|
||||||
|
self.cursor = (row, col);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user