소스 검색

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
Kyle Meyer 3 년 전
부모
커밋
f2833ff255
2개의 변경된 파일13개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 5
      lisp/org.el
  2. 8 0
      testing/lisp/test-org.el

+ 5 - 5
lisp/org.el

@@ -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.")))

+ 8 - 0
testing/lisp/test-org.el

@@ -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)))))))