Auto-submit snippets with Cmd+Enter on macOS in Avalonia app#129
Merged
Conversation
Match the WPF behavior: when a snippet is applied via Enter while the auto-submit modifier is held (Cmd on macOS, Ctrl on Windows), wait for the modifier to be released, paste, then send an extra Enter to submit the pasted content. - Avalonia Navigator.Send samples the modifier state at entry using platform APIs (CGEventSourceFlagsState on macOS, GetAsyncKeyState on Windows) and gates the extra Enter on that. - MacOSApplication.SendEnterShortcut sends the Return key via AppleScript; SimulateEnter falls back to 'xdotool key Return' on Linux. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR brings WPF’s “auto-submit” behavior to the Avalonia app by detecting an “auto-submit modifier” at send-time, waiting for release, pasting the snippet, and optionally sending an extra Enter—using platform-specific implementations (notably CoreGraphics on macOS).
Changes:
- Sample auto-submit modifier state at entry to
ISendTextService.Send, wait-for-release (5s timeout), then paste and optionally send Enter. - Add macOS CoreGraphics-based Enter keystroke simulation and Command-key state query.
- Add a small Windows helper to query Ctrl key state via
GetAsyncKeyState.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Neptuo.Productivity.SnippetManager.Avalonia/WindowsApplication.cs | Adds Windows Ctrl key state query helper via GetAsyncKeyState. |
| src/Neptuo.Productivity.SnippetManager.Avalonia/Navigator.cs | Implements modifier sampling, wait-for-release, and conditional Enter simulation after paste. |
| src/Neptuo.Productivity.SnippetManager.Avalonia/MacOSApplication.cs | Adds CGEvent-based Return keystroke posting and Command modifier state query. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…Process - Removed Windows branch from IsAutoSubmitModifierPressed (and the WindowsApplication helper). SimulatePaste/SimulateEnter have no Windows implementation yet, so detecting Ctrl there just caused a 5s wait-for-release with no follow-up keystroke. - Wrapped the Linux xdotool Process.Start calls in 'using' to dispose the returned Process handle. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The WPF app has a handy shortcut: hold Ctrl while pressing Enter to apply a snippet and it sends an extra Enter after the paste to auto-submit (e.g. run the pasted command). The Avalonia app was missing this; this PR brings the same behavior over, using Cmd on macOS and Ctrl on Windows.
Approach
Navigator.Sendnow samples the auto-submit modifier state at entry (before closing the main window and restoring focus), mirroring the WPF flow. If the modifier is held, it waits for the key to be released, pastes, then posts an extra Enter. Modifier detection is platform-specific but stays entirely inside the Avalonia project so the sharedISendTextServicesignature is unchanged:CGEventSourceFlagsStatefor the state query andCGEventCreateKeyboardEvent+CGEventPostfor the Return keystroke, reusing the existingCoreGraphicsP/Invoke helper introduced in Faster frontmost app detection on macOS via NSWorkspace + CGEvent #127. Noosascriptspawn on the hot path.GetAsyncKeyState(VK_CONTROL)via a new smallWindowsApplicationhelper.xdotool key Returnfor the keystroke and is treated as "modifier not pressed" for state (same conservative behavior as the existing paste path).Notes for reviewers
ISendTextService/ApplySnippetCommand/tests are untouched - this is Avalonia-only plumbing.