提交 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 {
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 {
<template>
<div class="main-comment-form">
<textarea v-model="note" placeholder="Write a comment..." />
<button @click="addComment" :disabled="isSaving || !note.length">
<textarea v-model="note" @keydown="handleKeydown" placeholder="Write a comment..." />
<button @click="addComment" :disabled="!canSubmit">
{{ buttonTitle }}
</button>
<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.
先完成此消息的编辑!
想要评论请 注册