Visitar URL original
Fix UTF-16 column counts in TextLength by shoutoutuoadi325 · Pull Request #345715 · microsoft/vscode · GitHub
Skip to content

Fix UTF-16 column counts in TextLength - #345715

Merged
Alexandru Dima (alexdima) merged 1 commit into
microsoft:mainfrom
shoutoutuoadi325:fix/text-length-utf16-columns
Nov 13, 2026
Merged

Alexandru Dima (alexdima) merged 1 commit into
microsoft:mainfrom
shoutoutuoadi325:fix/text-length-utf16-columns

Conversation

@shoutoutuoadi325

Copy link
Copy Markdown
Contributor

Fixes #345714.

TextLength.ofText undercounts supplementary Unicode characters because its string iterator yields code points while editor columns use UTF-16 code units. Inserting an emoji and applying the inverse edit leaves a lone surrogate; trimming a completion's common prefix can delete an existing character at a secondary cursor. Count each yielded string's UTF-16 length so inverse ranges and multicursor completions preserve the original text.

Added regressions for UTF-16 length calculation, multiline and multiple-edit inverses, common prefix/suffix reduction, and the actual getSecondaryEdits path. All seven new regressions fail before the fix and pass afterward.

Validation on macOS arm64, Node.js 24.22.1, pnpm 12.16.0:

  • pnpm run build-fast --client-only: passed.
  • pnpm run test-node --runGlob 'vs/editor/test/common/core/{textEdit,textLength}.test.js': 127 passed, 2 existing skipped fuzz tests.
  • pnpm run test-browser-no-install --browser chromium-chrome --run src/vs/editor/contrib/inlineCompletions/test/browser/getSecondaryEdits.test.ts: 4 passed using local Chrome.
  • pnpm run eslint on all four changed files: passed.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@shoutoutuoadi325

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@cartertaee3-boop cartertaee3-boop mentioned this pull request Nov 13, 2026
@alexdima
Alexandru Dima (alexdima) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit 944e57d Nov 13, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 13, 2026
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.

TextLength undercounts UTF-16 columns and corrupts inverse and multicursor edits

6 participants