From a29a02abe7ce3dd0d5d09f64e7fe918e723faa10 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 28 Jul 2022 16:18:44 +1000 Subject: [PATCH] FEATURE: Allow submitting the assign modal with ctrl+enter (#362) This commit allows submitting the assign modal with control/meta+enter when the textarea is focused. --- .../discourse-assign/controllers/assign-user.js | 10 +++++++++- .../discourse/templates/modal/assign-user.hbs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse-assign/controllers/assign-user.js b/assets/javascripts/discourse-assign/controllers/assign-user.js index 9e05a94..664c455 100644 --- a/assets/javascripts/discourse-assign/controllers/assign-user.js +++ b/assets/javascripts/discourse-assign/controllers/assign-user.js @@ -1,4 +1,5 @@ import Controller, { inject as controller } from "@ember/controller"; +import ModalFunctionality from "discourse/mixins/modal-functionality"; import { action } from "@ember/object"; import { not, or } from "@ember/object/computed"; import { inject as service } from "@ember/service"; @@ -6,7 +7,7 @@ import { isEmpty } from "@ember/utils"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; -export default Controller.extend({ +export default Controller.extend(ModalFunctionality, { topicBulkActions: controller(), assignSuggestions: null, allowedGroups: null, @@ -41,6 +42,13 @@ export default Controller.extend({ }); }, + @action + handleTextAreaKeydown(value, event) { + if ((event.ctrlKey || event.metaKey) && event.key === "Enter") { + this.assign(); + } + }, + @action assign() { if (this.isBulkAction) { diff --git a/assets/javascripts/discourse/templates/modal/assign-user.hbs b/assets/javascripts/discourse/templates/modal/assign-user.hbs index 0e806b2..7d79ca1 100644 --- a/assets/javascripts/discourse/templates/modal/assign-user.hbs +++ b/assets/javascripts/discourse/templates/modal/assign-user.hbs @@ -26,7 +26,7 @@ {{/each}} - {{textarea value=model.note}} + {{textarea id="assign-modal-note" value=model.note key-down=(action "handleTextAreaKeydown")}} {{/d-modal-body}}