mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
This commit is contained in:
parent
bfe50d9009
commit
ff909fa149
3 changed files with 24 additions and 20 deletions
|
@ -559,16 +559,12 @@ ${genHintItemHTML(item)}
|
||||||
}, response => {
|
}, response => {
|
||||||
// https://github.com/siyuan-note/siyuan/issues/10133
|
// https://github.com/siyuan-note/siyuan/issues/10133
|
||||||
protyle.toolbar.range = range;
|
protyle.toolbar.range = range;
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
color: `${response.data}${Constants.ZWSP}${refIsS ? "s" : "d"}${Constants.ZWSP}${(refIsS ? fileNames[0] : realFileName).substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen)}`
|
color: `${response.data}${Constants.ZWSP}${refIsS ? "s" : "d"}${Constants.ZWSP}${(refIsS ? fileNames[0] : realFileName).substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen)}`
|
||||||
});
|
});
|
||||||
if (protyle.toolbar.range.endContainer.nodeType === 1 &&
|
if (refElement[0]) {
|
||||||
protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) {
|
protyle.toolbar.range.setEnd(refElement[0].lastChild, refElement[0].lastChild.textContent.length);
|
||||||
const refElement = hasPreviousSibling(protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) as HTMLElement;
|
|
||||||
if (refElement && refElement.nodeType === 1 && refElement.getAttribute("data-type") === "block-ref") {
|
|
||||||
setLastNodeRange(refElement as HTMLElement, protyle.toolbar.range, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
protyle.toolbar.range.collapse(false);
|
protyle.toolbar.range.collapse(false);
|
||||||
});
|
});
|
||||||
|
@ -600,16 +596,12 @@ ${genHintItemHTML(item)}
|
||||||
tempElement.innerText = dynamicTexts[1];
|
tempElement.innerText = dynamicTexts[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
|
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
|
||||||
});
|
});
|
||||||
if (protyle.toolbar.range.endContainer.nodeType === 1 &&
|
if (refElement[0]) {
|
||||||
protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) {
|
protyle.toolbar.range.setEnd(refElement[0].lastChild, refElement[0].lastChild.textContent.length);
|
||||||
const refElement = hasPreviousSibling(protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) as HTMLElement;
|
|
||||||
if (refElement && refElement.nodeType === 1 && refElement.getAttribute("data-type") === "block-ref") {
|
|
||||||
setLastNodeRange(refElement as HTMLElement, protyle.toolbar.range, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
protyle.toolbar.range.collapse(false);
|
protyle.toolbar.range.collapse(false);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -386,10 +386,13 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
}
|
}
|
||||||
|
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
color: `${linkElement.dataset.id}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
|
color: `${linkElement.dataset.id}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
|
||||||
});
|
});
|
||||||
|
if (refElement[0]) {
|
||||||
|
protyle.toolbar.range.selectNodeContents(refElement[0]);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (types.includes("a")) {
|
if (types.includes("a")) {
|
||||||
|
@ -546,11 +549,14 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
if (range.toString() !== "") {
|
if (range.toString() !== "") {
|
||||||
const firstLine = textPlain.split("\n")[0];
|
const firstLine = textPlain.split("\n")[0];
|
||||||
if (isDynamicRef(textPlain)) {
|
if (isDynamicRef(textPlain)) {
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
// range 不能 escape,否则 https://github.com/siyuan-note/siyuan/issues/8359
|
// range 不能 escape,否则 https://github.com/siyuan-note/siyuan/issues/8359
|
||||||
color: `${textPlain.substring(2, 22 + 2)}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
|
color: `${textPlain.substring(2, 22 + 2)}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
|
||||||
});
|
});
|
||||||
|
if (refElement[0]) {
|
||||||
|
protyle.toolbar.range.selectNodeContents(refElement[0]);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (isFileAnnotation(firstLine)) {
|
} else if (isFileAnnotation(firstLine)) {
|
||||||
protyle.toolbar.setInlineMark(protyle, "file-annotation-ref", "range", {
|
protyle.toolbar.setInlineMark(protyle, "file-annotation-ref", "range", {
|
||||||
|
|
|
@ -249,10 +249,13 @@ export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeEleme
|
||||||
}, (idResponse) => {
|
}, (idResponse) => {
|
||||||
const refText = newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen);
|
const refText = newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen);
|
||||||
if (idResponse.data && idResponse.data.length > 0) {
|
if (idResponse.data && idResponse.data.length > 0) {
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
color: `${idResponse.data[0]}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
|
color: `${idResponse.data[0]}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
|
||||||
});
|
});
|
||||||
|
if (refElement[0]) {
|
||||||
|
protyle.toolbar.range.selectNodeContents(refElement[0]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/filetree/createDocWithMd", {
|
fetchPost("/api/filetree/createDocWithMd", {
|
||||||
notebook: targetNotebookId,
|
notebook: targetNotebookId,
|
||||||
|
@ -260,10 +263,13 @@ export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeEleme
|
||||||
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
|
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
|
||||||
markdown: ""
|
markdown: ""
|
||||||
}, response => {
|
}, response => {
|
||||||
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
type: "id",
|
type: "id",
|
||||||
color: `${response.data}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
|
color: `${response.data}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
|
||||||
});
|
});
|
||||||
|
if (refElement[0]) {
|
||||||
|
protyle.toolbar.range.selectNodeContents(refElement[0]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
hideElements(["toolbar"], protyle);
|
hideElements(["toolbar"], protyle);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue