Add keyboard and clipboard support for razorconsole website preview#191
Add keyboard and clipboard support for razorconsole website preview#191LittleLittleCloud merged 10 commits intomainfrom
Conversation
|
@copilot Retry |
|
@copilot Try again |
…key parsing Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
I've implemented the keyboard support for the website component preview. The changes in commit
|
|
@copilot Fix fIDE0073: A source file is missing a required header |
|
@copilot Fix fIDE0073: A source file is missing a required header |
…ctionExtensions.cs Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Fixed in commit |
🚀 Preview DeploymentA preview build has been generated for this PR from CI run #19685379952! Download the artifact: To view the preview locally:
🌐 Live Preview URL: https://fc218c65.razorconsole.pages.dev The live preview will be automatically updated when you push new |
|
@copilot Key input doesn't work at all |
|
@copilot you entirely break the keyboard input, shame on you This is the log when I press enter |
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Fixed in commit This was a pre-existing bug from the JS-WASM interop refactoring, not introduced by my keyboard enhancement changes. The fix adds |
|
@LittleLittleCloud Num keys works but ctrl+v doesn't work |
|
@TeseySTD xterm doesn't process control C && V by default, also sending the keyboard command back to wasm won't make a big difference because currently, the keyboard handler in wasm doesn't save text from clipboard when ctrl + C and send text to keyboard manager when ctrl + V. I think we can refer to the solution under this issue and on frontend, when terminal is focused, save to clipboard when control + C is pressed, and when control + V is pressed, send the text content from clipboard to wasm character by character @copilot do it |
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Implemented in commit Ctrl+C (Copy): When Ctrl+C is pressed and text is selected in the terminal, it copies the selected text to the clipboard using the Clipboard API. Ctrl+V (Paste): When Ctrl+V is pressed, it reads text from the clipboard and sends each character individually to the WASM backend, allowing the keyboard manager to process them as regular input. Both operations support Cmd key on Mac (metaKey). The implementation also includes error handling and debug logging for troubleshooting. |
|
@TeseySTD seems to be working now |
There was a problem hiding this comment.
Pull request overview
This PR enhances the RazorConsole website preview with comprehensive keyboard and clipboard support, enabling users to interact with terminal components using standard keyboard shortcuts and clipboard operations.
Key changes:
- Extended keyboard support to include control key combinations (Ctrl+A-Z), function keys (F1-F12), navigation keys (Home, End, PageUp, PageDown, Insert, Delete), and special keys (modifier, lock, and system keys)
- Implemented clipboard operations with Ctrl+C (Cmd+C on Mac) for copying selected text and Ctrl+V (Cmd+V on Mac) for pasting
- Enhanced the
ParseKeyFromBrowsermethod inRazorConsoleRenderer.csto properly parse control characters and map them to appropriateConsoleKeyvalues
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| website/src/lib/xtermConsole.ts | Added async keyboard event handler with clipboard support for copy (Ctrl+C) and paste (Ctrl+V) operations, including error handling for clipboard API failures |
| src/RazorConsole.Website/RazorConsoleRenderer.cs | Extended keyboard parsing to support function keys, navigation keys, special keys, control character combinations, and additional punctuation/symbol keys |
Comments suppressed due to low confidence (3)
src/RazorConsole.Website/RazorConsoleRenderer.cs:109
- Disposable 'StringWriter' is created but not disposed.
var sw = new StringWriter();
src/RazorConsole.Website/RazorConsoleRenderer.cs:120
- This assignment to consoleOption is useless, since its value is never read.
var consoleOption = new RenderOptions(console.Profile.Capabilities, new Size(80, 150));
src/RazorConsole.Website/RazorConsoleRenderer.cs:168
- This assignment to modifiers is useless, since its value is never read.
modifiers |= ConsoleModifiers.Shift;
| // Handle Ctrl+C (or Cmd+C on Mac) - Copy selected text | ||
| if ((ctrlKey || metaKey) && (domKey === 'c' || domKey === 'C')) { | ||
| const selection = terminal.getSelection() | ||
| if (selection) { | ||
| try { | ||
| await navigator.clipboard.writeText(selection) | ||
| console.debug('Copied to clipboard:', selection) | ||
| } catch (err) { | ||
| console.warn('Failed to copy to clipboard:', err) | ||
| } | ||
| } | ||
| // Still forward the event to WASM in case it needs to handle it | ||
| void helper.invokeMethodAsync( | ||
| 'HandleKeyboardEvent', | ||
| elementId, | ||
| key, | ||
| domEvent.key, | ||
| domEvent.ctrlKey, | ||
| domEvent.altKey, | ||
| domEvent.shiftKey | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| // Handle Ctrl+V (or Cmd+V on Mac) - Paste from clipboard | ||
| if ((ctrlKey || metaKey) && (domKey === 'v' || domKey === 'V')) { | ||
| try { | ||
| const text = await navigator.clipboard.readText() | ||
| if (text) { | ||
| console.debug('Pasting from clipboard:', text) | ||
| // Send each character individually to WASM | ||
| for (const char of text) { | ||
| await helper.invokeMethodAsync( | ||
| 'HandleKeyboardEvent', | ||
| elementId, | ||
| char, | ||
| char.length === 1 ? char : 'Unidentified', | ||
| false, | ||
| false, | ||
| false | ||
| ) | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.warn('Failed to paste from clipboard:', err) | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
The Ctrl+C handler forwards the keyboard event to WASM after copying to clipboard, but the Ctrl+V handler does not forward the Ctrl+V event itself—only the pasted characters. This creates an inconsistency in behavior. Consider either:
- Not forwarding Ctrl+C to WASM (consistent with Ctrl+V handling), or
- Forwarding Ctrl+V to WASM before pasting (consistent with Ctrl+C handling)
The current implementation may cause unexpected behavior where the backend receives Ctrl+C events but not Ctrl+V events.
ParseKeyFromBrowserinRazorConsoleRenderer.csto support:Clipboard Implementation
The clipboard support is implemented in
xtermConsole.tsusing the Clipboard API:Both operations support the Cmd key on macOS and include error handling with debug logging.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.