-
Notifications
You must be signed in to change notification settings - Fork 153
fix: add SGR mouse and focus input #107
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0394c2f
fix: add SGR mouse and focus input
Railly f2a4752
fix: preserve drag and wheel direction
Railly e70b771
fix: preserve mouse capture across terminal bounds
Railly fd90ba1
fix: harden mouse capture and coordinates
Railly 06275ca
docs: remove duplicate mouse mode note
Railly 2462a83
fix: preserve native mouse interactions
Railly cccb4c5
fix: harden mouse tracking state
Railly fe8ce3a
fix: avoid style reads during mouse tracking
Railly 73b23b7
style: format mouse tracking test
Railly 9170742
Merge remote-tracking branch 'origin/main' into fix/sgr-mouse-focus
Railly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Binary file not shown.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import type { TerminalCore } from "@wterm/core"; | ||
| import { InputHandler } from "../input.js"; | ||
|
|
||
| describe("InputHandler mouse and focus modes", () => { | ||
| let container: HTMLDivElement; | ||
| let received: string[]; | ||
| let handler: InputHandler; | ||
| let core: TerminalCore; | ||
|
|
||
| beforeEach(() => { | ||
| container = document.createElement("div"); | ||
| document.body.appendChild(container); | ||
| Object.defineProperty(container, "getBoundingClientRect", { | ||
| value: () => ({ | ||
| left: 10, | ||
| top: 20, | ||
| width: 800, | ||
| height: 400, | ||
| }), | ||
| }); | ||
| received = []; | ||
| core = { | ||
| getCols: () => 80, | ||
| getRows: () => 40, | ||
| mouseTracking: () => 1002, | ||
| mouseSgr: () => true, | ||
| focusEvents: () => true, | ||
| } as unknown as TerminalCore; | ||
| handler = new InputHandler( | ||
| container, | ||
| (data) => received.push(data), | ||
| () => core, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| handler.destroy(); | ||
| container.remove(); | ||
| }); | ||
|
|
||
| it("encodes SGR press, drag, release, and wheel", () => { | ||
| container.dispatchEvent( | ||
| new MouseEvent("mousedown", { | ||
| button: 0, | ||
| buttons: 1, | ||
| clientX: 85, | ||
| clientY: 65, | ||
| }), | ||
| ); | ||
| container.dispatchEvent( | ||
| new MouseEvent("mousemove", { buttons: 1, clientX: 105, clientY: 75 }), | ||
| ); | ||
| container.dispatchEvent( | ||
| new MouseEvent("mouseup", { button: 0, clientX: 105, clientY: 75 }), | ||
| ); | ||
| const wheel = new WheelEvent("wheel", { | ||
| deltaY: 100, | ||
| clientX: 105, | ||
| clientY: 75, | ||
| cancelable: true, | ||
| }); | ||
| container.dispatchEvent(wheel); | ||
|
|
||
| expect(received).toEqual([ | ||
| "\x1b[<0;8;5M", | ||
| "\x1b[<32;10;6M", | ||
| "\x1b[<0;10;6m", | ||
| "\x1b[<65;10;6M", | ||
| ]); | ||
| expect(wheel.defaultPrevented).toBe(true); | ||
| }); | ||
|
|
||
| it("emits focus reports only when mode 1004 is enabled", () => { | ||
| const textarea = container.querySelector("textarea")!; | ||
| textarea.dispatchEvent(new FocusEvent("focus")); | ||
| textarea.dispatchEvent(new FocusEvent("blur")); | ||
| expect(received).toEqual(["\x1b[I", "\x1b[O"]); | ||
|
|
||
| received = []; | ||
| core.focusEvents = () => false; | ||
| textarea.dispatchEvent(new FocusEvent("focus")); | ||
| textarea.dispatchEvent(new FocusEvent("blur")); | ||
| expect(received).toEqual([]); | ||
| }); | ||
| }); |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.