Skip to content

Commit

Permalink
Make sure to restore state after executing motion
Browse files Browse the repository at this point in the history
This fixes a regression caused by commit 29a5d46.

Resolves #1756
  • Loading branch information
axelf4 committed Jan 20, 2023
1 parent 8a05eb9 commit 9f25e19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
71 changes: 35 additions & 36 deletions evil-macros.el
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ RETURN-TYPE is non-nil."
(or evil-this-type 'exclusive))))
;; motion
(t
(unless motion
(evil-save-state
(evil-save-state
(unless motion
;; Make linewise operator shortcuts. E.g., "d" yields the
;; shortcut "dd", and "g?" yields shortcuts "g??" and "g?g?".
(let ((keys (nth 2 (evil-extract-count (this-command-keys)))))
Expand All @@ -601,47 +601,46 @@ RETURN-TYPE is non-nil."
(let ((command (evil-read-motion motion)))
(setq motion (car command)
count (cadr command)
type (or type (nth 2 command))))))
(cond
((eq motion #'undefined)
(setq range (list nil nil)
motion nil))
((or (null motion) ; keyboard-quit
(evil-get-command-property motion :suppress-operator))
(evil-repeat-abort)
(setq quit-flag t
range (evil-range (point) (point)) ; zero-len range
motion nil))
(evil-repeat-count
(setq count evil-repeat-count
;; only the first operator's count is overwritten
evil-repeat-count nil))
((or count current-prefix-arg)
;; multiply operator count and motion count together
(setq count
(* (prefix-numeric-value count)
(prefix-numeric-value current-prefix-arg)))))
(when motion
(let ((evil-state 'operator)
mark-active)
;; calculate motion range
(setq range (evil-motion-range motion count type))))
;; update global variables
(setq evil-this-motion motion
evil-this-motion-count count
type (evil-type range type)
evil-this-type type))))
type (or type (nth 2 command)))))
(cond
((eq motion #'undefined)
(setq range (list nil nil)
motion nil))
((or (null motion) ; keyboard-quit
(evil-get-command-property motion :suppress-operator))
(evil-repeat-abort)
(setq quit-flag t
range (evil-range (point) (point)) ; zero-len range
motion nil))
(evil-repeat-count
(setq count evil-repeat-count
;; only the first operator's count is overwritten
evil-repeat-count nil))
((or count current-prefix-arg)
;; multiply operator count and motion count together
(setq count
(* (prefix-numeric-value count)
(prefix-numeric-value current-prefix-arg)))))
(when motion
(let ((evil-state 'operator)
mark-active)
;; calculate motion range
(setq range (evil-motion-range motion count type))))
;; update global variables
(setq evil-this-motion motion
evil-this-motion-count count
type (evil-type range type)
evil-this-type type)))))
(unless (or (null type) (eq (evil-type range) type))
(evil-contract-range range)
(evil-set-range-type range type)
(evil-expand-range range))
(setq evil-operator-range-beginning (evil-range-beginning range)
evil-operator-range-end (evil-range-end range)
evil-operator-range-type (evil-type range))
(if return-type
(list (car range) (cadr range) (evil-type range))
(setcdr (cdr range) nil)
range)))
(setcdr (cdr range)
(when return-type (list (evil-type range))))
range))

(defmacro evil-define-type (type doc &rest body)
"Define type TYPE.
Expand Down
6 changes: 6 additions & 0 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,12 @@ Below some empty line")))
("^`[")
"alpha b[r]")))

(ert-deftest evil-test-operator-save-state-for-motion ()
"Test that `evil-operator-range' restores state after executing motion."
(evil-test-buffer "abc"
("dfbix" [escape])
"xc"))

;;; Paste

(ert-deftest evil-test-paste-before ()
Expand Down

0 comments on commit 9f25e19

Please # to comment.