Skip to content

fix: Ensure syntax highlighting after expanding tool output (#32)#39

Merged
dnouri merged 1 commit intomasterfrom
fix/toggle-tool-fontification
Jan 7, 2026
Merged

fix: Ensure syntax highlighting after expanding tool output (#32)#39
dnouri merged 1 commit intomasterfrom
fix/toggle-tool-fontification

Conversation

@dnouri
Copy link
Owner

@dnouri dnouri commented Jan 7, 2026

Summary

Fix syntax highlighting lost when expanding collapsed tool output.

Problem

When expanding collapsed tool output (clicking ... (N more lines)), syntax highlighting was missing. It would appear erratically "bit by bit" when scrolling around because JIT font-lock only fontifies visible portions lazily.

Root Cause

--toggle-tool-output calls --insert-expanded-content which inserts markdown code fences but never calls font-lock-ensure.

Compare with:

  • --finalize-streaming-message (line 1064) - calls font-lock-ensure
  • --render-history-text (line 1831) - calls font-lock-ensure

Fix

Add font-lock-ensure call after inserting expanded/collapsed content in --toggle-tool-output:

(if expanded
    (pi-coding-agent--insert-collapsed-content ...)
  (pi-coding-agent--insert-expanded-content ...))
;; Ensure fontification of inserted content (JIT font-lock is lazy)
(font-lock-ensure content-start (point))

Test Added

pi-coding-agent-test-tool-toggle-expands-with-highlighting - verifies that after expanding, Python keywords have font-lock-keyword-face.

Closes #32

Add font-lock-ensure call after toggling tool output. JIT font-lock
only fontifies visible portions lazily, so expanding collapsed content
left it unhighlighted until the user scrolled around.

The fix follows the established pattern from --finalize-streaming-message
and --render-history-text which both call font-lock-ensure after
inserting content.
@dnouri dnouri merged commit d9b096a into master Jan 7, 2026
6 checks passed
@dnouri dnouri deleted the fix/toggle-tool-fontification branch January 7, 2026 14:40
dnouri added a commit that referenced this pull request Feb 25, 2026
Add font-lock-ensure call after toggling tool output. JIT font-lock
only fontifies visible portions lazily, so expanding collapsed content
left it unhighlighted until the user scrolled around.

The fix follows the established pattern from --finalize-streaming-message
and --render-history-text which both call font-lock-ensure after
inserting content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax highlighting lost when expanding collapsed tool output

1 participant