mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
9916fe7f65
commit
8f530a9b0a
4 changed files with 58 additions and 10 deletions
|
|
@ -1614,5 +1614,3 @@ export class Toolbar {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,48 @@ export const previewTemplate = (pathString: string, element: Element, parentId:
|
||||||
element.innerHTML = `<div class="protyle-wysiwyg" style="padding: 8px">${response.data.content.replace(/contenteditable="true"/g, "")}</div>`;
|
element.innerHTML = `<div class="protyle-wysiwyg" style="padding: 8px">${response.data.content.replace(/contenteditable="true"/g, "")}</div>`;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mergeElement = (a: Element, b: Element, after = true) => {
|
||||||
|
a.setAttribute("data-type", a.getAttribute("data-type").replace("search-mark", "").trim());
|
||||||
|
b.setAttribute("data-type", b.getAttribute("data-type").replace("search-mark", "").trim());
|
||||||
|
const attributes = a.attributes
|
||||||
|
let isMatch = true
|
||||||
|
for (let i = 0; i < attributes.length; i++) {
|
||||||
|
if (b.getAttribute(attributes[i].name) !== attributes[i].value) {
|
||||||
|
isMatch = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMatch) {
|
||||||
|
if (after) {
|
||||||
|
a.innerHTML = a.innerHTML + b.innerHTML
|
||||||
|
} else {
|
||||||
|
a.innerHTML = b.innerHTML + a.innerHTML
|
||||||
|
}
|
||||||
|
b.remove();
|
||||||
|
}
|
||||||
|
return isMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const removeSearchMark = (element: HTMLElement) => {
|
||||||
|
let previousElement = element.previousSibling as HTMLElement;
|
||||||
|
while (previousElement && previousElement.nodeType !== 3) {
|
||||||
|
if (!mergeElement(element, previousElement, false)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
previousElement = element.previousSibling as HTMLElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let nextElement = element.nextSibling as HTMLElement;
|
||||||
|
while (nextElement && nextElement.nodeType !== 3) {
|
||||||
|
if (!mergeElement(element, nextElement)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
nextElement = element.nextSibling as HTMLElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.getAttribute("data-type").includes("search-mark")) {
|
||||||
|
element.setAttribute("data-type", element.getAttribute("data-type").replace("search-mark", "").trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ import {setTableAlign} from "../util/table";
|
||||||
import {countBlockWord, countSelectWord} from "../../layout/status";
|
import {countBlockWord, countSelectWord} from "../../layout/status";
|
||||||
import {showMessage} from "../../dialog/message";
|
import {showMessage} from "../../dialog/message";
|
||||||
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
|
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
|
||||||
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
|
|
||||||
export class WYSIWYG {
|
export class WYSIWYG {
|
||||||
public lastHTMLs: { [key: string]: string } = {};
|
public lastHTMLs: { [key: string]: string } = {};
|
||||||
|
|
@ -1181,6 +1182,9 @@ export class WYSIWYG {
|
||||||
protyle.toolbar.range = getEditorRange(protyle.element);
|
protyle.toolbar.range = getEditorRange(protyle.element);
|
||||||
if (target.tagName === "SPAN" && !protyle.disabled) { // https://ld246.com/article/1665141518103
|
if (target.tagName === "SPAN" && !protyle.disabled) { // https://ld246.com/article/1665141518103
|
||||||
const types = protyle.toolbar.getCurrentType(protyle.toolbar.range);
|
const types = protyle.toolbar.getCurrentType(protyle.toolbar.range);
|
||||||
|
if (types.length > 0) {
|
||||||
|
removeSearchMark(target);
|
||||||
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(protyle, target);
|
refMenu(protyle, target);
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
|
|
@ -1189,20 +1193,16 @@ export class WYSIWYG {
|
||||||
target.removeAttribute("prevent-popover");
|
target.removeAttribute("prevent-popover");
|
||||||
}, 620);
|
}, 620);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (types.includes("file-annotation-ref")) {
|
||||||
if (types.includes("file-annotation-ref")) {
|
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (types.includes("tag")) {
|
||||||
if (types.includes("tag")) {
|
|
||||||
tagMenu(protyle, target);
|
tagMenu(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (types.includes("inline-memo")) {
|
||||||
if (types.includes("inline-memo")) {
|
|
||||||
protyle.toolbar.showRender(protyle, target);
|
protyle.toolbar.showRender(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (types.includes("a")) {
|
||||||
if (types.includes("a")) {
|
|
||||||
linkMenu(protyle, target);
|
linkMenu(protyle, target);
|
||||||
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
||||||
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import {getSavePath} from "../../util/newFile";
|
||||||
import {escapeHtml} from "../../util/escape";
|
import {escapeHtml} from "../../util/escape";
|
||||||
import {insertHTML} from "../util/insertHTML";
|
import {insertHTML} from "../util/insertHTML";
|
||||||
import {quickMakeCard} from "../../card/makeCard";
|
import {quickMakeCard} from "../../card/makeCard";
|
||||||
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
|
|
||||||
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||||
|
|
@ -526,6 +527,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
const inlineElement = hasClosestByAttribute(range.startContainer, "data-type", null);
|
const inlineElement = hasClosestByAttribute(range.startContainer, "data-type", null);
|
||||||
if (inlineElement) {
|
if (inlineElement) {
|
||||||
const types = inlineElement.getAttribute("data-type").split(" ");
|
const types = inlineElement.getAttribute("data-type").split(" ");
|
||||||
|
if (types.length > 0) {
|
||||||
|
protyle.toolbar.range = range;
|
||||||
|
removeSearchMark(inlineElement);
|
||||||
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(protyle, inlineElement);
|
refMenu(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue