From d3c8812e513578bd7f2d11c5efa35068259c67f8 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 2 Aug 2018 01:44:10 +0300 Subject: [PATCH] listen on newly added section's CodeMirror too --- edit/codemirror-editing-hooks.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/edit/codemirror-editing-hooks.js b/edit/codemirror-editing-hooks.js index 8ac7d69a..17d968b6 100644 --- a/edit/codemirror-editing-hooks.js +++ b/edit/codemirror-editing-hooks.js @@ -632,7 +632,9 @@ onDOMscriptReady('/codemirror.js').then(() => { } /** - * Observes newly added section elements and sets an 'input' event listener on .applies-to inside. + * Observes newly added section elements, and sets these event listeners: + * 1. 'changes' on CodeMirror inside + * 2. 'input' on .applies-to inside * The goal is to avoid listening to 'input' on the entire #sections tree, * which would trigger updatePreview() twice on any keystroke - * both for the synthetic event from CodeMirror and the original event. @@ -652,6 +654,7 @@ onDOMscriptReady('/codemirror.js').then(() => { for (const node of addedNodes) { const el = node.children && $('.applies-to', node); if (el) el.addEventListener('input', updatePreview); + if (node.CodeMirror) node.CodeMirror.on('changes', updatePreview); } } });