Skip to content

Commit

Permalink
Merge pull request #64 from obgnail/dev
Browse files Browse the repository at this point in the history
fix bug, multi_highlighter location error
  • Loading branch information
obgnail authored Aug 6, 2023
2 parents 014b7be + 0a4ed50 commit 8f1dbdf
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 8f1dbdf

Please sign in to comment.