From 2e8576188b1d0768fbf92c6bea2fb3fbed9f019f Mon Sep 17 00:00:00 2001 From: Tom Dalziel <33435574+tomdl89@users.noreply.github.com> Date: Tue, 22 Nov 2022 15:50:12 +0100 Subject: Only restrict objects when current line is not empty (#1721) --- evil-common.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/evil-common.el b/evil-common.el index ba9f137..15095d9 100644 --- a/evil-common.el +++ b/evil-common.el @@ -3153,7 +3153,7 @@ linewise, otherwise it is character wise." (defun evil-select-inner-restricted-object (thing beg end type &optional count line) "Return an inner text object range of COUNT objects. -Selection is restricted to the current line. +Selection is restricted to the current line, unless it is empty. If COUNT is positive, return objects following point; if COUNT is negative, return objects preceding point. If one is unspecified, the other is used with a negative argument. THING is a symbol @@ -3161,8 +3161,10 @@ understood by `thing-at-point'. BEG, END and TYPE specify the current selection. If LINE is non-nil, the text object should be linewise, otherwise it is character wise." (save-restriction - (narrow-to-region (save-excursion (beginning-of-line) (point)) - (save-excursion (end-of-line) (point))) + (let ((start (save-excursion (beginning-of-line) (point))) + (end (save-excursion (end-of-line) (point)))) + (when (/= start end) + (narrow-to-region start end))) (evil-select-inner-object thing beg end type count line))) (defun evil-select-an-object (thing beg end type count &optional line) @@ -3246,7 +3248,7 @@ linewise, otherwise it is character wise." (defun evil-select-a-restricted-object (thing beg end type &optional count line) "Return an outer text object range of COUNT objects. -Selection is restricted to the current line. +Selection is restricted to the current line, unless it is empty. If COUNT is positive, return objects following point; if COUNT is negative, return objects preceding point. If one is unspecified, the other is used with a negative argument. THING is a symbol @@ -3254,8 +3256,10 @@ understood by thing-at-point. BEG, END and TYPE specify the current selection. If LINE is non-nil, the text object should be linewise, otherwise it is character wise." (save-restriction - (narrow-to-region (save-excursion (beginning-of-line) (point)) - (save-excursion (end-of-line) (point))) + (let ((start (save-excursion (beginning-of-line) (point))) + (end (save-excursion (end-of-line) (point)))) + (when (/= start end) + (narrow-to-region start end))) (evil-select-an-object thing beg end type count line))) (defun evil--get-block-range (op cl selection-type) -- cgit v1.0