Skip to content

Commit

Permalink
fix bug, multi_highlighter location error
Browse files Browse the repository at this point in the history
  • Loading branch information
obgnail committed Aug 6, 2023
1 parent cd3e0a6 commit 0a4ed50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion plugin/collapse_paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions plugin/multi_highlighter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -434,6 +443,8 @@
return;
}

compatibleOtherPlugin(next);

showMarkerInfo.idxOfWrite = whichMarker(entities.write, next);

const fence = next.closest("#write .md-fences");
Expand Down
25 changes: 13 additions & 12 deletions plugin/truncate_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// 剩余文本段
REMAIN_LENGTH: 80,

IN_USE: false,
CLASS_NAME: "plugin-truncate-text",
}

Expand All @@ -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) {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit 0a4ed50

Please sign in to comment.