-
Notifications
You must be signed in to change notification settings - Fork 14.2k
fix(patch): cherry-pick ab6b229 to release/v0.16.0-preview.2-pr-13101 to patch version v0.16.0-preview.2 and create version 0.16.0-preview.3 #13110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ export interface MouseEvent { | |
| shift: boolean; | ||
| meta: boolean; | ||
| ctrl: boolean; | ||
| button: 'left' | 'middle' | 'right' | 'none'; | ||
| } | ||
|
|
||
| export type MouseHandler = (event: MouseEvent) => void | boolean; | ||
|
|
@@ -71,6 +72,20 @@ export function getMouseEventName( | |
| } | ||
| } | ||
|
|
||
| function getButtonFromCode(code: number): MouseEvent['button'] { | ||
| const button = code & 3; | ||
| switch (button) { | ||
| case 0: | ||
| return 'left'; | ||
| case 1: | ||
| return 'middle'; | ||
| case 2: | ||
| return 'right'; | ||
| default: | ||
| return 'none'; | ||
| } | ||
| } | ||
|
|
||
| export function parseSGRMouseEvent( | ||
| buffer: string, | ||
| ): { event: MouseEvent; length: number } | null { | ||
|
|
@@ -98,6 +113,7 @@ export function parseSGRMouseEvent( | |
| shift, | ||
| col, | ||
| row, | ||
| button: getButtonFromCode(buttonCode), | ||
| }, | ||
| length: match[0].length, | ||
| }; | ||
|
|
@@ -165,8 +181,21 @@ export function parseX11MouseEvent( | |
| } | ||
|
|
||
| if (name) { | ||
| let button = getButtonFromCode(b); | ||
| if (name === 'left-release' && button === 'none') { | ||
| button = 'left'; | ||
| } | ||
|
Comment on lines
+184
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the SGR parsing, scroll events in X11 mode are being assigned a button incorrectly. For example, a scroll-up event will be assigned let button: MouseEvent['button'];
if (name.startsWith('scroll-')) {
button = 'none';
} else {
button = getButtonFromCode(b);
if (name === 'left-release' && button === 'none') {
button = 'left';
}
} |
||
|
|
||
| return { | ||
| event: { name, ctrl, meta, shift, col, row }, | ||
| event: { | ||
| name, | ||
| ctrl, | ||
| meta, | ||
| shift, | ||
| col, | ||
| row, | ||
| button, | ||
| }, | ||
| length: match[0].length, | ||
| }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For scroll events, the
buttonproperty is being incorrectly assigned based on the event code. For example, a scroll-up event (code 64) will result inbutton: 'left'because64 & 3is0. Scroll events should havebutton: 'none'. You should also update theparses SGR scroll eventstest inpackages/cli/src/ui/utils/mouse.test.tsto assert thatevent.buttonis'none'.