Skip to content
Snippets Groups Projects
Verified Commit 8d341b9e authored by Nick Leonard's avatar Nick Leonard :pushpin: Committed by GitLab
Browse files

Always submit note via key shortcut with shift

Adding shift to the key shortcut will submit notes
including on MRs, where base shortcut adds to draft.

Changelog: added
parent a5d0771e
No related branches found
No related tags found
2 merge requests!158455Backport Release Environments notification pipeline change to 16.11,!148899Always submit notes and comments via key shortcut when shift is pressed
......@@ -195,6 +195,12 @@ const EDIT_RECENT_COMMENT = {
defaultKeys: ['up'],
};
export const SAVE_CHANGES = {
id: 'globalShortcuts.saveChanges',
description: __('Submit/save changes'),
defaultKeys: ['mod+enter'],
};
export const EDIT_WIKI_PAGE = {
id: 'wiki.editWikiPage',
description: __('Edit wiki page'),
......@@ -449,6 +455,20 @@ export const MR_TOGGLE_FILE_BROWSER = {
customizable: false,
};
export const MR_ADD_TO_REVIEW = {
id: 'mergeRequests.addToReview',
description: __('Add your comment to a review'),
defaultKeys: ['mod+enter'],
customizable: false,
};
export const MR_ADD_COMMENT_NOW = {
id: 'mergeRequests.addCommentNow',
description: __('Publish your comment immediately'),
defaultKeys: ['shift+mod+enter'],
customizable: false,
};
export const MR_NEXT_UNRESOLVED_DISCUSSION = {
id: 'mergeRequests.nextUnresolvedDiscussion',
description: __('Next unresolved thread'),
......@@ -558,6 +578,7 @@ export const EDITING_SHORTCUTS_GROUP = {
LINK_TEXT,
TOGGLE_MARKDOWN_PREVIEW,
EDIT_RECENT_COMMENT,
SAVE_CHANGES,
],
};
......@@ -647,6 +668,8 @@ const MR_SHORTCUTS_GROUP = {
MR_PREVIOUS_UNRESOLVED_DISCUSSION,
MR_COPY_SOURCE_BRANCH_NAME,
MR_TOGGLE_FILE_BROWSER,
MR_ADD_TO_REVIEW,
MR_ADD_COMMENT_NOW,
],
};
......
......@@ -374,8 +374,10 @@ export default {
:autocomplete-data-sources="autocompleteDataSources"
supports-quick-actions
@keydown.up="editCurrentUserLastNote()"
@keydown.meta.enter="handleEnter()"
@keydown.ctrl.enter="handleEnter()"
@keydown.shift.meta.enter="handleSave()"
@keydown.shift.ctrl.enter="handleSave()"
@keydown.meta.enter.exact="handleEnter()"
@keydown.ctrl.enter.exact="handleEnter()"
@input="onInput"
/>
</comment-field-layout>
......
......@@ -287,8 +287,8 @@ export default {
onInput(value) {
this.updatedNoteBody = value;
},
handleKeySubmit() {
if (this.showBatchCommentsActions) {
handleKeySubmit(forceUpdate = false) {
if (this.showBatchCommentsActions && !forceUpdate) {
this.handleAddToReview();
} else {
this.isSubmittingWithKeydown = true;
......@@ -372,8 +372,10 @@ export default {
:disabled="isSubmitting"
supports-quick-actions
:autofocus="autofocus"
@keydown.meta.enter="handleKeySubmit()"
@keydown.ctrl.enter="handleKeySubmit()"
@keydown.shift.meta.enter="handleKeySubmit((forceUpdate = true))"
@keydown.shift.ctrl.enter="handleKeySubmit((forceUpdate = true))"
@keydown.meta.enter.exact="handleKeySubmit()"
@keydown.ctrl.enter.exact="handleKeySubmit()"
@keydown.exact.up="editMyLastNote()"
@keydown.exact.esc="cancelHandler(true)"
@input="onInput"
......
......@@ -108,9 +108,15 @@ To add a commit diff comment:
1. Select the **Commits** tab, then select the commit message.
1. By the line you want to comment on, hover over the line number and select **Comment** (**{comment}**).
You can select multiple lines by dragging the **Comment** (**{comment}**) icon.
1. Enter your comment and select **Start a review** or **Add comment now**.
The comment is displayed on the merge request's **Overview** tab.
1. Enter your comment.
1. To add your comment immediately, select **Add comment now**, or use the keyboard shortcut:
- macOS: <kbd>Shift</kbd> + <kbd>Command</kbd> + <kbd>Enter</kbd>
- All other OSes: <kbd>Shift</kbd> + <kbd>Control</kbd> + <kbd>Enter</kbd>
1. To leave your comment unpublished until you finish a review, select **Start a review**, or use the keyboard shortcut:
- macOS: <kbd>Command</kbd> + <kbd>Enter</kbd>
- All other OSes: <kbd>Control</kbd> + <kbd>Enter</kbd>
The comment displays on the merge request's **Overview** tab.
The comment is not displayed on your project's **Code > Commits** page.
......
......@@ -39,11 +39,13 @@ merge request, authored by the user who suggested the changes.
````
1. Edit the pre-populated code block to add your suggestion.
1. Select whether you want your comment to appear immediately:
- **Start a review** or **Add to review** creates your comment in a pending state
as part of a [review](index.md).
- **Add comment now** adds your comment immediately.
1. To add your comment immediately, select **Add comment now**, or use the keyboard shortcut:
- macOS: <kbd>Shift</kbd> + <kbd>Command</kbd> + <kbd>Enter</kbd>
- All other OSes: <kbd>Shift</kbd> + <kbd>Control</kbd> + <kbd>Enter</kbd>
1. To leave your comment unpublished until you finish a [review](index.md), select
**Start a review**, or use the keyboard shortcut:
- macOS: <kbd>Command</kbd> + <kbd>Enter</kbd>
- All other OSes: <kbd>Control</kbd> + <kbd>Enter</kbd>
### Multi-line suggestions
......
......@@ -43,6 +43,7 @@ These shortcuts are available in most areas of GitLab:
| <kbd>Shift</kbd> + <kbd>t</kbd> | Go to your To-Do List page. |
| <kbd>p</kbd>, then <kbd>b</kbd> | Show or hide the Performance Bar. |
| <kbd>Escape</kbd> | Hide tooltips or popovers. |
| <kbd>Escape</kbd> | Hide tooltips or popovers. |
| <kbd>g</kbd>, then <kbd>x</kbd> | Toggle between [GitLab](https://gitlab.com/) and [GitLab Next](https://next.gitlab.com/) (GitLab SaaS only). |
| <kbd>.</kbd> | Open the [Web IDE](project/web_ide/index.md). |
......@@ -60,6 +61,7 @@ descriptions):
| <kbd>Command</kbd> + <kbd>k</kbd> | <kbd>Control</kbd> + <kbd>k</kbd> | Add a link (surround the selected text with `[]()`). |
| <kbd>Command</kbd> + <kbd>&#93;</kbd> | <kbd>Control</kbd> + <kbd>&#93;</kbd> | Indent list item. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/351924) in GitLab 15.3. |
| <kbd>Command</kbd> + <kbd>&#91;</kbd> | <kbd>Control</kbd> + <kbd>&#91;</kbd> | Outdent list item. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/351924) in GitLab 15.3. |
| <kbd>Command</kbd> + <kbd>Enter</kbd> | <kbd>Control</kbd> + <kbd>Enter</kbd> | Submit or save changes |
The shortcuts for editing in text fields are always enabled, even if other
keyboard shortcuts are disabled.
......@@ -122,6 +124,8 @@ These shortcuts are available when viewing [merge requests](project/merge_reques
| <kbd>b</kbd> | | Copy source branch name. |
| <kbd>c</kbd> + <kbd>r</kbd> | | Copy merge request reference. |
| <kbd>r</kbd> | | Start writing a comment. Pre-selected text is quoted in the comment. Can't be used to reply in a thread. |
| <kbd>Shift</kbd> + <kbd>Command</kbd> + <kbd>Enter</kbd> | <kbd>Shift</kbd> + <kbd>Control</kbd> + <kbd>Enter</kbd> | Publish your comment immediately. |
| <kbd>Command</kbd> + <kbd>Enter</kbd> | <kbd>Control</kbd> + <kbd>Enter</kbd> | Add your comment in a pending state, as part of a [review](project/merge_requests/reviews/index.md#start-a-review). |
| <kbd>c</kbd> | | Move to next commit. |
| <kbd>x</kbd> | | Move to previous commit. |
| <kbd>f</kbd> | | Toggle file browser. |
......
......@@ -3184,6 +3184,9 @@ msgstr ""
msgid "Add webhook"
msgstr ""
 
msgid "Add your comment to a review"
msgstr ""
msgid "Add your team members and others to GitLab."
msgstr ""
 
......@@ -41535,6 +41538,9 @@ msgstr ""
msgid "Publish to status page"
msgstr ""
 
msgid "Publish your comment immediately"
msgstr ""
msgid "Published"
msgstr ""
 
......@@ -49782,6 +49788,9 @@ msgstr ""
msgid "Submit the current review."
msgstr ""
 
msgid "Submit/save changes"
msgstr ""
msgid "Submitted as ham"
msgstr ""
 
......@@ -474,6 +474,50 @@ describe('issue_comment_form component', () => {
isDraft: true,
});
});
it('should add comment when shift+cmd+enter is pressed', async () => {
mountComponent({ mountFunction: mountExtended, initialData: { note: 'a' }, store });
jest.spyOn(store, 'dispatch').mockResolvedValue();
await findMarkdownEditorTextarea().trigger('keydown.enter', {
shiftKey: true,
metaKey: true,
});
expect(store.dispatch).toHaveBeenCalledWith('saveNote', {
data: {
merge_request_diff_head_sha: undefined,
note: {
internal: false,
note: 'a',
noteable_id: noteableDataMock.id,
noteable_type: 'Issue',
},
},
endpoint: noteableDataMock.create_note_path,
isDraft: false,
});
});
it('should add comment when shift+ctrl+enter is pressed', async () => {
mountComponent({ mountFunction: mountExtended, initialData: { note: 'a' }, store });
jest.spyOn(store, 'dispatch').mockResolvedValue();
await findMarkdownEditorTextarea().trigger('keydown.enter', {
shiftKey: true,
ctrlKey: true,
});
expect(store.dispatch).toHaveBeenCalledWith('saveNote', {
data: {
merge_request_diff_head_sha: undefined,
note: {
internal: false,
note: 'a',
noteable_id: noteableDataMock.id,
noteable_type: 'Issue',
},
},
endpoint: noteableDataMock.create_note_path,
isDraft: false,
});
});
});
});
});
......
......@@ -320,6 +320,17 @@ describe('issue_note_form component', () => {
});
});
describe('on shift cmd enter', () => {
it('should add comment now when shift-cmd+enter is pressed', async () => {
textarea.setValue('Foo');
textarea.trigger('keydown.enter', { metaKey: true, shiftKey: true });
await nextTick();
expect(wrapper.emitted('handleFormUpdate')).toHaveLength(1);
});
});
describe('when adding a draft comment', () => {
beforeEach(() => {
jest.spyOn(notesEventHub, '$emit');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment