aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMauro Aranda2025-01-17 17:12:08 -0300
committerEli Zaretskii2025-02-05 15:08:28 +0200
commit85113fcda97970bc2468f409278e27d6570fc76f (patch)
treed91a3ca509cf9f26075d3c39b592a3e86cc6fc98 /test
parenta1f2f5995d69db646f58a7203ab6208556f0df4b (diff)
downloademacs-85113fcda97970bc2468f409278e27d6570fc76f.tar.gz
emacs-85113fcda97970bc2468f409278e27d6570fc76f.zip
Prepare markers for insertions inside of a widget
Recreating child widgets without recreating the parent widget may lead to situations where the parent widget doesn't cover its children or buttons entirely anymore. This bug manifests as a faulty fontification of children or buttons, for example. (Bug#69941) * lisp/wid-edit.el (widget--prepare-markers-for-inside-insertion) (widget--prepare-markers-for-outside-insertion): New functions. (widget-default-create): Use them. * test/lisp/wid-edit-tests.el (widget-test-insertion-at-parent-markers) (widget-test-insertion-at-parent-markers-2): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/wid-edit-tests.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index c18e6d14c4c..e34aa64f8d1 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -430,4 +430,55 @@ return nil, even with a non-nil bubblep argument."
430 (should-not (overlay-buffer field-overlay)) 430 (should-not (overlay-buffer field-overlay))
431 (should-not (overlay-buffer field-end-overlay))))) 431 (should-not (overlay-buffer field-end-overlay)))))
432 432
433;; The following two tests are for Bug#69941. Markers need to be prepared
434;; against "inside" insertions at them. That is, a recreated child should
435;; still be covered by the parent's :from and :to markers.
436(ert-deftest widget-test-insertion-at-parent-markers ()
437 "Test that recreating a child keeps the parent's markers covering it.
438
439Test the most common situation, where only one parent needs to be adjusted."
440 (with-temp-buffer
441 (let* ((group (widget-create 'group
442 :format "%v"
443 '(item :value 1 :format "%v")))
444 (item (car (widget-get group :children)))
445 (ofrom (marker-position (widget-get group :from)))
446 (oto (marker-position (widget-get group :to))))
447 (widget-insert "\n")
448 (widget-setup)
449 ;; Change item, without recreating the group. This causes changes
450 ;; right at the :from and :to markers, and if they don't have
451 ;; the right type, the group's :from-:to span won't include its
452 ;; child, the item widget, anymore.
453 (widget-value-set item 2)
454 ;; The positions should be the same as they were when the group
455 ;; widget was first created.
456 (should (= ofrom (widget-get group :from)))
457 (should (= oto (widget-get group :to))))))
458
459(ert-deftest widget-test-insertion-at-parent-markers-2 ()
460 "Test that recreating a child keeps the parent's marker covering it.
461
462Test the uncommon situation in which we might need to prepare the grandparent's
463markers (and so on) as well."
464 (with-temp-buffer
465 (let* ((group (widget-create '(group
466 :format "%v"
467 (group
468 :format "%v"
469 (item :value 1 :format "%v")))))
470 (group2 (car (widget-get group :children)))
471 (item (car (widget-get group2 :children)))
472 (ofrom (marker-position (widget-get group :from)))
473 (oto (marker-position (widget-get group :to)))
474 (ofrom2 (marker-position (widget-get group2 :from)))
475 (oto2 (marker-position (widget-get group2 :to))))
476 (widget-insert "\n")
477 (widget-setup)
478 (widget-value-set item 2)
479 (should (= ofrom (widget-get group :from)))
480 (should (= oto (widget-get group :to)))
481 (should (= ofrom2 (widget-get group2 :from)))
482 (should (= oto2 (widget-get group2 :to))))))
483
433;;; wid-edit-tests.el ends here 484;;; wid-edit-tests.el ends here