diff options
| author | Trevor Murphy <trevormurphy@google.com> | 2025-05-19 16:41:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-19 16:41:31 -0700 |
| commit | 57d9ab3f909109a093ae69730d8666d8202898ab (patch) | |
| tree | 393160a921e60330ef8322dacd68353eb6db8360 | |
| parent | 82cbb665bc6a62de59e00aa76dcef29ef3a6c3a2 (diff) | |
Fix moving point (#363)
When replacing text, calculate the cursor offset relative to the start
of the replacement, not the end of the text-to-be-added.
* test/integration/apheleia-it.el (supports-inserting-whitespace): New
test case
* apheleia-rcs.el (apheleia--apply-rcs-patch): Go to start of deletion
text before calculating offsets
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | apheleia-rcs.el | 1 | ||||
| -rw-r--r-- | test/integration/apheleia-it.el | 19 |
3 files changed, 25 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d2399bb..e0c6db9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog]. +## Unreleased +### Bugs fixed +* A formatter that adds indentation while point is at the end of the + line would sometimes leave point at the wrong position ([#362]). + ## 4.4.1 (released 2025-05-13) ### Enhancements * Black will respect configuration in `pyproject.toml` when run via diff --git a/apheleia-rcs.el b/apheleia-rcs.el index 388e0f7..2c15c7a 100644 --- a/apheleia-rcs.el +++ b/apheleia-rcs.el @@ -131,6 +131,7 @@ contains the patch." -1) (alist-get 'start addition))) (let ((text-start (alist-get 'marker deletion))) + (goto-char text-start) (forward-line (alist-get 'lines deletion)) (let ((text-end (point))) (dolist (pos-spec pos-list) diff --git a/test/integration/apheleia-it.el b/test/integration/apheleia-it.el index d4e9238..b48e420 100644 --- a/test/integration/apheleia-it.el +++ b/test/integration/apheleia-it.el @@ -244,3 +244,22 @@ exit 1 (lambda (&rest props) (funcall callback (plist-get props :error)))))) (expect "line4\nline1\n|line2\nline3"))) + +(apheleia-it-deftest supports-inserting-whitespace + "Running `apheleia-format-buffer' preserves point when inserting +whitespace before point" + :scripts `(("apheleia-it" . + ,(apheleia-it-script + :allowed-inputs + '(("function main() {\na=\n return 0\n}" . + "function main() {\n a=\n return 0\n}"))))) + :formatters '((apheleia-it . ("apheleia-it"))) + :steps '((insert "function main() {\na=|\n return 0\n}") + (with-callback + callback + (eval (apheleia-format-buffer + 'apheleia-it nil + :callback + (lambda (&rest props) + (funcall callback (plist-get props :error)))))) + (expect "function main() {\n a=|\n return 0\n}"))) |
