From 24c4fe6d2fa8c1824129535502d4f619fcf0f912 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 23 Oct 2024 12:45:40 +0800 Subject: refactor: set observers for charactorData/childList separately * this patches e774e55, make code easier to understanded * use data attribute to initialize content in container * add limitation on method replaceNode(), to prevent GeoLinks generated in pre/code/a element --- src/editor.mjs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/editor.mjs') diff --git a/src/editor.mjs b/src/editor.mjs index 3a70ae6..430353a 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -30,22 +30,17 @@ dumbyContainer.dataset.scrollLine = '' new window.MutationObserver(mutations => { const mutation = mutations.at(-1) - /** Handle layout change */ + // Handle layout change const layout = dumbyContainer.dataset.layout - if (layout !== 'normal' || mutation.oldValue === 'normal') { + if (layout && (layout !== 'normal' || mutation.oldValue === 'normal')) { context.dataset.mode = '' } }).observe(dumbyContainer, { attributes: true, attributeFilter: ['data-layout'], attributeOldValue: true, - childList: true, - subtree: true, }) -const dumbymap = generateMaps(dumbyContainer, { crs }) -if (initialLayout) { - dumbyContainer.dataset.layout = initialLayout -} +const dumbymap = generateMaps(dumbyContainer, { crs, initialLayout }) // Set oncontextmenu callback dumbymap.utils.setContextMenu(menuForEditor) @@ -431,19 +426,6 @@ const completeForCodeBlock = change => { } } -/* Disable debounce temporarily */ -// const debounceForMap = (() => { -// const timer = null -// -// return function (...args) { -// dumbymap = generateMaps.apply(this, args) -// clearTimeout(timer); -// timer = setTimeout(() => { -// dumbymap = generateMaps.apply(this, args) -// }, 10); -// } -// })() - /** * menuForEditor. * -- cgit v1.2.3-70-g09d2