[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-exchange 47c017cc9a 22/46: Fix weird behaviour for ad
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-exchange 47c017cc9a 22/46: Fix weird behaviour for adjacent areas |
Date: |
Thu, 6 Jan 2022 03:59:52 -0500 (EST) |
branch: elpa/evil-exchange
commit 47c017cc9a662b14d681fd60fdbf9984c147d8ee
Author: Dewdrops <v_v_4474@126.com>
Commit: Dewdrops <v_v_4474@126.com>
Fix weird behaviour for adjacent areas
---
evil-exchange.el | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/evil-exchange.el b/evil-exchange.el
index e002514e6b..1dceacbffd 100644
--- a/evil-exchange.el
+++ b/evil-exchange.el
@@ -4,7 +4,7 @@
;; Author: Dewdrops <v_v_4474@126.com>
;; URL: http://github.com/Dewdrops/evil-exchange
-;; Version: 0.22
+;; Version: 0.23
;; Keywords: evil, plugin
;; Package-Requires: ((evil "1.0.7") (cl-lib "0.3"))
@@ -106,7 +106,8 @@
((and (eq orig-type 'block) (eq type 'block))
(evil-exchange--do-swap beg-marker end-marker
orig-beg orig-end
- #'delete-extract-rectangle
#'insert-rectangle))
+ #'delete-extract-rectangle #'insert-rectangle
+ nil))
;; signal error if regions incompatible
((or (eq orig-type 'block) (eq type 'block))
(user-error "Can't exchange block region with non-block region"))
@@ -114,19 +115,37 @@
(t
(evil-exchange--do-swap beg-marker end-marker
orig-beg orig-end
- #'delete-and-extract-region #'insert))))))
+ #'delete-and-extract-region #'insert
+ t))))))
;; place cursor on beginning of line
(when (and (evil-called-interactively-p) (eq type 'line))
(evil-first-non-blank)))
-(defun evil-exchange--do-swap (curr-beg curr-end orig-beg orig-end extract-fn
insert-fn)
- (let ((orig-text (funcall extract-fn orig-beg orig-end))
+(defun evil-exchange--do-swap (curr-beg curr-end orig-beg orig-end extract-fn
insert-fn not-block)
+ ;; This function does the real exchange work. Here's the detailed steps:
+ ;; 1. call extract-fn with orig-beg and orig-end to extract orig-text.
+ ;; 2. call extract-fn with curr-beg and curr-end to extract curr-text.
+ ;; 3. go to orig-beg and then call insert-fn with curr-text.
+ ;; 4. go to curr-beg and then call insert-fn with orig-text.
+ ;; After step 2, curr-beg and curr-end (the same as orig-beg and orig-end)
+ ;; will point to the same position. So if orig-beg is at the same position of
+ ;; curr-end initially, orig-beg and curr-beg will point to the same position
+ ;; before step 3. Because curr-beg is a marker moved after insertion, the
+ ;; insertion in step 3 will push it to the end of the newly inserted text,
+ ;; thus resulting incorrect behaviour.
+ ;; To fix this edge case, we swap two extracted texts before step 3 to
+ ;; effectively reverse the (problematic) order of two `evil-exchange' calls.
+ (let ((adjacent (and not-block (equal (marker-position orig-beg)
(marker-position curr-end))))
+ (orig-text (funcall extract-fn orig-beg orig-end))
(curr-text (funcall extract-fn curr-beg curr-end)))
- (save-excursion
- (goto-char orig-beg)
- (funcall insert-fn curr-text)
- (goto-char curr-beg)
- (funcall insert-fn orig-text)))
+ ;; swaps two texts if adjacent is set
+ (let ((orig-text (if adjacent curr-text orig-text))
+ (curr-text (if adjacent orig-text curr-text)))
+ (save-excursion
+ (goto-char orig-beg)
+ (funcall insert-fn curr-text)
+ (goto-char curr-beg)
+ (funcall insert-fn orig-text))))
(setq evil-exchange--position nil)
(evil-exchange--remove-overlays))
- [nongnu] elpa/evil-exchange 37fd36065d 10/46: Merge https://github.com/Dewdrops/evil-exchange, (continued)
- [nongnu] elpa/evil-exchange 37fd36065d 10/46: Merge https://github.com/Dewdrops/evil-exchange, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 1e3ba07be4 18/46: Merge pull request #5 from fbergroth/remove-transpose-regions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 7cd34aea03 13/46: use non-advancable marker to mark the end of the region to exchange, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 7f1436b781 14/46: highlight the area marked to exchange, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange d35ebe9a7d 16/46: doc improvement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 5b0c4ab07c 20/46: add vim-compatible key bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 2ae6e0a203 24/46: ignore tags, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 22d9b6ce1b 19/46: bump version and rename internal function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 51c830b65d 21/46: better error message, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 328370e898 23/46: vim compatible bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 47c017cc9a 22/46: Fix weird behaviour for adjacent areas,
ELPA Syncer <=
- [nongnu] elpa/evil-exchange e7e3d679b9 27/46: implement exchange across buffers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 19b4b6277e 29/46: Merge pull request #8 from Dewdrops/cross-buffer, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 9d59144066 30/46: improve doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 492c6f7ff0 33/46: Merge pull request #9 from sooheon/support-lispyville, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 6e80e2509b 35/46: mention compatibility issues in doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 8902966aec 36/46: add melpa badge, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange a17eca6d0d 38/46: Merge pull request #11 from Dewdrops/add-test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 548393cb16 44/46: Always inhibit operator code when canceling an exchange., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 4769153781 41/46: update version and copyright, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 86500b91f6 37/46: add test, ELPA Syncer, 2022/01/06