Skip to content

Add Find/Replace In Selection#1045

Open
saberoueslati wants to merge 2 commits into
dail8859:masterfrom
saberoueslati:feature/find-replace-in-selection
Open

Add Find/Replace In Selection#1045
saberoueslati wants to merge 2 commits into
dail8859:masterfrom
saberoueslati:feature/find-replace-in-selection

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

@saberoueslati saberoueslati commented May 5, 2026

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 selection checkbox 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 selection is 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 :

Screencast.from.2026-05-27.18-24-21.webm

@saberoueslati saberoueslati marked this pull request as draft May 25, 2026 15:01
@saberoueslati
Copy link
Copy Markdown
Contributor Author

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

@saberoueslati saberoueslati force-pushed the feature/find-replace-in-selection branch from 5f51233 to 1825409 Compare May 27, 2026 17:49
@saberoueslati saberoueslati marked this pull request as ready for review May 27, 2026 17:49
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.

Replace and Find In Selection

1 participant