Jelajahi Sumber

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

Vanessa 2 tahun lalu
induk
melakukan
a5417ec301
1 mengubah file dengan 20 tambahan dan 2 penghapusan
  1. 20 2
      app/src/protyle/header/Title.ts

+ 20 - 2
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