Repository navigation
Editor search: mark the current match on any line (#1177) - #1182
Merged
Merged
Conversation
The current search match, the one Find next or Replace takes, was marked only when it was on the caret line. Find next crosses lines and wraps around, so with the caret after the last match of its line, no match was marked. The Find panel's highlight now marks it wherever it is: the selected match, else the first match after the caret (before it when searching back), wrapping around. It is found by searching outward from the caret (EditBox.findCurrentMatch()), at most 1000 lines or 100k characters, and is cached per text revision, pattern, options, scope, selection, caret and direction, so a repaint doesn't search again. When no match is within those limits, all matches are collected once the text has been unchanged for 300 ms; caret moves then pick from them. Highlights set with the two-argument setTextToHighlight() (DlangIDE's search results, for example) keep the old behavior: a current match only on the caret line, or the selected one. currentMatchIndex() wraps around now, like Find next. The scoped forEachLineMatch() overload takes the current match instead of the selection, caret and direction. Both came with #1145 and are not released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1177.
The current search match (the one Find next or Replace takes) was marked only when it was on the caret line. Find next crosses lines and wraps around, so e.g. with the caret after the last match of its line, nothing was marked. The Find panel's highlight now marks the current match wherever it is: the selected match, else the first match after the caret (before it when searching back), wrapping around.
How it is found
EditBox.findCurrentMatch()searches outward from the caret: the selected match's line, the caret line, then the following lines in the search direction, wrapping around. It gives up after 1000 lines or 100k characters.forEachLineMatchon 100k lines of code-like text: a full pass takes 11–63 ms in a release build (44–91 ms debug), depending on the pattern and case sensitivity. So the bounded search costs about 0.1–0.6 ms per caret move, and a full pass happens at most once per pause in typing, only when matches are sparse near the caret. Keeping the match list up to date on edits would avoid even that, but isn't done here.Other highlights
setTextToHighlight()(used by DlangIDE's search results and its editor highlight) keeps the old behavior: a current match only on the caret line, or the selected one. It now goes through the four-argument version again, so overrides see every call.API changes (unreleased)
EditBox.currentMatchIndex()now wraps around like Find next: after the last match it returns the first one instead of -1.EditBox.forEachLineMatch()overload takes the current match instead of selection, caret and direction.Testing
dub test(Linux and Windows) anddub test -c console: pass, no leak lines. D-Scanner: clean.findCurrentMatch()withcurrentMatchIndex()over all matches, for every caret position, selection, direction and scope on several multi-line texts, also with a small search limit. Further tests cover giving up at the line and character limits, and hand-written cases for the caret-line-only mode. Each fails with a deliberately broken version (no wrap-around, no give-up,r.end >= caret).id:is marked current (master: nothing).🤖 Generated with Claude Code