FIX: Fast-edit shortcuts got lost in bdd97ff (#22762)

This commit is contained in:
Jarek Radosz 2023-07-25 14:45:59 +02:00 committed by GitHub
parent f7353e7bfa
commit 49fc775fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 33 deletions

View File

@ -1,4 +1,6 @@
<div class="fast-edit-container"> {{! template-lint-disable no-pointer-down-event-binding }}
{{! template-lint-disable no-invalid-interactive }}
<div class="fast-edit-container" {{on "keydown" this.onKeydown}}>
<textarea <textarea
{{auto-focus}} {{auto-focus}}
{{on "input" this.updateValue}} {{on "input" this.updateValue}}

View File

@ -15,6 +15,15 @@ export default class FastEdit extends Component {
modifier: translateModKey("Meta+"), modifier: translateModKey("Meta+"),
}); });
@action
onKeydown(event) {
if (event.key === "Escape") {
this.args.close();
} else if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
this.save();
}
}
@action @action
updateValue(event) { updateValue(event) {
this.value = event.target.value; this.value = event.target.value;
@ -36,7 +45,7 @@ export default class FastEdit extends Component {
popupAjaxError(error); popupAjaxError(error);
} finally { } finally {
this.isSaving = false; this.isSaving = false;
this.args.afterSave?.(); this.args.close();
} }
} }
} }

View File

@ -2,6 +2,6 @@
<FastEdit <FastEdit
@initialValue={{@model.initialValue}} @initialValue={{@model.initialValue}}
@post={{@model.post}} @post={{@model.post}}
@afterSave={{@closeModal}} @close={{@closeModal}}
/> />
</DModal> </DModal>

View File

@ -54,7 +54,7 @@
<FastEdit <FastEdit
@initialValue={{this._fastEditInitialSelection}} @initialValue={{this._fastEditInitialSelection}}
@post={{this.post}} @post={{this.post}}
@afterSave={{this._hideButton}} @close={{this._hideButton}}
/> />
{{/if}} {{/if}}

View File

@ -8,7 +8,6 @@ import {
} from "discourse/lib/utilities"; } from "discourse/lib/utilities";
import Component from "@ember/component"; import Component from "@ember/component";
import { INPUT_DELAY } from "discourse-common/config/environment"; import { INPUT_DELAY } from "discourse-common/config/environment";
import KeyEnterEscape from "discourse/mixins/key-enter-escape";
import Sharing from "discourse/lib/sharing"; import Sharing from "discourse/lib/sharing";
import { action, computed } from "@ember/object"; import { action, computed } from "@ember/object";
import { alias } from "@ember/object/computed"; import { alias } from "@ember/object/computed";
@ -43,7 +42,7 @@ export function fixQuotes(str) {
return str.replace(/[\u201C\u201D]/g, '"').replace(/[\u2018\u2019]/g, "'"); return str.replace(/[\u201C\u201D]/g, '"').replace(/[\u2018\u2019]/g, "'");
} }
export default Component.extend(KeyEnterEscape, { export default Component.extend({
modal: service(), modal: service(),
classNames: ["quote-button"], classNames: ["quote-button"],

View File

@ -7,7 +7,6 @@ import {
triggerKeyEvent, triggerKeyEvent,
visit, visit,
} from "@ember/test-helpers"; } from "@ember/test-helpers";
import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts";
import { toggleCheckDraftPopup } from "discourse/services/composer"; import { toggleCheckDraftPopup } from "discourse/services/composer";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
import TopicFixtures from "discourse/tests/fixtures/topic"; import TopicFixtures from "discourse/tests/fixtures/topic";
@ -23,6 +22,7 @@ import {
count, count,
exists, exists,
invisible, invisible,
metaModifier,
query, query,
updateCurrentUser, updateCurrentUser,
visible, visible,
@ -217,15 +217,7 @@ acceptance("Composer", function (needs) {
textarea.selectionStart = textarea.value.length; textarea.selectionStart = textarea.value.length;
textarea.selectionEnd = textarea.value.length; textarea.selectionEnd = textarea.value.length;
// Testing keyboard events is tough! await triggerKeyEvent(textarea, "keydown", "B", metaModifier);
const event = document.createEvent("Event");
event.initEvent("keydown", true, true);
event[`${PLATFORM_KEY_MODIFIER}Key`] = true;
event.key = "B";
event.keyCode = 66;
textarea.dispatchEvent(event);
await settled();
const example = I18n.t(`composer.bold_text`); const example = I18n.t(`composer.bold_text`);
assert.strictEqual( assert.strictEqual(
@ -1373,12 +1365,10 @@ acceptance("Composer - current time", function (needs) {
const date = moment().format("YYYY-MM-DD"); const date = moment().format("YYYY-MM-DD");
const eventOptions = { await triggerKeyEvent(".d-editor-input", "keydown", ".", {
...metaModifier,
shiftKey: true, shiftKey: true,
}; });
eventOptions[`${PLATFORM_KEY_MODIFIER}Key`] = true;
await triggerKeyEvent(".d-editor-input", "keydown", ".", eventOptions);
const inputValue = query("#reply-control .d-editor-input").value.trim(); const inputValue = query("#reply-control .d-editor-input").value.trim();

View File

@ -1,5 +1,6 @@
import { import {
acceptance, acceptance,
metaModifier,
query, query,
selectText, selectText,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -28,11 +29,9 @@ acceptance("Fast Edit", function (needs) {
await click(".quote-button .quote-edit-label"); await click(".quote-button .quote-edit-label");
assert.dom("#fast-edit-input").exists(); assert.dom("#fast-edit-input").exists();
assert.strictEqual( assert
query("#fast-edit-input").value, .dom("#fast-edit-input")
"Any plans", .hasValue("Any plans", "contains selected text");
"contains selected text"
);
await fillIn("#fast-edit-input", "My edit"); await fillIn("#fast-edit-input", "My edit");
await click(".save-fast-edit"); await click(".save-fast-edit");
@ -49,16 +48,23 @@ acceptance("Fast Edit", function (needs) {
await triggerKeyEvent(document, "keypress", "E"); await triggerKeyEvent(document, "keypress", "E");
assert.dom("#fast-edit-input").exists(); assert.dom("#fast-edit-input").exists();
assert.strictEqual( assert
query("#fast-edit-input").value, .dom("#fast-edit-input")
"Any plans", .hasValue("Any plans", "contains selected text");
"contains selected text"
);
// Saving
await fillIn("#fast-edit-input", "My edit"); await fillIn("#fast-edit-input", "My edit");
await click(".save-fast-edit"); await triggerKeyEvent("#fast-edit-input", "keydown", "Enter", metaModifier);
assert.dom("#fast-edit-input").doesNotExist(); assert.dom("#fast-edit-input").doesNotExist();
// Closing
await selectText(textNode, 9);
await triggerKeyEvent(document, "keypress", "E");
assert.dom("#fast-edit-input").exists();
await triggerKeyEvent("#fast-edit-input", "keydown", "Escape");
assert.dom("#fast-edit-input").doesNotExist();
}); });
test("Opens full composer for multi-line selection", async function (assert) { test("Opens full composer for multi-line selection", async function (assert) {

View File

@ -52,7 +52,10 @@ import {
} from "discourse/lib/topic-list-tracker"; } from "discourse/lib/topic-list-tracker";
import sinon from "sinon"; import sinon from "sinon";
import siteFixtures from "discourse/tests/fixtures/site-fixtures"; import siteFixtures from "discourse/tests/fixtures/site-fixtures";
import { clearExtraKeyboardShortcutHelp } from "discourse/lib/keyboard-shortcuts"; import {
PLATFORM_KEY_MODIFIER,
clearExtraKeyboardShortcutHelp,
} from "discourse/lib/keyboard-shortcuts";
import { clearResolverOptions } from "discourse-common/resolver"; import { clearResolverOptions } from "discourse-common/resolver";
import { clearNavItems } from "discourse/models/nav-item"; import { clearNavItems } from "discourse/models/nav-item";
import { import {
@ -607,3 +610,5 @@ export function normalizeHtml(html) {
resultElement.innerHTML = html; resultElement.innerHTML = html;
return resultElement.innerHTML; return resultElement.innerHTML;
} }
export const metaModifier = { [`${PLATFORM_KEY_MODIFIER}Key`]: true };