diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 4ff4a2fc0..3f5bd2121 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -1289,6 +1289,8 @@ instead of text properties. The created overlays will be stored in "Non-nil: skip processing modifications in `org-fold-core--fix-folded-region'.") (defvar org-fold-core--ignore-fragility-checks nil "Non-nil: skip fragility checks in `org-fold-core--fix-folded-region'.") +(defvar org-fold-core--suppress-folding-fix nil + "Non-nil: skip folding fix in `org-fold-core--fix-folded-region'.") (defmacro org-fold-core-ignore-modifications (&rest body) "Run BODY ignoring buffer modifications in `org-fold-core--fix-folded-region'." @@ -1297,6 +1299,12 @@ instead of text properties. The created overlays will be stored in (unwind-protect (progn ,@body) (setq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick))))) +(defmacro org-fold-core-suppress-folding-fix (&rest body) + "Run BODY skipping re-folding checks in `org-fold-core--fix-folded-region'." + (declare (debug (form body)) (indent 0)) + `(let ((org-fold-core--suppress-folding-fix t)) + (progn ,@body))) + (defmacro org-fold-core-ignore-fragility-checks (&rest body) "Run BODY skipping :fragility checks in `org-fold-core--fix-folded-region'." (declare (debug (form body)) (indent 0)) @@ -1330,7 +1338,7 @@ property, unfold the region if the :fragile function returns non-nil." ;; buffer. Work around Emacs bug#46982. ;; Re-hide text inserted in the middle/front/back of a folded ;; region. - (unless (equal from to) ; Ignore deletions. + (unless (or org-fold-core--suppress-folding-fix (equal from to)) ; Ignore deletions. (when (eq org-fold-core-style 'text-properties) (org-fold-core-cycle-over-indirect-buffers (dolist (spec (org-fold-core-folding-spec-list)) diff --git a/lisp/org.el b/lisp/org.el index 57379c26a..cf9abafac 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16768,7 +16768,8 @@ overwritten, and the table is not marked as requiring realignment." t) (looking-at "[^|\n]* |")) ;; There is room for insertion without re-aligning the table. - (org-fold-core-ignore-modifications + ;; Interactively, point should never be inside invisible regions + (org-fold-core-suppress-folding-fix (self-insert-command N)) (org-table-with-shrunk-field (save-excursion @@ -16779,7 +16780,8 @@ overwritten, and the table is not marked as requiring realignment." (delete-region (- (point) 2) (1- (point)))))) (t (setq org-table-may-need-update t) - (org-fold-core-ignore-modifications + ;; Interactively, point should never be inside invisible regions + (org-fold-core-suppress-folding-fix (self-insert-command N) (org-fix-tags-on-the-fly)) (when org-self-insert-cluster-for-undo diff --git a/testing/lisp/test-org-fold.el b/testing/lisp/test-org-fold.el index 955ebc417..22f17977f 100644 --- a/testing/lisp/test-org-fold.el +++ b/testing/lisp/test-org-fold.el @@ -471,6 +471,17 @@ Text here" (org-delete-char 1) (re-search-forward "Text") (should-not (org-invisible-p))) + (org-test-with-temp-text + "* Heading 1 +Text here" + (org-overview) + (re-search-forward "Text") + (should (org-invisible-p)) + (goto-char 1) + (let ((last-command-event ?a)) + (org-self-insert-command 1)) + (re-search-forward "Text") + (should-not (org-invisible-p))) (org-test-with-temp-text "* Heading 1 :PROPERTIES: