org-copy-visible: Fix handling of adjacent invisible text

* lisp/org.el (org-copy-visible): Don't copy invisible text that
follows invisible text with a different property value.

If org-copy-visible sees that the left bound position has a non-nil
invisible property, it uses next-single-char-property-change to find
the new bound.  However, next-single-char-property-change may just
find a bound that still has a _different_ non-nil invisible property.

Reported-by: "Максим Бабушкин" <maxbabushkin@gmail.com>
Link: https://debbugs.gnu.org/49967
This commit is contained in:
Kyle Meyer 2022-02-27 23:31:49 -05:00
parent e85a872f3b
commit f2833ff255
2 changed files with 13 additions and 5 deletions

View File

@ -17522,11 +17522,11 @@ this numeric value."
(interactive "r")
(let ((result ""))
(while (/= beg end)
(when (get-char-property beg 'invisible)
(setq beg (next-single-char-property-change beg 'invisible nil end)))
(let ((next (next-single-char-property-change beg 'invisible nil end)))
(setq result (concat result (buffer-substring beg next)))
(setq beg next)))
(if (get-char-property beg 'invisible)
(setq beg (next-single-char-property-change beg 'invisible nil end))
(let ((next (next-single-char-property-change beg 'invisible nil end)))
(setq result (concat result (buffer-substring beg next)))
(setq beg next))))
(setq deactivate-mark t)
(kill-new result)
(message "Visible strings have been copied to the kill ring.")))

View File

@ -8223,6 +8223,14 @@ CLOSED: %s
(equal "abc"
(org-test-with-temp-text
#("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
(let ((kill-ring nil))
(org-copy-visible (point-min) (point-max))
(current-kill 0 t)))))
;; Handle adjacent invisible parts.
(should
(equal "ab"
(org-test-with-temp-text
#("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
(let ((kill-ring nil))
(org-copy-visible (point-min) (point-max))
(current-kill 0 t)))))))