fix(ui): Correct mouse click cursor positioning for wide characters#13537
fix(ui): Correct mouse click cursor positioning for wide characters#13537
Conversation
Summary of ChangesHello @SandyTao520, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical UI bug affecting cursor positioning when users interact with wide characters in the CLI's input prompt. By overhauling the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Summary of ChangesHello @SandyTao520, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical UI bug where mouse clicks on wide characters within the CLI's input prompt would misplace the cursor. The core problem stemmed from an incorrect assumption about character width in visual rendering. The solution refines the cursor positioning logic to accurately account for multi-width characters, significantly improving the user experience for input involving internationalized text and ensuring precise cursor control. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an issue with mouse cursor positioning for wide characters by calculating character widths. The new logic in moveToVisualPosition properly iterates through characters to map a visual column to a logical character offset. The accompanying test case for CJK characters is a great addition.
I've found a critical issue where the new cursor snapping logic is incorrectly applied to single-width characters, which would break expected mouse behavior for regular text. I've also noted a high-severity issue regarding an inconsistency between the implementation and documentation for preferredCol that should be addressed to maintain code clarity. Please see my detailed comments.
|
Size Change: +450 B (0%) Total Size: 21.1 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request provides a solid fix for incorrect cursor positioning when clicking on wide characters. The logic in moveToVisualPosition is well-reasoned, correctly calculating the logical character offset from visual click coordinates by iterating through characters and summing their widths. This properly handles multi-column characters. The new test case for Chinese characters is comprehensive and effectively validates the fix. The related change to update preferredCol to use a logical offset is also a good improvement for consistent vertical navigation. The changes are correct and improve the user experience.
3425d99 to
d294e7b
Compare
…ing for wide characters (google-gemini#13537)

TLDR
This PR fixes an issue where clicking on wide characters (e.g., CJK characters) in the input prompt would position the cursor incorrectly. Previously, the logic assumed a 1:1 mapping between visual columns and character indices, which is incorrect for characters taking up multiple columns.
Dive Deeper
The
moveToVisualPositionfunction intext-buffer.tswas updated to correctly calculate the logical cursor position from a visual click coordinate.string-width).preferredColis updated to track the logical character offset rather than the raw visual column, improving vertical navigation consistency across lines with mixed character widths.Reviewer Test Plan
Testing Matrix
Linked issues / bugs