mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 22:38:49 +01:00
This commit is contained in:
parent
35942795f2
commit
a3c33565df
2 changed files with 14 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = `<div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>`
|
||||
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: `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,
|
||||
data: `<div data-subtype="t" data-node-id="${newId}" updated="${newId.split("-")[0]}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,
|
||||
previousID: id,
|
||||
}, {
|
||||
action: "move",
|
||||
|
|
@ -67,16 +68,17 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:
|
|||
action: "delete",
|
||||
id: newId
|
||||
}]);
|
||||
blockElement.outerHTML = `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`
|
||||
focusByWbr(protyle.wysiwyg.element, getSelection().getRangeAt(0))
|
||||
blockElement.outerHTML = `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list" updated="${newId.split("-")[0]}"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`
|
||||
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: `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,
|
||||
data: `<div data-subtype="u" data-node-id="${newId}" data-type="NodeList" class="list" updated="${newId.split("-")[0]}"><div data-marker="${editElement.innerHTML.substring(0, 1)}" data-subtype="u" data-node-id="${liItemId}" data-type="NodeListItem" class="li" updated="${liItemId.split("-")[0]}"><div class="protyle-action" draggable="true"><svg><use xlink:href="#iconDot"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,
|
||||
previousID: id,
|
||||
}, {
|
||||
action: "move",
|
||||
|
|
@ -111,9 +113,9 @@ export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElemen
|
|||
action: "delete",
|
||||
id: newId
|
||||
}]);
|
||||
blockElement.outerHTML = `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`
|
||||
focusByWbr(protyle.wysiwyg.element, getSelection().getRangeAt(0))
|
||||
return true;
|
||||
blockElement.outerHTML = `<div data-subtype="u" data-node-id="${newId}" data-type="NodeList" class="list" updated="${newId.split("-")[0]}"><div data-marker="${editElement.innerHTML.substring(0, 1)}" data-subtype="u" data-node-id="${liItemId}" data-type="NodeListItem" class="li" updated="${liItemId.split("-")[0]}"><div class="protyle-action" draggable="true"><svg><use xlink:href="#iconDot"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`
|
||||
focusByWbr(protyle.wysiwyg.element, range)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue