diff --git a/lisp/org.el b/lisp/org.el index df482d0f3..6c9ff3026 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -21389,13 +21389,13 @@ With ARG, repeats or can move backward if negative." (end-of-line)) (while (and (< arg 0) (re-search-backward regexp nil :move)) (unless (bobp) - (when (org-fold-folded-p) + (when (org-invisible-p nil t) (goto-char (org-fold-previous-visibility-change)) (unless (looking-at-p regexp) (re-search-backward regexp nil :mode)))) (cl-incf arg)) (while (and (> arg 0) (re-search-forward regexp nil :move)) - (when (org-fold-folded-p) + (when (org-invisible-p nil t) (goto-char (org-fold-next-visibility-change)) (skip-chars-forward " \t\n") (end-of-line)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 2fab3ff88..62d841b37 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -4069,7 +4069,13 @@ text" (should (org-test-with-temp-text "* H1\n* H2\n* H3" (org-next-visible-heading -2) - (looking-at "\\* H1")))) + (looking-at "\\* H1"))) + ;; Edge case: visible links. + (should + (let ((org-link-descriptive nil)) + (org-test-with-temp-text "* H1\n* [[https://orgmode.org][Org mode]]\n* H3" + (org-next-visible-heading 1) + (looking-at "\\* \\[\\[https:"))))) (ert-deftest test-org/previous-visible-heading () "Test `org-previous-visible-heading' specifications."