aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Fischer <frank-fischer@shadow-soft.de>2015-09-27 11:47:34 +0200
committerFrank Fischer <frank-fischer@shadow-soft.de>2015-09-27 11:47:34 +0200
commit0aeecc17ab4381a73b362e96492c748ada622737 (patch)
tree308b19ca7e53e8dc68e6eb56c1b7fd9ebe7f6b33
parent03eebaaf0be027ed0f6cfaf75f354dcb589b6d4b (diff)
Ensure non-line object do not select whitespace on other lines (re #577)
-rw-r--r--evil-common.el46
-rw-r--r--evil-tests.el4
2 files changed, 32 insertions, 18 deletions
diff --git a/evil-common.el b/evil-common.el
index 2e009d8..e1c741d 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -3002,22 +3002,36 @@ linewise, otherwise it is character wise."
(cond
((> dir 0) (goto-char end) (setq other beg))
(t (goto-char beg) (setq other end)))
- ;; if current is only selected object ...
- (when (and (= beg (car bnd)) (= end (cdr bnd)))
- (if objbnd
- ;; current match is thing, add whitespace
- (let ((wsend (evil-bounds-of-not-thing-at-point thing dir)))
- (if (not wsend) ;; no whitespace at end, try beginning
- (save-excursion
- (goto-char other)
- (setq wsend (evil-bounds-of-not-thing-at-point thing (- dir)))
- (when wsend (setq other wsend addcurrent t)))
- ;; add whitespace at end
- (goto-char wsend)
- (setq addcurrent t)))
- ;; current match is whitespace, add thing
- (forward-thing thing dir)
- (setq addcurrent t)))
+ (cond
+ ;; do nothing more than only current is selected
+ ((not (and (= beg (car bnd)) (= end (cdr bnd)))))
+ ;; current match is thing, add whitespace
+ (objbnd
+ (let ((wsend (evil-with-restriction
+ ;; restrict to current line if we do non-line selection
+ (and (not line) (line-beginning-position))
+ (and (not line) (line-end-position))
+ (evil-bounds-of-not-thing-at-point thing dir))))
+ (cond
+ (wsend
+ ;; add whitespace at end
+ (goto-char wsend)
+ (setq addcurrent t))
+ (t
+ ;; no whitespace at end, try beginning
+ (save-excursion
+ (goto-char other)
+ (setq wsend
+ (evil-with-restriction
+ ;; restrict to current line if we do non-line selection
+ (and (not line) (line-beginning-position))
+ (and (not line) (line-end-position))
+ (evil-bounds-of-not-thing-at-point thing (- dir))))
+ (when wsend (setq other wsend addcurrent t)))))))
+ ;; current match is whitespace, add thing
+ (t
+ (forward-thing thing dir)
+ (setq addcurrent t)))
;; possibly count current object as selection
(if addcurrent (setq count (1- count)))
;; move
diff --git a/evil-tests.el b/evil-tests.el
index c884500..174912a 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -7957,7 +7957,7 @@ maybe we need one line more with some text\n")
(evil-test-buffer
"there are two lines in this file\n[\n]and some whitespace between them"
("dao")
- "there are two lines in this file[a]nd some whitespace between them")
+ "there are two lines in this file\n[a]nd some whitespace between them")
(evil-test-buffer
"here are another two lines\n[\n]with a blank line between them"
("dio")
@@ -7966,7 +7966,7 @@ maybe we need one line more with some text\n")
(evil-test-buffer
"These two lines \n[\n]!have punctuation on them"
("dao")
- ("These two lines [!]have punctuation on them"))))
+ "These two lines \n[!]have punctuation on them")))
(provide 'evil-tests)