提交 be3c5f06 编写于 作者: T Tomas Vik

Merge branch 'allow-submitting-comments-with-strg-enter' into 'main'

feat(webview): allow submitting comments with ctrl+enter

See merge request gitlab-org/gitlab-vscode-extension!138
...@@ -18,6 +18,9 @@ export default { ...@@ -18,6 +18,9 @@ export default {
buttonTitle() { buttonTitle() {
return this.isSaving ? 'Saving...' : 'Comment'; return this.isSaving ? 'Saving...' : 'Comment';
}, },
canSubmit() {
return !this.isSaving && this.note.length > 0;
},
}, },
methods: { methods: {
getNoteType() { getNoteType() {
...@@ -26,6 +29,10 @@ export default { ...@@ -26,6 +29,10 @@ export default {
: { type: 'issue', path: 'issues' }; : { type: 'issue', path: 'issues' };
}, },
addComment() { addComment() {
if (!this.canSubmit) {
return;
}
const { issuable, note, command } = this; const { issuable, note, command } = this;
this.isSaving = true; this.isSaving = true;
...@@ -33,6 +40,11 @@ export default { ...@@ -33,6 +40,11 @@ export default {
const noteType = this.getNoteType(); const noteType = this.getNoteType();
window.vsCodeApi.postMessage({ command, issuable, note, noteType }); window.vsCodeApi.postMessage({ command, issuable, note, noteType });
}, },
handleKeydown({ key, ctrlKey, shiftKey, metaKey, altKey }) {
if (key === 'Enter' && (ctrlKey || metaKey) && !shiftKey && !altKey) {
this.addComment();
}
},
}, },
mounted() { mounted() {
window.addEventListener('message', event => { window.addEventListener('message', event => {
...@@ -52,8 +64,8 @@ export default { ...@@ -52,8 +64,8 @@ export default {
<template> <template>
<div class="main-comment-form"> <div class="main-comment-form">
<textarea v-model="note" placeholder="Write a comment..." /> <textarea v-model="note" @keydown="handleKeydown" placeholder="Write a comment..." />
<button @click="addComment" :disabled="isSaving || !note.length"> <button @click="addComment" :disabled="!canSubmit">
{{ buttonTitle }} {{ buttonTitle }}
</button> </button>
<span v-if="isFailed">Failed to save your comment. Please try again.</span> <span v-if="isFailed">Failed to save your comment. Please try again.</span>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册