DEV: refactor composer-editor/d-editor, a little more (#29973)

Adds setupEditor to ComposerEditor so it can setup/destroy events when the underlying editorComponent is switched.

Moves putCursorAtEnd uses (which implementation is textarea-specific) to TextareaTextManipulation.

Moves insertCurrentTime and a corresponding test, which is discourse-local-dates specific, to the plugin.

Moves applyList and formatCode from DEditor to the TextareaTextManipulation.

Moves DEditor._applySurround to TextareaTextManipulation.applySurroundSelection

Avoids resetting the textarea value on applyList and formatCode, keeping the undo history.
This commit is contained in:
Renato Atilio
2024-12-02 18:24:14 -03:00
committed by GitHub
parent 706987ce76
commit 85691a7f31
9 changed files with 216 additions and 168 deletions

View File

@ -1,6 +1,9 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import {
acceptance,
metaModifier,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Local Dates - composer", function (needs) {
@ -128,4 +131,24 @@ acceptance("Local Dates - composer", function (needs) {
await click("ul.formats a.moment-format");
assert.dom("input.format-input").hasValue("LLL");
});
test("composer insert current time shortcut", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", "and the time now is: ");
await triggerKeyEvent(".d-editor-input", "keydown", ".", {
...metaModifier,
shiftKey: true,
});
const date = moment().format("YYYY-MM-DD");
assert
.dom("#reply-control .d-editor-input")
.hasValue(
new RegExp(`and the time now is: \\[date=${date}`),
"it adds the current date"
);
});
});