org-fold-core-fontify-region: Calculate jit-lock-bounds accurately

* lisp/org-fold-core.el (org-fold-core-fontify-region): Collect all
the return values of `font-lock-default-fontify-region' on visible
regions and extend jit-lock-bounds accordingly.
This commit is contained in:
Ihor Radchenko 2022-04-24 18:01:43 +08:00
parent 2249f4d7e5
commit 24c1c877cf
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 1 deletions

View File

@ -1467,7 +1467,16 @@ folded regions.")
(< next end))
(setq next (org-fold-core-next-folding-state-change nil next end))))
(save-excursion
(setq font-lock-return-value (font-lock-default-fontify-region pos next loudly))
;; Keep track of the actually fontified region.
(pcase (font-lock-default-fontify-region pos next loudly)
(`(jit-lock-bounds ,beg . ,end)
(pcase font-lock-return-value
(`(jit-lock-bounds ,oldbeg . ,oldend)
(setq font-lock-return-value
`(jit-lock-bounds
,(min oldbeg beg)
,(max oldend end))))
(value (setq font-lock-return-value value)))))
(save-match-data
;; Only run within regions that are not yet touched by
;; fontification.