diff --git a/plugin/collapse_paragraph.js b/plugin/collapse_paragraph.js index 47ca9162..878eb32f 100644 --- a/plugin/collapse_paragraph.js +++ b/plugin/collapse_paragraph.js @@ -62,7 +62,9 @@ } const rollback = start => { - let ele = start.closest("#write [cid]"); + if (!document.querySelector(`#write > .${config.CLASS_NAME}`)) return; + + let ele = start.closest("#write > [cid]"); const pList = []; while (ele) { diff --git a/plugin/multi_highlighter/index.js b/plugin/multi_highlighter/index.js index 5ab88ec0..6f5f8a98 100644 --- a/plugin/multi_highlighter/index.js +++ b/plugin/multi_highlighter/index.js @@ -233,6 +233,15 @@ const metaKeyPressed = ev => File.isMac ? ev.metaKey : ev.ctrlKey; const getFilePath = () => File.filePath || File.bundle && File.bundle.filePath; + const collapsePlugin = global._getPlugin("collapse_paragraph"); + const truncatePlugin = global._getPlugin("truncate_text"); + const compatibleOtherPlugin = target => { + if (!target) return; + + collapsePlugin && collapsePlugin.meta && collapsePlugin.meta.rollback && collapsePlugin.meta.rollback(target); + truncatePlugin && truncatePlugin.meta && truncatePlugin.meta.rollback && truncatePlugin.meta.rollback(target); + } + const multiHighlighterClass = reqnode(reqnode('path').join(global.dirname || global.__dirname, "plugin", "multi_highlighter", "multi_highlighter.js")).multiHighlighter; const multiHighlighter = new multiHighlighterClass(); @@ -434,6 +443,8 @@ return; } + compatibleOtherPlugin(next); + showMarkerInfo.idxOfWrite = whichMarker(entities.write, next); const fence = next.closest("#write .md-fences"); diff --git a/plugin/truncate_text.js b/plugin/truncate_text.js index 676c43e2..fb280067 100644 --- a/plugin/truncate_text.js +++ b/plugin/truncate_text.js @@ -3,7 +3,6 @@ // 剩余文本段 REMAIN_LENGTH: 80, - IN_USE: false, CLASS_NAME: "plugin-truncate-text", } @@ -21,7 +20,6 @@ } const hideFront = () => { - config.IN_USE = true; const write = document.getElementById("write"); const length = write.children.length; if (length > config.REMAIN_LENGTH) { @@ -34,14 +32,12 @@ } const showAll = () => { - config.IN_USE = false; const write = document.getElementById("write"); write.getElementsByClassName(config.CLASS_NAME).forEach(el => el.classList.remove(config.CLASS_NAME)); write.children.forEach(el => el.style.display = ""); }; const hideBaseView = () => { - config.IN_USE = true; const write = document.getElementById("write"); let start = 0, end = 0; write.children.forEach((ele, idx) => { @@ -69,18 +65,23 @@ // 已废弃 const rollback2 = start => { - if (!config.IN_USE) return; - let ele = start.closest("#write [cid]"); - while (ele) { - if (ele.classList.contains(config.CLASS_NAME)) { - ele.classList.remove(config.CLASS_NAME); - ele.style.display = ""; + if (document.querySelector(`#write > .${config.CLASS_NAME}`)) { + let ele = start.closest("#write > [cid]"); + while (ele) { + if (ele.classList.contains(config.CLASS_NAME)) { + ele.classList.remove(config.CLASS_NAME); + ele.style.display = ""; + } + ele = ele.nextElementSibling; } - ele = ele.nextElementSibling; } } - const rollback = () => showAll(); + const rollback = () => { + if (document.querySelector(`#write > .${config.CLASS_NAME}`)) { + showAll(); + } + }; const call = type => { if (type === "hide_front") {