Skip to content

A platform for community discussion. Free, open, simple.

UX: Add keyboard shortcut for fast edits (#14543)

Penar Musaraj8a377130f4a2
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
}}