Vanessa 2025-09-09 10:02:51 +08:00
parent bfe50d9009
commit ff909fa149
3 changed files with 24 additions and 20 deletions

View file

@ -559,16 +559,12 @@ ${genHintItemHTML(item)}
}, response => {
// https://github.com/siyuan-note/siyuan/issues/10133
protyle.toolbar.range = range;
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
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 &&
protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) {
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);
}
if (refElement[0]) {
protyle.toolbar.range.setEnd(refElement[0].lastChild, refElement[0].lastChild.textContent.length);
}
protyle.toolbar.range.collapse(false);
});
@ -600,16 +596,12 @@ ${genHintItemHTML(item)}
tempElement.innerText = dynamicTexts[1];
}
}
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
});
if (protyle.toolbar.range.endContainer.nodeType === 1 &&
protyle.toolbar.range.endContainer.childNodes[protyle.toolbar.range.endOffset]) {
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);
}
if (refElement[0]) {
protyle.toolbar.range.setEnd(refElement[0].lastChild, refElement[0].lastChild.textContent.length);
}
protyle.toolbar.range.collapse(false);
return;

View file

@ -386,10 +386,13 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
}
if (types.includes("block-ref")) {
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
color: `${linkElement.dataset.id}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
});
if (refElement[0]) {
protyle.toolbar.range.selectNodeContents(refElement[0]);
}
return;
}
if (types.includes("a")) {
@ -508,12 +511,12 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
}
if (linkElement) {
const selectText = range.toString();
const aElements = protyle.toolbar.setInlineMark(protyle, "a", "range", {
const aElements = protyle.toolbar.setInlineMark(protyle, "a", "range", {
type: "a",
color: `${linkElement.getAttribute("href")}${Constants.ZWSP}${selectText || linkElement.textContent}`
});
if (!selectText) {
if(aElements[0].lastChild) {
if (aElements[0].lastChild) {
// https://github.com/siyuan-note/siyuan/issues/15801
range.setEnd(aElements[0].lastChild, aElements[0].lastChild.textContent.length);
}
@ -546,11 +549,14 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
if (range.toString() !== "") {
const firstLine = textPlain.split("\n")[0];
if (isDynamicRef(textPlain)) {
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
// range 不能 escape否则 https://github.com/siyuan-note/siyuan/issues/8359
color: `${textPlain.substring(2, 22 + 2)}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
});
if (refElement[0]) {
protyle.toolbar.range.selectNodeContents(refElement[0]);
}
return;
} else if (isFileAnnotation(firstLine)) {
protyle.toolbar.setInlineMark(protyle, "file-annotation-ref", "range", {

View file

@ -249,10 +249,13 @@ export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeEleme
}, (idResponse) => {
const refText = newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen);
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",
color: `${idResponse.data[0]}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
});
if (refElement[0]) {
protyle.toolbar.range.selectNodeContents(refElement[0]);
}
} else {
fetchPost("/api/filetree/createDocWithMd", {
notebook: targetNotebookId,
@ -260,10 +263,13 @@ export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeEleme
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
markdown: ""
}, response => {
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
color: `${response.data}${Constants.ZWSP}d${Constants.ZWSP}${refText}`
});
if (refElement[0]) {
protyle.toolbar.range.selectNodeContents(refElement[0]);
}
});
}
hideElements(["toolbar"], protyle);