fix(markdown-compose): measure table cells by display width#2477
Merged
Conversation
Table column sizing and cell padding measured text with JS `String.length` (UTF-16 code units), so a trailing 2-cell-wide glyph (emoji such as `✅`, CJK, …) counted as 1 column while it renders as 2. Non-cursor rows were padded one column too wide, pushing their right border past the box frame; the cursor's own row (rendered raw) stayed correct, so the border appeared to flicker as the cursor moved over it. Route the four width-measuring sites through a `displayWidth()` helper backed by `editor.stringWidth` (added in #2401, itself backed by `fresh_core::display_width`), so the plugin measures cells exactly as the renderer lays them out. Fixes #2475 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
In Markdown compose/preview mode, the right border of a rendered table is drawn one column too far right on any row whose last cell ends in a 2-cell-wide glyph (emoji such as
✅, CJK, …). Because the current (cursor) line is rendered raw and stays correctly aligned, the border appears to flicker/pop as the cursor moves over each emoji row. Rows without a wide trailing glyph are unaffected. Fixes #2475.Root cause
The
markdown_composeplugin measured cell text with JSString.length(UTF-16 code units), so✅(U+2705) counted as 1 column while the renderer lays it out as 2. Non-cursor rows were therefore padded one column too wide, pushing their right│past the┌┐└┘├┼┤box frame.Fix
Add a small
displayWidth()helper backed byeditor.stringWidth— the plugin API added in #2401, itself backed byfresh_core::display_width— so the plugin measures cells exactly as the editor lays out terminal cells. Routed the four width-measuring sites through it:processTableAlignmentVerification
Reproduced and verified in tmux (110×30,
xterm-256color) with the example file from #2475:Plugin type checks pass (
plugins/check-types.sh).Related
editor.charWidth/editor.stringWidthto plugins (the API this fix uses).🤖 Generated with Claude Code