Skip to content

Editor search: one current match, the selected one if it is a match (#1145) - #1167

Merged
buggins merged 1 commit into
masterfrom
search-current-match-1145
Nov 23, 2026
Merged

buggins merged 1 commit into
masterfrom
search-current-match-1145

Conversation

@buggins

@buggins buggins commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Fixes #1145

Two adjacent search matches could both get the current-match color: the caret at the end of the first one is also at the start of the second.

Changes (editors.d):

  • One current match per line: the selected match if the selection is one of the matches, else the first match with the caret inside or right after it (currentMatchIndex()). After Find next, the found match is selected; after selecting a match from right to left (caret at its start), that match stays current too.
  • findNextPattern() counts from the same current match: it takes the selection as a new last parameter (TextRange selection = TextRange.init), and the Find panel passes it for Find next and Replace. Before, Find next from a match selected right to left selected the same match again.
  • The match loop is shared by the highlight and findAll() (forEachLineMatch()), so both see the same matches; the index arithmetic of findNextPattern() moved unchanged into nextMatchIndex().
  • Unittests for the highlight's current match, currentMatchIndex() and nextMatchIndex() (adjacent matches, selections in both directions, a selection that isn't a match, wrapping, a single match). They fail with the old rule.

API change: findNextPattern() has a new parameter with a default value, so calls compile as before, but a subclass overriding the old 4-parameter version no longer compiles. DlangIDE doesn't override or call it.

Testing:

  • dub test (36 modules) and dub test -c console (33), no leak lines; D-Scanner clean; dmledit and DlangIDE build.
  • Console dmledit (tmux), searching for two spaces in indented lines (adjacent matches): after Find next, the match right after the selected one was drawn with the current color on master, with the other-match color with this change; after a second Find next, the selection moves to that match and no other match is current. No leaks.
  • Not tested in the GUI: the highlight code is shared with console builds, and the Windows test tool can't send Ctrl+F.

Found by the reviews, filed separately: #1164 (Replace repeats when the replacement is a match), #1165 (Find next skips the match at the caret without a selection), #1166 (Selection option ignored by Find next and Replace).

🤖 Generated with Claude Code

…1145)

Of two adjacent matches, the caret at the end of the first one is also
at the start of the second, and both were drawn as current. The current
match is now the selected match if the selection is one, else the first
match with the caret inside or right after it; Find next and Replace
count from the same match (findNextPattern takes the selection). The
match loop is shared by the highlight and findAll(), the choice of the
current and the next match are static functions with unittests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@buggins buggins self-assigned this Nov 23, 2026
@buggins
buggins marked this pull request as ready for review November 23, 2026 22:37
@buggins
buggins merged commit 38c3aa2 into master Nov 23, 2026
13 checks passed
@buggins
buggins deleted the search-current-match-1145 branch November 23, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor search: two adjacent matches can both get the current-match color

1 participant