-
Notifications
You must be signed in to change notification settings - Fork 375
fix: detect Shift+Enter on macOS terminals without Kitty protocol support #2969
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -771,6 +771,16 @@ func (e *editor) Update(msg tea.Msg) (layout.Model, tea.Cmd) { | |
| return e, nil | ||
| } | ||
|
|
||
| // On macOS, terminals like Terminal.app don't support the Kitty keyboard | ||
| // protocol, so Shift+Enter sends the same byte as Enter. Use the macOS | ||
| // CoreGraphics API to check if Shift is physically held, and treat it | ||
| // as a newline insertion. | ||
| if msg.String() == "enter" && termfeatures.IsShiftPressed() { | ||
|
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. [MEDIUM] Timing race: Shift key may be released before IsShiftPressed() is polled
Impact: Intermittent false negatives: the user presses Shift+Enter intending to insert a newline, but the message is submitted unexpectedly. This is a regression compared to terminals that use the Kitty protocol (where the key event carries shift modifier flags, immune to timing). Suggestion: The PR description acknowledges this is a best-effort approach, but this limitation should be documented (e.g., a code comment or a note in the PR). Consider whether the timing window is acceptable in practice (bubbletea dispatch is typically sub-millisecond), and if so, document it explicitly to set expectations. |
||
| e.textarea.InsertString("\n") | ||
|
gtardif marked this conversation as resolved.
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. [LOW] InsertString("\n") vs InsertNewline may behave differently The Kitty-protocol path inserts a newline by passing the key event through For the current textarea implementation these are likely equivalent, but if the bubbletea Suggestion: If a direct |
||
| e.refreshSuggestion() | ||
| return e, nil | ||
| } | ||
|
|
||
| // Let textarea process the key - it handles newlines via InsertNewline binding | ||
| prev := e.textarea.Value() | ||
| e.textarea, _ = e.textarea.Update(msg) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //go:build darwin | ||
|
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. [HIGH] CGo dependency breaks darwin cross-compilation from Linux CI
Impact: CI pipelines doing cross-compilation for darwin will fail. Docker's own multi-platform build ( Suggestion: Consider adding a build tag guard or a |
||
|
|
||
| package termfeatures | ||
|
|
||
| /* | ||
| #cgo LDFLAGS: -framework CoreGraphics | ||
| #include <CoreGraphics/CoreGraphics.h> | ||
|
|
||
| static int isShiftPressed() { | ||
| CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState); | ||
|
gtardif marked this conversation as resolved.
|
||
| return (flags & kCGEventFlagMaskShift) != 0; | ||
| } | ||
| */ | ||
| import "C" | ||
|
|
||
| // IsShiftPressed queries the macOS CoreGraphics event system to determine | ||
| // whether the Shift key is currently held down. This allows us to distinguish | ||
| // Shift+Enter from Enter in terminals that don't support the Kitty keyboard | ||
| // protocol (like macOS Terminal.app), since those terminals send the same byte | ||
| // for both key combinations. | ||
| func IsShiftPressed() bool { | ||
| return C.isShiftPressed() != 0 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //go:build !darwin | ||
|
|
||
| package termfeatures | ||
|
|
||
| // IsShiftPressed returns false on non-macOS platforms. The CoreGraphics-based | ||
| // modifier detection is only available on macOS. | ||
| func IsShiftPressed() bool { | ||
| return false | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.