From 8a377130f4a2eb822cdbf7b6f25c5bac1644a1b8 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 7 Oct 2021 05:25:58 -0400 Subject: [PATCH] UX: Add keyboard shortcut for fast edits (#14543) --- .../discourse/app/components/quote-button.js | 20 ++++++++++++++++++- .../app/templates/components/quote-button.hbs | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js index 09261a0f359..a41198a7c6f 100644 --- a/app/assets/javascripts/discourse/app/components/quote-button.js +++ b/app/assets/javascripts/discourse/app/components/quote-button.js @@ -7,9 +7,12 @@ import { selectedElement, selectedText, setCaretPosition, + translateModKey, } from "discourse/lib/utilities"; import Component from "@ember/component"; +import I18n from "I18n"; import { INPUT_DELAY } from "discourse-common/config/environment"; +import KeyEnterEscape from "discourse/mixins/key-enter-escape"; import Sharing from "discourse/lib/sharing"; import { action } from "@ember/object"; import { alias } from "@ember/object/computed"; @@ -41,7 +44,7 @@ function regexSafeStr(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } -export default Component.extend({ +export default Component.extend(KeyEnterEscape, { classNames: ["quote-button"], classNameBindings: ["visible", "_displayFastEditInput:fast-editing"], visible: false, @@ -54,6 +57,9 @@ export default Component.extend({ _fastEditNewSelection: null, _isSavingFastEdit: false, _canEditPost: false, + _saveEditButtonTitle: I18n.t("composer.title", { + modifier: translateModKey("Meta+"), + }), _isMouseDown: false, _reselected: false, @@ -422,6 +428,18 @@ export default Component.extend({ .catch(popupAjaxError); }, + @action + save() { + if (this._displayFastEditInput && !this._saveFastEditDisabled) { + this._saveFastEdit(); + } + }, + + @action + cancelled() { + this._hideButton(); + }, + @action share(source) { Sharing.shareSource(source, { diff --git a/app/assets/javascripts/discourse/app/templates/components/quote-button.hbs b/app/assets/javascripts/discourse/app/templates/components/quote-button.hbs index 06827a16b3b..38d4d4da18a 100644 --- a/app/assets/javascripts/discourse/app/templates/components/quote-button.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/quote-button.hbs @@ -54,6 +54,7 @@ class="btn-small btn-primary save-fast-edit" icon="pencil-alt" label="composer.save_edit" + translatedTitle=_saveEditButtonTitle disabled=_saveFastEditDisabled isLoading=_isSavingFastEdit }}