Skip to content

Commit

Permalink
Improve text search
Browse files Browse the repository at this point in the history
  • Loading branch information
toftpokk authored and jackpot51 committed Dec 21, 2024
1 parent 39eb454 commit 647d291
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ impl EditorTab {
regex
.find_iter(buffer.lines[cursor.line].text())
.filter_map(|m| {
if cursor.line != start_line || m.start() >= cursor.index {
if cursor.line != start_line
|| m.start() >= cursor.index
|| m.start() < cursor.index && wrapped == true
{
Some((m.start(), m.len()))
} else {
None
Expand Down Expand Up @@ -263,14 +266,19 @@ impl EditorTab {
let mut cursor = editor.cursor();
let mut wrapped = false; // Keeps track of whether the search has wrapped around yet.
let start_line = cursor.line;
let current_selection = editor.selection();

if forwards {
while cursor.line < editor.with_buffer(|buffer| buffer.lines.len()) {
if let Some((start, end)) = editor.with_buffer(|buffer| {
regex
.find_iter(buffer.lines[cursor.line].text())
.filter_map(|m| {
if cursor.line != start_line || m.start() > cursor.index {
if cursor.line != start_line
|| m.start() > cursor.index
|| m.start() == cursor.index && current_selection == Selection::None
|| m.start() < cursor.index && wrapped == true
{
Some((m.start(), m.end()))
} else {
None
Expand Down Expand Up @@ -309,7 +317,11 @@ impl EditorTab {
regex
.find_iter(buffer.lines[cursor.line].text())
.filter_map(|m| {
if cursor.line != start_line || m.start() < cursor.index {
if cursor.line != start_line
|| m.start() < cursor.index
|| m.start() == cursor.index && current_selection == Selection::None
|| m.start() > cursor.index && wrapped == true
{
Some((m.start(), m.end()))
} else {
None
Expand Down

0 comments on commit 647d291

Please sign in to comment.