From 50da5ffd455def46cde9d00cffb60d8fb8ab47ef Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Mon, 8 Mar 2021 16:09:18 -0500 Subject: [PATCH] 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`. --- .../forum/util/MarkdownAreaEditorDriver.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/markdown/js/src/forum/util/MarkdownAreaEditorDriver.js b/extensions/markdown/js/src/forum/util/MarkdownAreaEditorDriver.js index 0cd2eea7d..5dff8ca66 100644 --- a/extensions/markdown/js/src/forum/util/MarkdownAreaEditorDriver.js +++ b/extensions/markdown/js/src/forum/util/MarkdownAreaEditorDriver.js @@ -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);