Add Find/Replace In Selection
Description
Fixes #856
This PR adds an In selection option to the Find/Replace dialog so users can limit find, count, find-all, replace, and replace-all operations to the selected text range.
The selection range is captured when the checkbox is enabled, so later cursor movement or selection changes do not accidentally expand the search scope.
Additionally, Mark All is constrained to the captured selection range when In selection is active, and Purge for each search clears highlights only within that range rather than the entire document.
Changes Made
- Added an
In selectioncheckbox to the Find/Replace dialog. - Enable the checkbox only for a valid single stream selection.
- Disable it for no selection, rectangular selections, and multiple selections.
- Capture the selected range when
In selectionis checked. - Constrain the following operations to the captured selection range:
- Find Next
- Find Previous
- Count
- Find All in Current Document
- Replace
- Replace All
- Keep replacement bounds updated when replacements change text length.
- Prevent single Replace from modifying a match outside the captured selection.
- Ensure Find Previous inside a selection uses the current search flags, including Match Case, Whole Word, and Regex.
- Reset the in-selection state when switching editor tabs.
- Mark All
- Constrain "Purge for each search" clearing to the captured selection range when In selection is active.
- Show distinct status bar messages: "match in selection" vs "match in entire file" for Mark All.
Testing
Manual test plan : TestPlan-FindReplaceInSelection.md
Coverage includes:
- Checkbox enabled/disabled state for normal, empty, rectangular, and multiple selections.
- Find Next and Find Previous constrained to the captured selection.
- Wrap Around behavior inside the captured selection.
- Count constrained to the captured selection.
- Replace All constrained to the captured selection.
- Replacement length changes updating the selected range correctly.
- Find All in Current Document constrained to the captured selection.
- Editor tab switching clearing the in-selection state.
- Match Case, Whole Word, and Regex behavior with In selection.
- Regression test for Find Previous using stale search flags.
- Regression test for single Replace not modifying matches outside the captured selection.
- Mark All constrained to the captured selection range.
- Purge for each search clearing only within the selection (marks outside survive).
- Status bar message distinguishing in-selection vs entire-file for Mark All.
- Clear All Marks removing all highlights regardless of In selection state.
- Bookmark Line with In Selection bookmarking only lines within the captured range.
- Mark All using the range captured at checkbox-toggle time, not the current editor selection.
Basic manual test below :
Screencast from 2026-05-06 00-46-52.webm
Edit :
Just added the In Selection option for the Mark Tab, updated the description, changes made and testing section accordingly
Basic manual test of the In Selection feature in the Mark tab below :
I returned this PR to being a draft to work on the In Selection for the recently added Mark Tab, will make it ready for review again as soon as I finish that