-
Notifications
You must be signed in to change notification settings - Fork 0
fix: vim visual mode on hover, port config, and Windows PTY #29
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
da14e92
fix: prevent visual mode activation on hover in Vim by blocking mouse…
0bab262
fix: prevent vim visual mode on hover, lost drags, and missed resizes
cebfd08
fix: ignore PORT env var, always use config port
e531459
fix: use node-pty instead of Bun.Terminal on Windows
94a2d22
chore: add .gitattributes to enforce LF line endings on all platforms
d507992
fix: restore PORT env override in server for tests and direct invocation
3184892
fix: resolve server entry to dist/ when spawning with node on Windows
3b61f52
refactor: address code review comments on PR #29
127d9e8
fix: remove setPointerCapture that broke basic vim drag
9272149
fix: filter hover SGR at onData level instead of blocking DOM events
8a19cf4
fix: correct hover SGR encoding and deduplicate drag events for vim m…
a811375
refactor: extract SGR mouse helpers into mouse.ts and add unit tests
6833650
fix: address copilot review comments
8e2a82e
test: fix Windows-local test failures
cae27ca
fix: guard configDir against non-absolute HOME, ignore undefined/ art…
9100dae
fix: lint and format errors from Windows test fixes
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * text=auto eol=lf | ||
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
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
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,68 @@ | ||
| import { describe, expect, test } from 'bun:test'; | ||
| import { isDuplicateDrag, rewriteHoverMotion } from './mouse'; | ||
|
|
||
| describe('rewriteHoverMotion', () => { | ||
| test('rewrites \\x1b[<32; to \\x1b[<35; when isHover is true', () => { | ||
| expect(rewriteHoverMotion('\x1b[<32;8;4M', true)).toBe('\x1b[<35;8;4M'); | ||
| }); | ||
|
|
||
| test('preserves col;row and M suffix after rewrite', () => { | ||
| expect(rewriteHoverMotion('\x1b[<32;120;50M', true)).toBe('\x1b[<35;120;50M'); | ||
| }); | ||
|
|
||
| test('returns data unchanged when isHover is false (drag)', () => { | ||
| expect(rewriteHoverMotion('\x1b[<32;8;4M', false)).toBe('\x1b[<32;8;4M'); | ||
| }); | ||
|
|
||
| test('returns data unchanged for non-motion sequences regardless of isHover', () => { | ||
| // left press | ||
| expect(rewriteHoverMotion('\x1b[<0;8;4M', true)).toBe('\x1b[<0;8;4M'); | ||
| // left release | ||
| expect(rewriteHoverMotion('\x1b[<0;8;4m', true)).toBe('\x1b[<0;8;4m'); | ||
| // scroll up | ||
| expect(rewriteHoverMotion('\x1b[<64;8;4M', true)).toBe('\x1b[<64;8;4M'); | ||
| // middle drag | ||
| expect(rewriteHoverMotion('\x1b[<33;8;4M', true)).toBe('\x1b[<33;8;4M'); | ||
| }); | ||
|
|
||
| test('returns data unchanged for plain text', () => { | ||
| expect(rewriteHoverMotion('hello', true)).toBe('hello'); | ||
| }); | ||
|
|
||
| test('does not rewrite when isHover is false even for button-32', () => { | ||
| // pointer moved to a new cell while button is held — must not rewrite | ||
| const drag = '\x1b[<32;9;4M'; | ||
| expect(rewriteHoverMotion(drag, false)).toBe(drag); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isDuplicateDrag', () => { | ||
| test('returns true for identical consecutive button-32 sequences', () => { | ||
| const seq = '\x1b[<32;8;4M'; | ||
| expect(isDuplicateDrag(seq, seq)).toBe(true); | ||
| }); | ||
|
|
||
| test('returns false when position changes', () => { | ||
| expect(isDuplicateDrag('\x1b[<32;9;4M', '\x1b[<32;8;4M')).toBe(false); | ||
| }); | ||
|
|
||
| test('returns false when lastDragSeq is empty (first drag event)', () => { | ||
| expect(isDuplicateDrag('\x1b[<32;8;4M', '')).toBe(false); | ||
| }); | ||
|
|
||
| test('returns false for non-drag sequences even if identical', () => { | ||
| // press, release, scroll must never be deduped | ||
| expect(isDuplicateDrag('\x1b[<0;8;4M', '\x1b[<0;8;4M')).toBe(false); | ||
| expect(isDuplicateDrag('\x1b[<0;8;4m', '\x1b[<0;8;4m')).toBe(false); | ||
| expect(isDuplicateDrag('\x1b[<64;8;4M', '\x1b[<64;8;4M')).toBe(false); | ||
| }); | ||
|
|
||
| test('returns false when row differs', () => { | ||
| expect(isDuplicateDrag('\x1b[<32;8;5M', '\x1b[<32;8;4M')).toBe(false); | ||
| }); | ||
|
|
||
| test('returns true only for exact string match', () => { | ||
| expect(isDuplicateDrag('\x1b[<32;8;4M', '\x1b[<32;8;4M')).toBe(true); | ||
| expect(isDuplicateDrag('\x1b[<32;8;4M', '\x1b[<35;8;4M')).toBe(false); | ||
| }); | ||
| }); |
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,60 @@ | ||
| /** | ||
| * SGR mouse sequence helpers. | ||
| * | ||
| * ghostty-web bug: handleMouseMove always encodes motion as SGR button-32 | ||
| * (\x1b[<32;col;rowM) regardless of whether a button is held. It uses its | ||
| * own mouseButtonsPressed bitmask; when no button is pressed the bitmask is 0, | ||
| * and 0+32=32 — the same Cb value as a left-button drag. Real terminals use | ||
| * Cb=35 (32+3, "no button") for hover and Cb=32 for left-button drag. | ||
| * | ||
| * Impact on vim: with `set mouse=a` vim requests mode 1003 (any-event | ||
| * tracking). Every hover move arrives as \x1b[<32;…M which vim decodes as | ||
| * <LeftDrag>, toggling visual mode on each pixel of cursor movement. | ||
| * | ||
| * The two exported functions implement the fixes applied in onData: | ||
| * | ||
| * - rewriteHoverMotion: when the DOM reports no button held (e.buttons===0), | ||
| * rewrite \x1b[<32; → \x1b[<35; so vim receives the correct no-button code | ||
| * (Cb=35 per the SGR spec). The position is still forwarded so vim can | ||
| * track the cursor for subsequent drag operations. | ||
| * | ||
| * - isDuplicateDrag: ghostty-web fires multiple mousemove events for the same | ||
| * character cell while the pointer stays within it. Vim treats a <LeftDrag> | ||
| * at the same cell twice as a visual-mode toggle (enter → exit), so | ||
| * consecutive identical drag sequences must be deduplicated. | ||
| */ | ||
|
|
||
| /** Prefix that ghostty-web emits for both hover and left-button drag. */ | ||
| const DRAG_PREFIX = '\x1b[<32;'; | ||
| /** Correct SGR prefix for no-button hover motion (Cb = 32 + 3 = 35). */ | ||
| const HOVER_PREFIX = '\x1b[<35;'; | ||
|
|
||
| /** | ||
| * If `isHover` is true and `data` is a ghostty-web hover-misencoded drag | ||
| * sequence, rewrite the button byte from 32 to 35 (the correct SGR no-button | ||
| * code) and return the corrected sequence. Otherwise return `data` unchanged. | ||
| * | ||
| * @param data Raw SGR sequence from ghostty-web's onData callback. | ||
| * @param isHover Whether the originating DOM mousemove had `e.buttons === 0`. | ||
| */ | ||
| export function rewriteHoverMotion(data: string, isHover: boolean): string { | ||
| if (isHover && data.startsWith(DRAG_PREFIX)) { | ||
| return HOVER_PREFIX + data.slice(DRAG_PREFIX.length); | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true when `data` is a left-button drag sequence (`\x1b[<32;…M`) | ||
| * that is identical to the previous drag sequence, indicating the pointer | ||
| * has not moved to a new character cell. | ||
| * | ||
| * Callers should maintain `lastDragSeq` state and pass it in; on a false | ||
| * return they update `lastDragSeq = data`, on a true return they skip sending. | ||
| * | ||
| * @param data Raw SGR sequence from ghostty-web's onData callback. | ||
| * @param lastDragSeq The last drag sequence that was forwarded to the PTY. | ||
| */ | ||
| export function isDuplicateDrag(data: string, lastDragSeq: string): boolean { | ||
| return data.startsWith(DRAG_PREFIX) && data === lastDragSeq; | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.