mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
This commit is contained in:
parent
a400fa3896
commit
493eba5a14
1 changed files with 14 additions and 14 deletions
|
|
@ -317,8 +317,8 @@ const updateEmbed = (protyle: IProtyle, operation: IOperation) => {
|
|||
}
|
||||
};
|
||||
|
||||
const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle) => {
|
||||
if (focus) {
|
||||
const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle, isUndo: boolean) => {
|
||||
if (isUndo) {
|
||||
focusSideBlock(updateElements[0]);
|
||||
}
|
||||
updateElements.forEach(item => {
|
||||
|
|
@ -333,7 +333,7 @@ const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle) =
|
|||
});
|
||||
};
|
||||
|
||||
const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOperation, focus: boolean) => {
|
||||
const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOperation, isUndo: boolean) => {
|
||||
updateElements.forEach(item => {
|
||||
item.outerHTML = operation.data;
|
||||
});
|
||||
|
|
@ -345,7 +345,7 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO
|
|||
}
|
||||
});
|
||||
const wbrElement = updateElements[0].querySelector("wbr");
|
||||
if (focus) {
|
||||
if (isUndo) {
|
||||
const range = getEditorRange(updateElements[0]);
|
||||
if (wbrElement) {
|
||||
focusByWbr(updateElements[0], range);
|
||||
|
|
@ -366,7 +366,7 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO
|
|||
};
|
||||
|
||||
// 用于推送和撤销
|
||||
export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: boolean) => {
|
||||
export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: boolean) => {
|
||||
const updateElements: Element[] = [];
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
|
||||
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
|
||||
|
|
@ -423,8 +423,8 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
}
|
||||
if (operation.action === "delete") {
|
||||
if (updateElements.length > 0) {
|
||||
deleteBlock(updateElements, operation.id, protyle);
|
||||
} else {
|
||||
deleteBlock(updateElements, operation.id, protyle, isUndo);
|
||||
} else if (isUndo){
|
||||
zoomOut({
|
||||
protyle,
|
||||
id: protyle.block.rootID,
|
||||
|
|
@ -436,7 +436,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
updateElements.push(item);
|
||||
}
|
||||
});
|
||||
deleteBlock(updateElements, operation.id, protyle);
|
||||
deleteBlock(updateElements, operation.id, protyle, isUndo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -444,8 +444,8 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
}
|
||||
if (operation.action === "update") {
|
||||
if (updateElements.length > 0) {
|
||||
updateBlock(updateElements, protyle, operation, focus);
|
||||
} else {
|
||||
updateBlock(updateElements, protyle, operation, isUndo);
|
||||
} else if (isUndo) {
|
||||
zoomOut({
|
||||
protyle,
|
||||
id: protyle.block.rootID,
|
||||
|
|
@ -457,7 +457,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
updateElements.push(item);
|
||||
}
|
||||
});
|
||||
updateBlock(updateElements, protyle, operation, focus);
|
||||
updateBlock(updateElements, protyle, operation, isUndo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -548,7 +548,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
}
|
||||
if (operation.action === "move") {
|
||||
let range;
|
||||
if (focus && getSelection().rangeCount > 0) {
|
||||
if (isUndo && getSelection().rangeCount > 0) {
|
||||
range = getSelection().getRangeAt(0);
|
||||
range.insertNode(document.createElement("wbr"));
|
||||
}
|
||||
|
|
@ -605,7 +605,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
removeTopElement(item, protyle);
|
||||
}
|
||||
});
|
||||
if (focus && range) {
|
||||
if (isUndo && range) {
|
||||
if (operation.data === "focus") {
|
||||
// 标记需要 focus,https://ld246.com/article/1650018446988/comment/1650081404993?r=Vanessa#comments
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).find(item => {
|
||||
|
|
@ -675,7 +675,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
avRender(item);
|
||||
blockRender(protyle, item);
|
||||
const wbrElement = item.querySelector("wbr");
|
||||
if (focus) {
|
||||
if (isUndo) {
|
||||
const range = getEditorRange(item);
|
||||
if (wbrElement) {
|
||||
focusByWbr(item, range);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue