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

This commit is contained in:
Penar Musaraj 2021-10-07 05:25:58 -04:00 committed by GitHub
parent 0dbc83132a
commit 8a377130f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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, {

View File

@ -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
}}