From fb93040aad8e07000942a1ff4c9d8f680e8e02cc Mon Sep 17 00:00:00 2001 From: Kev Date: Thu, 10 Dec 2020 23:49:47 +0100 Subject: [PATCH] feat(webview): allow submitting comments with strg+enter --- src/webview/src/components/CommentForm.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/webview/src/components/CommentForm.vue b/src/webview/src/components/CommentForm.vue index e356cf0..d35add5 100644 --- a/src/webview/src/components/CommentForm.vue +++ b/src/webview/src/components/CommentForm.vue @@ -18,6 +18,9 @@ export default { buttonTitle() { return this.isSaving ? 'Saving...' : 'Comment'; }, + canSubmit() { + return !this.isSaving && this.note.length > 0; + }, }, methods: { getNoteType() { @@ -26,6 +29,10 @@ export default { : { type: 'issue', path: 'issues' }; }, addComment() { + if (!this.canSubmit) { + return; + } + const { issuable, note, command } = this; this.isSaving = true; @@ -33,6 +40,11 @@ export default { const noteType = this.getNoteType(); window.vsCodeApi.postMessage({ command, issuable, note, noteType }); }, + handleKeydown({ key, ctrlKey, shiftKey, metaKey, altKey }) { + if (key === 'Enter' && (ctrlKey || metaKey) && !shiftKey && !altKey) { + this.addComment(); + } + }, }, mounted() { window.addEventListener('message', event => { @@ -52,8 +64,8 @@ export default {