fix(chat): stabilize fenced code block redisplay#258
Open
itkonen wants to merge 1 commit into
Open
Conversation
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>
57359ee to
d0c4780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-markupis enabled.ECA recently optimized chat rendering by deferring intermediate
font-lock-ensurecalls 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:
font-lock-ensureover the same scoped regions as beforeThe 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
check-parenspassed for the changed source and test files.buttercup/easkwere unavailable there.🤖 Generated with ECA (openai/gpt-5.5 - high)