Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

maxContentWidthInRange logs an unexpected width error when called on the long distance hint preview editor before it's rendered. This occurs because getWidthOfLine returns -1 for unrendered editors, which wasn't handled.

Changes

  • Handle getWidthOfLine returning -1 by using a character-width-based approximation, consistent with the sibling function getContentSizeOfLines
  • Remove the now-unnecessary error logging
// Before: no handling for unrendered editor case
const lineContentWidth = editor.getWidthOfLine(i, reader);
maxContentWidth = Math.max(maxContentWidth, lineContentWidth);

// After: approximate width when editor not yet rendered
let lineContentWidth = editor.getWidthOfLine(i, reader);
if (lineContentWidth === -1) {
    const column = model.getLineMaxColumn(i);
    const typicalHalfwidthCharacterWidth = editor.editor.getOption(EditorOption.fontInfo).typicalHalfwidthCharacterWidth;
    lineContentWidth = column * typicalHalfwidthCharacterWidth;
}
maxContentWidth = Math.max(maxContentWidth, lineContentWidth);
Original prompt

This section details on the original issue you should resolve

<issue_title>NES: Long Distance Hint can cause unexpected width error</issue_title>
<issue_description>maxContentWidthInRange sometimes logs an unexpected width error for the preview editor in the long distance hint. The long distance hint then shows an empty preview.

Seems to only happen on first layout. We run maxContentWidthInRange before we ever called layout on the preview editor, can that cause an issue?</issue_description>

Comments on the Issue (you are @copilot in this section)

@hediet It can happen when the editor is not rendered yet.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ditors

Handle case when getWidthOfLine returns -1 (editor not yet rendered) by
using an approximation based on line column count and character width,
consistent with getContentSizeOfLines.

Co-authored-by: benibenj <44439583+benibenj@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unexpected width error in long distance hint Fix unexpected width error in long distance hint preview editor Jan 26, 2026
Copilot AI requested a review from benibenj January 26, 2026 17:16
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.

NES: Long Distance Hint can cause unexpected width error

2 participants