Commit 5ed0be0f authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '216631-cmd-enter-no-clear-comment-text' into 'master'

Prevent autosave when reply comment via cmd+enter

Closes #216631

See merge request gitlab-org/gitlab!35716
parents 45384ccd 49941a92
...@@ -101,6 +101,7 @@ export default { ...@@ -101,6 +101,7 @@ export default {
isResolving: this.resolveDiscussion, isResolving: this.resolveDiscussion,
isUnresolving: !this.resolveDiscussion, isUnresolving: !this.resolveDiscussion,
resolveAsThread: true, resolveAsThread: true,
isSubmittingWithKeydown: false,
}; };
}, },
computed: { computed: {
...@@ -241,6 +242,10 @@ export default { ...@@ -241,6 +242,10 @@ export default {
this.$emit('cancelForm', shouldConfirm, this.noteBody !== this.updatedNoteBody); this.$emit('cancelForm', shouldConfirm, this.noteBody !== this.updatedNoteBody);
}, },
onInput() { onInput() {
if (this.isSubmittingWithKeydown) {
return;
}
if (this.autosaveKey) { if (this.autosaveKey) {
const { autosaveKey, updatedNoteBody: text } = this; const { autosaveKey, updatedNoteBody: text } = this;
updateDraft(autosaveKey, text); updateDraft(autosaveKey, text);
...@@ -250,6 +255,7 @@ export default { ...@@ -250,6 +255,7 @@ export default {
if (this.showBatchCommentsActions) { if (this.showBatchCommentsActions) {
this.handleAddToReview(); this.handleAddToReview();
} else { } else {
this.isSubmittingWithKeydown = true;
this.handleUpdate(); this.handleUpdate();
} }
}, },
......
---
title: Prevent autosave when reply comment via cmd+enter
merge_request: 35716
author:
type: fixed
...@@ -245,6 +245,24 @@ describe('issue_note_form component', () => { ...@@ -245,6 +245,24 @@ describe('issue_note_form component', () => {
expect(updateDraft).toHaveBeenCalledWith(dummyAutosaveKey, dummyContent); expect(updateDraft).toHaveBeenCalledWith(dummyAutosaveKey, dummyContent);
}); });
it('does not save draft when ctrl+enter is pressed', () => {
const options = {
noteBody: '',
autosaveKey: dummyAutosaveKey,
};
props = { ...props, ...options };
wrapper = createComponentWrapper();
wrapper.setData({ isSubmittingWithKeydown: true });
const textarea = wrapper.find('textarea');
textarea.setValue('some content');
textarea.trigger('keydown.enter', { metaKey: true });
expect(updateDraft).not.toHaveBeenCalled();
});
}); });
describe('with batch comments', () => { describe('with batch comments', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment