From a3c33565df0db50a5a229cd508d735ed2cd46469 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 27 Apr 2023 11:17:58 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/8106 --- app/src/protyle/wysiwyg/input.ts | 4 ++-- app/src/protyle/wysiwyg/turnIntoList.ts | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts index 20919824a..878a1ccdd 100644 --- a/app/src/protyle/wysiwyg/input.ts +++ b/app/src/protyle/wysiwyg/input.ts @@ -49,10 +49,10 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: wbrElement.remove(); return; } - if (turnIntoTaskList(protyle, type, blockElement, editElement)) { + if (turnIntoTaskList(protyle, type, blockElement, editElement, range)) { return; } - if (headingTurnIntoList(protyle, type, blockElement, editElement)) { + if (headingTurnIntoList(protyle, type, blockElement, editElement, range)) { return; } // table、粗体 中也会有 br,仅用于类似#a#,删除后会产生的 br diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.ts index d1d601585..a015f9309 100644 --- a/app/src/protyle/wysiwyg/turnIntoList.ts +++ b/app/src/protyle/wysiwyg/turnIntoList.ts @@ -2,7 +2,7 @@ import {transaction, updateTransaction} from "./transaction"; import {focusByWbr} from "../util/selection"; import * as dayjs from "dayjs"; -export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement) => { +export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement, range: Range) => { if (type !== "NodeCodeBlock" && blockElement.parentElement.getAttribute("data-subtype") !== "t" && ( @@ -29,6 +29,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: blockElement.previousElementSibling.outerHTML = `
` editElement.innerHTML = editElement.innerHTML.substring(contextStartIndex); updateTransaction(protyle, liElement.getAttribute("data-node-id"), liElement.outerHTML, oldHTML); + focusByWbr(protyle.wysiwyg.element, range) return true; } return false; @@ -46,7 +47,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: }, { action: "insert", id: newId, - data: `
`, + data: `
`, previousID: id, }, { action: "move", @@ -67,16 +68,17 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: action: "delete", id: newId }]); - blockElement.outerHTML = `
${blockElement.outerHTML}
` - focusByWbr(protyle.wysiwyg.element, getSelection().getRangeAt(0)) + blockElement.outerHTML = `
${blockElement.outerHTML}
` + focusByWbr(protyle.wysiwyg.element, range) return true; } } return false } -export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement) => { - if (type !== "NodeHeading" && ["* ", "- "].includes(editElement.innerHTML.substring(0, 2))) { +export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement, range: Range) => { + if (type === "NodeHeading" && ["* ", "- "].includes(editElement.innerHTML.substring(0, 2)) && + blockElement.parentElement.getAttribute("data-type") !== "NodeListItem") { const id = blockElement.getAttribute("data-node-id") const newId = Lute.NewNodeID(); const emptyId = Lute.NewNodeID(); @@ -90,7 +92,7 @@ export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElemen }, { action: "insert", id: newId, - data: `
`, + data: `
`, previousID: id, }, { action: "move", @@ -111,9 +113,9 @@ export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElemen action: "delete", id: newId }]); - blockElement.outerHTML = `
${blockElement.outerHTML}
` - focusByWbr(protyle.wysiwyg.element, getSelection().getRangeAt(0)) - return true; + blockElement.outerHTML = `
${blockElement.outerHTML}
` + focusByWbr(protyle.wysiwyg.element, range) + return true } return false }