mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
Handle editor-driven input events.
The mdarea extension's handleKey method only applies when input is accompanied by an actual key press, and won't register programmatic inputs via `app.composer.editor` methods. We add an additional listener for custom events, which are dispatched in `setValue`.
This commit is contained in:
parent
6cbd641ad5
commit
50da5ffd45
|
@ -40,12 +40,6 @@ export default class MarkdownAreaEditorDriver extends BasicEditorDriver {
|
|||
|
||||
dom.append(this.el);
|
||||
|
||||
// We can't bind shortcutHandler directly in case `build`
|
||||
// runs before MarkdownToolbar's `oninit`.
|
||||
this.el.addEventListener('keydown', function (e) {
|
||||
return params.shortcutHandler(...arguments);
|
||||
});
|
||||
|
||||
const callInputListeners = (e) => {
|
||||
params.inputListeners.forEach((listener) => {
|
||||
listener();
|
||||
|
@ -54,6 +48,21 @@ export default class MarkdownAreaEditorDriver extends BasicEditorDriver {
|
|||
e.redraw = false;
|
||||
};
|
||||
|
||||
// We can't bind shortcutHandler directly in case `build`
|
||||
// runs before MarkdownToolbar's `oninit`.
|
||||
this.el.addEventListener('keydown', function (e) {
|
||||
return params.shortcutHandler(...arguments);
|
||||
});
|
||||
|
||||
// Our mdarea extension won't detect programmatic changes via
|
||||
// the `app.composer.editor api.
|
||||
this.el.addEventListener('input', function (e) {
|
||||
if (e instanceof CustomEvent) {
|
||||
params.oninput(e.target.value);
|
||||
callInputListeners(e);
|
||||
}
|
||||
});
|
||||
|
||||
// This one can't be run through mdarea, but that doesn't matter
|
||||
// because mdarea doesn't change value in response to clicks.
|
||||
this.el.addEventListener('click', callInputListeners);
|
||||
|
|
Loading…
Reference in New Issue
Block a user