Images visible when org headings are collapsed (#1)
sportmacher opened 2 months ago

Reported by: pathemata (Reddit)

Image overlays remain visible when org headings are folded/collapsed. The overlays should be hidden (placement deleted) when their containing heading is collapsed, and re-placed when the heading is expanded.

This likely requires hooking into org's visibility change mechanism (org-cycle-hook or org-after-todo-state-change-hook) to detect when a heading's body becomes invisible, and then deleting the terminal placement for any overlays in the hidden region.

Steps to reproduce:

  1. Open an org file with inline images under a heading
  2. C-c C-x C-v to display inline images
  3. Collapse the heading with TAB
  4. Images remain visible on screen even though the text is hidden

Expected: Images disappear when heading is collapsed, reappear when expanded.

  • sportmacher commented 2 months ago

    Fix implemented with two changes:

    1. kitty-gfx--overlay-screen-pos: Added (not (invisible-p pos)) check. When org folds a heading, the text gets an invisible property. Previously, pos-visible-in-window-p alone didn't detect this — it only checks the window scroll range, not text invisibility. Now overlays in invisible regions return nil from screen-pos, causing the refresh cycle to delete their terminal placements.

    2. kitty-gfx--on-org-cycle: New function hooked into org-cycle-hook. When org cycles heading visibility, this clears the position cache on all overlays and schedules a refresh, ensuring images are immediately hidden/shown rather than waiting for the next post-command-hook.

    Byte-compiles and load-tests clean. Needs manual testing in a Kitty-compatible terminal.

  • sportmacher changed state to 'In Review' 2 months ago
    Previous Value Current Value
    Open
    In Review
  • sportmacher commented 2 months ago

    Verified working by user. Heading collapse now correctly hides images, expand shows them again.

    Root cause was twofold:

    1. invisible-p was too broad (caught org-link bracket hiding) — replaced with kitty-gfx--in-folded-region-p using org-fold-folded-p
    2. kitty-gfx--on-org-cycle cleared the position cache (last-row → nil) before the refresh ran, causing the refresh's else branch (when last-row ...) to skip placement deletion. Fixed by explicitly deleting all current-buffer placements in the org-cycle handler before clearing cache.
  • sportmacher commented 2 months ago

    Fixed in b239825. Images now hide when org headings are collapsed and reappear when expanded. Uses org-fold-folded-p for org 9.6+ with legacy fallback. User verified working.

  • sportmacher changed state to 'Closed' 2 months ago
    Previous Value Current Value
    In Review
    Closed
issue 1/1
Type
Bug
Priority
Critical
Assignees
Not assigned
Issue Votes (0)
Watchers (1)
Reference
cashmere/kitty-graphics#1
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover