webui: restore command+enter keyboard shortcut for diff comments
This used to exist. I missed it. Bring it back.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s6cd4f7fa81a2ee71k
diff --git a/webui/src/web-components/sketch-monaco-view.test.ts b/webui/src/web-components/sketch-monaco-view.test.ts
index 7366153..538fbaf 100644
--- a/webui/src/web-components/sketch-monaco-view.test.ts
+++ b/webui/src/web-components/sketch-monaco-view.test.ts
@@ -60,3 +60,29 @@
// The actual scroll preservation happens during runtime interactions
expect(true).toBe(true); // Test passes if component mounts successfully with fixes
});
+
+// Test keyboard shortcut functionality for comment submission
+test("Command+Enter and Ctrl+Enter keyboard shortcuts submit comments", async ({ mount }) => {
+ const component = await mount(CodeDiffEditor, {
+ props: {
+ originalCode: 'console.log("original");',
+ modifiedCode: 'console.log("modified");',
+ },
+ });
+
+ await expect(component).toBeVisible();
+
+ // Test that the keyboard shortcut handler exists
+ const hasKeyboardHandler = await component.evaluate((node) => {
+ const monacoView = node as any;
+
+ // Check if the handleCommentKeydown method exists
+ return typeof monacoView.handleCommentKeydown === 'function';
+ });
+
+ expect(hasKeyboardHandler).toBe(true);
+
+ // The actual keyboard event testing would require more complex setup
+ // with Monaco editor being fully loaded and comment UI being active.
+ // This test verifies the handler method is present.
+});
diff --git a/webui/src/web-components/sketch-monaco-view.ts b/webui/src/web-components/sketch-monaco-view.ts
index 9f3fa50..b74097a 100644
--- a/webui/src/web-components/sketch-monaco-view.ts
+++ b/webui/src/web-components/sketch-monaco-view.ts
@@ -373,6 +373,7 @@
placeholder="Type your comment here..."
.value="${this.commentText}"
@input="${this.handleCommentInput}"
+ @keydown="${this.handleCommentKeydown}"
></textarea>
<div class="flex justify-end gap-2">
<button
@@ -403,6 +404,17 @@
}
/**
+ * Handle keyboard shortcuts in the comment textarea
+ */
+ private handleCommentKeydown(e: KeyboardEvent) {
+ // Check for Command+Enter (Mac) or Ctrl+Enter (other platforms)
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
+ e.preventDefault();
+ this.submitComment();
+ }
+ }
+
+ /**
* Get CSS class for selected text preview based on number of lines
*/
private getPreviewCssClass(): string {