]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix regression in widget-move (bug#72995)
authorStephen Berman <stephen.berman@gmx.net>
Sat, 14 Sep 2024 10:42:49 +0000 (12:42 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 14 Sep 2024 20:34:45 +0000 (22:34 +0200)
* lisp/wid-edit.el (widget-move): Avoid advancing point only if it
is at the start of a widget at BOB.

* test/lisp/wid-edit-tests.el (widget-test-widget-move-bug72995): New test.

(cherry picked from commit d509a35699738519d42a35d72827b1111425669c)

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

index 693991a6f3eb41213c0fe7ae0d5ba6ff32e5fc33..21904acf2838881157daa0dd1a309a872643a8f0 100644 (file)
@@ -1336,7 +1336,10 @@ nothing is shown in the echo area."
     (let ((new (widget-tabable-at)))
       (while (and (eq (widget-tabable-at) new) (not (bobp)))
        (backward-char)))
-    (unless (bobp) (forward-char)))
+    ;; If the widget is at BOB, point is already at the widget's
+    ;; starting position; otherwise, advance point to put it at the
+    ;; start of the widget (cf. bug#69943 and bug#72995).
+    (unless (and (widget-tabable-at) (bobp)) (forward-char)))
   (unless suppress-echo
     (widget-echo-help (point)))
   (run-hooks 'widget-move-hook))
index d416eb990228fbfce4e410d9831eee9c32c0a1a5..03e7e5a7b7dd7d942a1516634942ff3cd636dbdb 100644 (file)
@@ -344,6 +344,23 @@ return nil, even with a non-nil bubblep argument."
     (should (string= "Third" (widget-value (widget-at))))
     (widget-forward 1)))  ; Should not signal beginning-of-buffer error.
 
+(ert-deftest widget-test-widget-move-bug72995 ()
+  "Test moving to a widget that starts at buffer position 2."
+  (with-temp-buffer
+    ;; The first tabable widget begins at position 2 (bug#72995).
+    (widget-insert " ")
+    (dolist (el '("First" "Second" "Third"))
+      (widget-create 'push-button el))
+    (widget-insert "\n")
+    (use-local-map widget-keymap)
+    (widget-setup)
+    ;; Make sure there is no tabable widget at BOB.
+    (goto-char (point-min))
+    (should-not (widget-tabable-at))
+    ;; Check that we can move to the first widget after BOB.
+    (widget-forward 1)
+    (should (widget-tabable-at))))
+
 (ert-deftest widget-test-color-match ()
   "Test that the :match function for the color widget works."
   (let ((widget (widget-convert 'color)))