Skip to content

fix(chat): stabilize fenced code block redisplay#258

Open
itkonen wants to merge 1 commit into
editor-code-assistant:masterfrom
itkonen:fix/jumping-fenced-code-block
Open

fix(chat): stabilize fenced code block redisplay#258
itkonen wants to merge 1 commit into
editor-code-assistant:masterfrom
itkonen:fix/jumping-fenced-code-block

Conversation

@itkonen

@itkonen itkonen commented Jun 17, 2026

Copy link
Copy Markdown

Personal note

I ran into a very irritating display issue while using ECA chat: fenced code blocks in assistant responses would visibly jump up and down in the chat buffer. The text content itself was fine, and normal prose stayed stable, but code blocks seemed to have an extra blank line around them and would snap into a different position after I moved point or even while I was typing my next prompt.

This made streamed answers with code blocks hard to read, especially because the block appeared to remain rendered the whole time—the problem looked like the visual layout around hidden markdown fences was unstable rather than the response content changing.

AI summary

This PR fixes a chat redisplay instability around fenced markdown code blocks when markdown-hide-markup is enabled.

ECA recently optimized chat rendering by deferring intermediate font-lock-ensure calls during assistant streaming. That keeps long chats faster, but it means streamed text can be inserted first and markdown fontification/invisibility can be applied later. For regular prose this is stable, but fenced code blocks are sensitive because markdown fontification hides the fence markup while the physical fence lines still affect display geometry.

In affected setups, after deferred fontification hid the fenced-block markup, Emacs could leave the visible layout stale until a later redisplay trigger such as point movement or prompt typing. That made a blank line around the code block appear to move and caused the code block to visually jump even though the underlying buffer content was unchanged.

The fix keeps the deferred-fontification strategy, but routes chat fontification through a small wrapper that:

  • preserves the visible window starts for chat buffers while fontifying
  • calls font-lock-ensure over the same scoped regions as before
  • requests a window redisplay update afterward so hidden fenced-block markup settles immediately

The wrapper is used for both the deferred streaming fontification path and the final end-of-stream fontification path. Tests cover the wrapper itself and verify that both deferred and final chat fontification use the stabilizing path.

Testing

  • Manually tested in a local Spacemacs setup by loading ECA from this worktree and verifying that streamed fenced code blocks no longer jump.
  • check-parens passed for the changed source and test files.
  • Editor diagnostics reported no issues for the changed files.
  • Full Buttercup tests were not runnable in the local shell environment because buttercup/eask were unavailable there.

🤖 Generated with ECA (openai/gpt-5.5 - high)

Hidden markdown markup can change visual layout after deferred chat
fontification. Preserve visible window starts and request a redisplay update
when streaming and final chat fontification run, so fenced code blocks settle
without waiting for later point motion.

Add tests covering the stable fontification wrapper and its use from deferred
and final chat fontification paths.

🤖 Generated with [ECA](https://eca.dev) (openai/gpt-5.5 - high)

Co-Authored-By: eca-agent <git@eca.dev>
@itkonen itkonen force-pushed the fix/jumping-fenced-code-block branch from 57359ee to d0c4780 Compare June 25, 2026 03:54
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.

1 participant