Skip to content

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

:wheelchair: fix https://github.com/siyuan-note/siyuan/issues/5870

Vanessaa5417ec30109
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index 846d6007d8..4028f01c27 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -1,6 +1,6 @@
import {
focusBlock,
- focusByRange,
+ focusByRange, focusByWbr,
getEditorRange,
} from "../util/selection";
import {fetchPost} from "../../util/fetch";
@@ -26,6 +26,8 @@ import {getNoContainerElement} from "../wysiwyg/getBlock";
import {commonHotkey} from "../wysiwyg/commonHotkey";
import {code160to32} from "../util/code160to32";
import {deleteFile} from "../../editor/deleteFile";
+import {genEmptyElement} from "../../block/util";
+import {transaction} from "../wysiwyg/transaction";
export class Title {
public element: HTMLElement;
@@ -80,7 +82,7 @@ export class Title {
return true;
}
- if (event.key === "ArrowDown" || event.key === "Enter") {
+ if (event.key === "ArrowDown") {
const noContainerElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild);
// https://github.com/siyuan-note/siyuan/issues/4923
if (noContainerElement) {
@@ -88,6 +90,22 @@ export class Title {
}
event.preventDefault();
event.stopPropagation();
+ } else if (event.key === "Enter") {
+ const newId = Lute.NewNodeID()
+ const newElement = genEmptyElement(false, true, newId)
+ protyle.wysiwyg.element.insertAdjacentElement("afterbegin", newElement);
+ focusByWbr(newElement, protyle.toolbar.range || getEditorRange(newElement));
+ transaction(protyle, [{
+ action: "insert",
+ data: newElement.outerHTML,
+ id: newId,
+ parentID: protyle.block.parentID
+ }], [{
+ action: "delete",
+ id: newId,
+ }]);
+ event.preventDefault();
+ event.stopPropagation();
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.attr.custom, event)) {
fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID