Forráskód Böngészése

:art: fix https://github.com/siyuan-note/siyuan/issues/5485

Vanessa 2 éve
szülő
commit
e86e8e242f

+ 6 - 1
app/src/protyle/wysiwyg/index.ts

@@ -25,7 +25,7 @@ import {dropEvent} from "../util/editorCommonEvent";
 import {input} from "./input";
 import {
     getContenteditableElement,
-    getLastBlock,
+    getLastBlock, getNextBlock,
     getPreviousHeading,
     getTopAloneElement,
     hasNextSibling,
@@ -297,7 +297,12 @@ export class WYSIWYG {
                         html = `<div data-subtype="${selectElements[0].getAttribute("data-subtype")}" data-node-id="${Lute.NewNodeID()}" data-type="NodeList" class="list">${html}<div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
                     }
                 }
+                const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
                 removeBlock(protyle, nodeElement, range);
+                if (nextElement) {
+                    // Ctrl+X 剪切后光标应跳到下一行行首 https://github.com/siyuan-note/siyuan/issues/5485
+                    focusBlock(nextElement);
+                }
             } else {
                 const id = nodeElement.getAttribute("data-node-id");
                 const oldHTML = nodeElement.outerHTML;

+ 9 - 1
app/src/protyle/wysiwyg/keydown.ts

@@ -1362,11 +1362,19 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
 
         if (isNotEditBlock(nodeElement) && matchHotKey("⌘X", event)) {
             let html = "";
-            protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
+            nodeElement.classList.add("protyle-wysiwyg--select");
+            const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")
+            selectElements.forEach(item => {
                 html += removeEmbed(item);
             });
             writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
+            const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
             removeBlock(protyle, nodeElement, range);
+            if (nextElement) {
+                focusBlock(nextElement);
+            }
+            event.preventDefault();
+            event.stopPropagation();
         }
 
         if (matchHotKey(window.siyuan.config.keymap.editor.general.vLayout.custom, event)) {

+ 1 - 1
app/src/protyle/wysiwyg/remove.ts

@@ -443,7 +443,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
         focusSideBlock(previousElement);
     } else {
         const previousLastEditElement = getContenteditableElement(previousLastElement);
-        if (editableElement.textContent !== "") {
+        if (editableElement && editableElement.textContent !== "") {
             // 非空块
             range.setEndAfter(editableElement.lastChild);
             // 数学公式会车后再删除 https://github.com/siyuan-note/siyuan/issues/3850