-
Notifications
You must be signed in to change notification settings - Fork 83
[202_105]: Fix replace-all to replace entire document, not just after cursor #2860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -723,6 +723,19 @@ tree 或 #f | |||||
| (perform-search*) | ||||||
| (set! isreplace? #t)))) | ||||||
|
|
||||||
| (tm-define (replace-all-occurrences . args) | ||||||
| (let ((u (if (null? args) (master-buffer) (car args))) | ||||||
| (raux (if (null? args) (replace-buffer) (cadr args)))) | ||||||
| (and-with by (or (by-tree raux) current-replace) | ||||||
| (with-buffer u | ||||||
| (search-extreme-match #f) | ||||||
|
||||||
| (search-extreme-match #f) | |
| (search-extreme-match u #f) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,42 @@ else | |
| ``` | ||
|
|
||
| Also removed the now-unused `("meta::keyboard" "")` entry from `TeXmacs/plugins/lang/dic/en_US/zh_CN.scm`. | ||
|
|
||
| # [202_105] Search and replace: add "Replace all occurrences" button | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation should be moved to a new file instead of being placed in |
||
|
|
||
| ## How to test | ||
| 1. Open a document with multiple occurrences of a word (e.g. "hello" appearing 5 times) | ||
| 2. Open search and replace (Edit → Search and replace) | ||
| 3. Place cursor in the middle of the document (e.g. after the 3rd occurrence) | ||
| 4. Enter the search term "hello" and the replacement "world" | ||
| 5. Click "Replace all further occurrences" (or press Ctrl+Enter / Command+Enter) | ||
| 6. Confirm that only the occurrences **after the cursor** are replaced (original behavior preserved) | ||
| 7. Undo, then click "Replace all occurrences" | ||
| 8. Confirm that **all 5 occurrences** are replaced, including those before the cursor | ||
|
|
||
| ## 2026/02/25 | ||
| ### What | ||
| Add a separate "Replace all occurrences" button that replaces every match in the entire document, while keeping the original "Replace all further occurrences" button and behavior. | ||
|
|
||
| ### Why | ||
| Users expect a way to replace every occurrence in the document regardless of cursor position (issue #2857). The maintainer requested this as a separate button so the original "Replace all further occurrences" behavior is preserved. | ||
|
|
||
|
Comment on lines
+49
to
53
|
||
| ### How | ||
| Added a new `replace-all-occurrences` function that calls `(search-extreme-match #f)` before the replace loop to navigate to the first match, so replacement starts from the beginning of the document. The original `replace-all` function is kept unchanged. | ||
|
|
||
| ```scheme | ||
| (tm-define (replace-all-occurrences . args) | ||
| (let ((u (if (null? args) (master-buffer) (car args))) | ||
| (raux (if (null? args) (replace-buffer) (cadr args)))) | ||
| (and-with by (or (by-tree raux) current-replace) | ||
| (with-buffer u | ||
| (search-extreme-match #f) ;; Go to the first match | ||
| (start-editing) | ||
| (while (replace-next by) | ||
| (perform-search*)) | ||
| (end-editing)) | ||
| (perform-search*) | ||
| (set! isreplace? #t)))) | ||
| ``` | ||
|
|
||
| Added a new "Replace all occurrences" button in all 3 replace UI locations (dialog, side panel, toolbar) alongside the existing "Replace all further occurrences" button. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument parsing in
replace-all-occurrencesis unsafe: whenargsis non-empty but has only one element,(cadr args)will throw. Since the procedure signature is variadic (. args), either enforce exactly 0 or 2 args (and signal a clear error) or makerauxdefault when(length args) < 2.