branch: externals/shift-number
commit 440505f14a38cb73b91c156e24c8445869e3cf3c
Author: Campbell Barton <[email protected]>
Commit: Campbell Barton <[email protected]>
Prevent the point "leaving" numbers
While keeping the point in-place works,
this should not cause the point to move outside the number.
Ensure the point remains in the numbers bounds.
---
shift-number.el | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/shift-number.el b/shift-number.el
index 0990052033..3168545c2c 100644
--- a/shift-number.el
+++ b/shift-number.el
@@ -111,6 +111,16 @@ the current line and change it."
(when (> len-diff 0)
(insert (make-string len-diff ?0)))))
(insert new-num-str)
+
+ (cond
+ ;; If the point was exactly at the end, keep it there.
+ ((eq old-pos end)
+ (setq old-pos (point)))
+ ;; Prevent the change causing the cursor to "leave" the number,
+ ;; allowing for further adjustments.
+ (t
+ (setq old-pos (min (point) old-pos))))
+
(goto-char old-pos)
(when shift-number-display-message
(message "Number %d has been changed to number %d."