From d8e99b12f184f9c40c204f8328f1fb3612f5a6ef Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Mon, 28 Feb 2022 19:00:26 -0500 Subject: [PATCH 1/2] Re-enable the editor mutation observer --- static/application.js | 18 ++++++++++++++++++ templates/index.html | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/static/application.js b/static/application.js index 7e7352fb..2f380585 100644 --- a/static/application.js +++ b/static/application.js @@ -1628,6 +1628,21 @@ function highlightEditingChunks() { } } +// This gets run every time the text in a chunk is edited +// or a chunk is deleted +function chunkOnDOMMutate(mutations, observer) { + if(!gametext_bound || !allowedit) { + return; + } + var nodes = []; + for(var i = 0; i < mutations.length; i++) { + var mutation = mutations[i]; + nodes = nodes.concat(Array.from(mutation.addedNodes), Array.from(mutation.removedNodes)); + nodes.push(mutation.target); + } + applyChunkDeltas(nodes); +} + // This gets run every time you try to paste text into the editor function chunkOnPaste(event) { // Register the chunk we're pasting in as having been modified @@ -1705,10 +1720,12 @@ function chunkOnFocusOut(event) { } function bindGametext() { + mutation_observer.observe(game_text[0], {characterData: true, childList: true, subtree: true}); gametext_bound = true; } function unbindGametext() { + mutation_observer.disconnect(); gametext_bound = false; } @@ -2280,6 +2297,7 @@ $(document).ready(function(){ ).on('focusout', chunkOnFocusOut ); + mutation_observer = new MutationObserver(chunkOnDOMMutate); // This is required for the editor to work correctly in Firefox on desktop // because the gods of HTML and JavaScript say so diff --git a/templates/index.html b/templates/index.html index 192ed9fc..40812cee 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@ - +
From f9ac23ba4e50146104f02916cba4633cd84e2e98 Mon Sep 17 00:00:00 2001 From: henk717