Fix text-property-search-backward skipping one character regions

* lisp/emacs-lisp/text-property-search.el
(text-property-search-backward)
(text-property--find-end-backward): Fix skipping one character
non-matching regions (bug#81539).
* test/lisp/emacs-lisp/text-property-search-tests.el
(text-property-setup): Make one of the propertized regions one
character long to test bug#81539.
(text-property-search-forward-bold-nil)
(text-property-search-forward-nil-nil)
(text-property-search-backward-bold-nil)
(text-property-search-backward-nil-nil)
(text-property-search-backward-prop-match-match-face-nil-nil)
(text-property-search-backward-prop-match-match-face-italic-t)
(text-property-search-backward-prop-match-match-face-italic-nil):
Update tests.
This commit is contained in:
Sean Whitton 2026-08-05 12:28:55 +01:00
parent e54ba84245
commit ed1a2e8239
2 changed files with 13 additions and 13 deletions

View file

@ -174,12 +174,12 @@ and if a matching region is found, place point at the start of the region."
(progn
(goto-char origin)
(setq ended t))
(goto-char (1- pos))
(if (text-property--match-p value (get-text-property (point) property)
(goto-char pos)
(if (text-property--match-p value (get-text-property (1- (point)) property)
predicate)
(setq ended
(text-property--find-end-backward
(point) property value predicate))
(1- (point)) property value predicate))
;; Skip past this section of non-matches.
(setq pos (previous-single-property-change (point) property))
(unless pos
@ -203,9 +203,9 @@ and if a matching region is found, place point at the start of the region."
(goto-char (point-min))
(setq end (point)
ended t))
(goto-char (1- end))
(goto-char end)
(unless (text-property--match-p
value (get-text-property (point) property) predicate)
value (get-text-property (1- (point)) property) predicate)
(goto-char end)
(setq ended t)))))
;; End this at the first place the property changes value.

View file

@ -36,7 +36,7 @@
" and this is "
(propertize "italic1" 'face 'italic)
(propertize "bold2" 'face 'bold)
(propertize "italic2" 'face 'italic)
(propertize "i" 'face 'italic) ; One char long to test bug#81539.
" at the end")
(goto-char (point-min)))
@ -59,7 +59,7 @@
(ert-deftest text-property-search-forward-bold-nil ()
(with-test (text-property-search-forward 'face 'bold nil)
'("This is " " and this is italic1" "italic2 at the end")))
'("This is " " and this is italic1" "i at the end")))
(ert-deftest text-property-search-forward-nil-t ()
(with-test (text-property-search-forward 'face nil t)
@ -67,7 +67,7 @@
(ert-deftest text-property-search-forward-nil-nil ()
(with-test (text-property-search-forward 'face nil nil)
'("bold1" "italic1" "bold2" "italic2")))
'("bold1" "italic1" "bold2" "i")))
(ert-deftest text-property-search-forward-partial-bold-t ()
(with-test (text-property-search-forward 'face 'bold t)
@ -87,7 +87,7 @@
(ert-deftest text-property-search-backward-bold-nil ()
(with-test (text-property-search-backward 'face 'bold nil)
'( "italic2 at the end" " and this is italic1" "This is ")
'("i at the end" " and this is italic1" "This is ")
(point-max)))
(ert-deftest text-property-search-backward-nil-t ()
@ -97,7 +97,7 @@
(ert-deftest text-property-search-backward-nil-nil ()
(with-test (text-property-search-backward 'face nil nil)
'("italic2" "bold2" "italic1" "bold1")
'("i" "bold2" "italic1" "bold1")
(point-max)))
(ert-deftest text-property-search-backward-partial-bold-t ()
@ -138,19 +138,19 @@
(ert-deftest text-property-search-backward-prop-match-match-face-nil-nil ()
(with-match-test
(text-property-search-backward 'face nil nil)
39 46 'italic
39 40 'italic
(point-max)))
(ert-deftest text-property-search-backward-prop-match-match-face-italic-t ()
(with-match-test
(text-property-search-backward 'face 'italic t)
39 46 'italic
39 40 'italic
(point-max)))
(ert-deftest text-property-search-backward-prop-match-match-face-italic-nil ()
(with-match-test
(text-property-search-backward 'face 'italic nil)
46 57 nil
40 51 nil
(point-max)))