Skip to content

Find panel: Replace, Find next from the caret, Selection scope (#1164, #1165, #1166) - #1176

Merged
buggins merged 1 commit into
masterfrom
find-panel-1164-1165-1166
Nov 24, 2026
Merged

buggins merged 1 commit into
masterfrom
find-panel-1164-1165-1166

Conversation

@buggins

@buggins buggins commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1164, fixes #1165, fixes #1166.

Replace (#1164)

  • Replace replaces only a match that is selected. Without one, it first selects the next match in the search direction, so you see what the next Replace will change.
  • Before, Replace took the match at the caret. A replacement that is itself a match (id → xid) was replaced again on every click.
  • After Replace, "Replace and find" and Replace all, the caret is after the replacement (before it when searching back) and nothing is selected.

Find next from the caret (#1165)

  • Without a selected match, Find next takes the first match that ends after the caret, and Find prev the last one that starts before it. Before, a match ending at the caret was taken as the current one and skipped.
  • A single selected match is found again instead of "not found".
  • The highlighted current match follows the search direction.

Selection option (#1166)

  • The selection when the option is turned on is the scope. Find next selecting matches no longer narrows it.
  • Replacements on the scope's last line move its end. Replacing all of its text leaves an empty scope with no matches, not the whole text.
  • The option needs a selection: ticking it with nothing selected unticks it again.
  • Other changes of the text (typing, undo, another content object) drop the scope and untick the option. The Find next, Replace or Replace all that notices this does nothing that time, rather than working on the whole text.
  • Reopening the panel (F3 or Ctrl+F after Esc) takes a new selection as the scope. The match the panel itself selected, or no selection, keeps the scope.
  • The find text is kept when the selection becomes the new scope. It is also kept when the selection is the panel's own match: before, F3 after Esc copied the case of a match found case-insensitively into the find text (an older bug, fixed here because it's the same line).
  • The editor highlights only the matches in the scope. Once the text changes, it highlights none until the panel updates the highlight.

API

  • EditableContent.revision: a new value with each edit, undo, redo, new content and clear(), never shared between content objects (atomic counter).
  • EditWidgetBase.setTextToHighlight(pattern, options, scope_, back), a new overload. The two-argument form is unchanged (DlangIDE uses it).
  • WHOLE_TEXT_RANGE; EditBox.currentMatchIndex() gets an optional back parameter; EditBox.forEachLineMatch() (the overload with current) takes a scope and the direction.
  • findNextPattern(): a single selected match returns true with the position unchanged. A caret right after a match goes on to the next one.

Testing

  • dub test (Linux and Windows) and dub test -c console: pass, no leak lines. D-Scanner: clean.
  • Unittests for the match choice in both directions, scopes (including an empty one), matchesInScope, scopeAfterReplace and revision.
  • dmledit console (tmux, with a temporary hook that selects lines 1–10 and opens the Replace panel; not committed), all ending with a normal exit and no leak lines:
    • Replace and "Replace and find" do one replacement per click.
    • Sel + Replace all replaces the 2 matches in the scope.
    • Esc → F3 keeps the scope.
    • A new selection + F3 becomes the scope and keeps the find text.
    • After typing in the text, Replace unticks Sel and replaces nothing.
    • Sel can't be ticked without a selection.
  • Win32 dmledit: Sel limits the highlight to the scope, Replace all replaces the 2 matches in it, the highlight disappears after typing, and the app closes with no leak lines.
  • Not checked in a GUI: the current-match highlight when searching back (unit-tested only).

The highlighted current match is still found on the caret line only, while Find next can go to the next line: #1177.

🤖 Generated with Claude Code

…#1165, #1166)

Replace replaced the match at the caret even when nothing was selected, so a
replacement that is itself a match was replaced again (#1164). It now replaces
only a selected match; without one it selects the next match first. Replace
and Replace all leave the caret after the replacement with nothing selected.

Without a selected match, Find next went on from a match that ended at the
caret, skipping it (#1165). It now takes the first match that ends after the
caret, and Find prev the last one that starts before it. The highlighted
current match follows the search direction.

The Selection option used the current selection at each operation, so the
first Find next narrowed the search to the match it selected (#1166). The
selection when the option is turned on is now the scope. Replacements on its
last line move its end, and replacing all of its text leaves an empty scope
with no matches. Other changes of the text (typing, undo, new content) drop
the scope and turn the option off; the operation that notices it does nothing
that time. The option needs a selection. Reopening the panel (F3 after Esc)
takes a new selection as the scope, but not the match the panel selected. In
both cases the find text is kept; it no longer takes the case of the found
match. The editor highlights only matches in the scope, and none after the
text changes until the panel sets the highlight again.

EditableContent.revision identifies the state of the text. It changes with
each edit, undo, redo, new content and clear(), and differs between content
objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@buggins buggins self-assigned this Nov 24, 2026
@buggins
buggins marked this pull request as ready for review November 24, 2026 12:52
@buggins
buggins merged commit ef4e22d into master Nov 24, 2026
13 checks passed
@buggins
buggins deleted the find-panel-1164-1165-1166 branch November 24, 2026 12:52
buggins added a commit that referenced this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant