Don't error on tabbing to a widget at BOB (bug#69943)
authorStephen Berman <stephen.berman@gmx.net>
Thu, 18 Apr 2024 13:35:49 +0000 (15:35 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Thu, 18 Apr 2024 13:35:49 +0000 (15:35 +0200)
* lisp/wid-edit.el (widget-move): Don't move backward when at
beginning of buffer, and keep point on widget's left side.

* test/lisp/wid-edit-tests.el (widget-test-widget-move): Test that
moving to a widget at beginning of buffer does not signal a
beginning-of-buffer error.

lisp/wid-edit.el
test/lisp/wid-edit-tests.el

index cb6d8ebc2c4b2023313dc1b82e3537c6ab83aa3e..dc481d4d0a548712c28b91bab6e9019b2d0cd52b 100644 (file)
@@ -1300,9 +1300,9 @@ nothing is shown in the echo area."
          (unless (eq new old)
            (setq arg (1+ arg))))))
     (let ((new (widget-tabable-at)))
-      (while (eq (widget-tabable-at) new)
+      (while (and (eq (widget-tabable-at) new) (not (bobp)))
        (backward-char)))
-    (forward-char))
+    (unless (bobp) (forward-char)))
   (unless suppress-echo
     (widget-echo-help (point)))
   (run-hooks 'widget-move-hook))
index 4b049478b29e17066f21bb84dc9c4cefb015597c..d416eb990228fbfce4e410d9831eee9c32c0a1a5 100644 (file)
@@ -336,7 +336,13 @@ return nil, even with a non-nil bubblep argument."
     (widget-forward 2)
     (forward-char)
     (widget-backward 1)
-    (should (string= "Second" (widget-value (widget-at))))))
+    (should (string= "Second" (widget-value (widget-at))))
+    ;; Check that moving to a widget at beginning of buffer does not
+    ;; signal a beginning-of-buffer error (bug#69943).
+    (widget-backward 1)   ; Should not signal beginning-of-buffer error.
+    (widget-forward 2)
+    (should (string= "Third" (widget-value (widget-at))))
+    (widget-forward 1)))  ; Should not signal beginning-of-buffer error.
 
 (ert-deftest widget-test-color-match ()
   "Test that the :match function for the color widget works."