Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/16703

Vanessa30ff7c0d13d8
diff --git a/app/src/block/util.ts b/app/src/block/util.ts
index 95b1df00fa..c45fc20b20 100644
--- a/app/src/block/util.ts
+++ b/app/src/block/util.ts
@@ -191,7 +191,8 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id
protyle,
selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
focusByWbr(protyle.wysiwyg.element, range);
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index cda011467b..1ccc01a61a 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -426,7 +426,8 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
protyle,
selectsElement: newSourceParentElement.reverse(),
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
if (document.contains(sourceElements[0])) {
@@ -515,7 +516,8 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
protyle,
selectsElement: newSourceParentElement.reverse(),
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
if (document.contains(sourceElements[0])) {
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index 59f4bb7e26..7a94aa0f87 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -1,7 +1,7 @@
import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/util";
import {focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection";
import {
- getContenteditableElement,
+ getContenteditableElement, getParentBlock,
getTopEmptyElement,
hasNextSibling,
hasPreviousSibling,
@@ -117,12 +117,10 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
}
// bq || callout
- const isCallout = blockElement.parentElement.classList.contains("callout-content");
- const parentBlockElement = isCallout ? blockElement.parentElement.parentElement : blockElement.parentElement;
if (editableElement.textContent.replace(Constants.ZWSP, "").replace("\n", "") === "" &&
((blockElement.nextElementSibling && blockElement.nextElementSibling.classList.contains("protyle-attr") &&
blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") ||
- (isCallout && !blockElement.nextElementSibling))) {
+ (blockElement.parentElement.classList.contains("callout-content") && !blockElement.nextElementSibling))) {
range.insertNode(document.createElement("wbr"));
const topElement = getTopEmptyElement(blockElement);
const blockId = blockElement.getAttribute("data-node-id");
@@ -137,6 +135,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
id: topId,
data: topElement.outerHTML,
};
+ let parentBlockElement = getParentBlock(blockElement);
if (topId === blockId) {
doInsert.previousID = parentBlockElement.getAttribute("data-node-id");
undoInsert.previousID = blockElement.previousElementSibling.getAttribute("data-node-id");
@@ -156,13 +155,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
action: "delete",
id: blockId,
}, undoInsert]);
+ parentBlockElement = getParentBlock(blockElement);
if (topId === blockId && parentBlockElement.classList.contains("sb") &&
parentBlockElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
focusByWbr(blockElement, range);
@@ -197,7 +198,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
data: newElement.outerHTML,
id: newId,
previousID: blockElement.previousElementSibling ? blockElement.previousElementSibling.getAttribute("data-node-id") : "",
- parentID: parentBlockElement.getAttribute("data-node-id") || protyle.block.parentID
+ parentID: getParentBlock(blockElement).getAttribute("data-node-id") || protyle.block.parentID
}], [{
action: "delete",
id: newId,
@@ -209,7 +210,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
}
range.insertNode(document.createElement("wbr"));
const html = blockElement.outerHTML;
- const parentHTML = parentBlockElement.outerHTML;
+ const parentHTML = getParentBlock(blockElement).outerHTML;
if (range.toString() !== "") {
// 选中数学公式后回车取消选中 https://github.com/siyuan-note/siyuan/issues/12637#issuecomment-2381106949
const mathElement = hasClosestByAttribute(range.startContainer, "data-type", "inline-math");
@@ -353,7 +354,8 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
protyle,
selectsElement,
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
focusByWbr(currentElement, range);
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index 9f5d686ed4..f1669769fe 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -513,7 +513,8 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
protyle,
selectsElement: [liElement, liElement.nextElementSibling],
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
focusByWbr(parentLiItemElement, range);
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 25574d4088..666b2fe5fc 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -655,7 +655,8 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele
protyle,
selectsElement: selectsElement.reverse(),
type: "BlocksMergeSuperBlock",
- level: "row"
+ level: "row",
+ unfocus: true,
});
}
focusByWbr(protyle.wysiwyg.element, range);
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index fc85b3e286..e9bfa53081 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -13,7 +13,7 @@ import {getAllModels} from "../../layout/getAll";
/// #endif
import {avRender, refreshAV} from "../render/av/render";
import {removeFoldHeading} from "../util/heading";
-import {genEmptyElement, genSBElement} from "../../block/util";
+import {cancelSB, genEmptyElement, genSBElement} from "../../block/util";
import {hideElements} from "../ui/hideElements";
import {reloadProtyle} from "../util/reload";
import {countBlockWord} from "../../layout/status";
@@ -935,11 +935,12 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
}
};
-export const turnsIntoOneTransaction = (options: {
+export const turnsIntoOneTransaction = async (options: {
protyle: IProtyle,
selectsElement: Element[],
type: TTurnIntoOne,
- level?: TTurnIntoOneSub
+ level?: TTurnIntoOneSub,
+ unfocus?: boolean
}) => {
let parentElement: Element;
const id = Lute.NewNodeID();
@@ -1048,8 +1049,16 @@ export const turnsIntoOneTransaction = (options: {
blockRender(options.protyle, item);
}
});
+ if ((["Blocks2Blockquote", "Blocks2Callout"].includes(options.type) || options.type.endsWith("Ls")) &&
+ parentElement.parentElement.classList.contains("sb") && parentElement.parentElement.childElementCount === 2) {
+ const cancelOperations = await cancelSB(options.protyle, parentElement.parentElement);
+ doOperations.push(...cancelOperations.doOperations);
+ undoOperations.splice(0, 0, ...cancelOperations.undoOperations);
+ }
transaction(options.protyle, doOperations, undoOperations);
- focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`));
+ if (!options.unfocus) {
+ focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`));
+ }
hideElements(["gutter"], options.protyle);
};