Skip to content

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

:art: Convert empty list item paragraphs with list shortcuts https://github.com/siyuan-note/siyuan/issues/14123

Daniel2baf31617629
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index ab368e474a..34f9e17983 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -1866,7 +1866,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const isListItemFocused = Boolean(protyle.block.showAll &&
protyle.block.id === listContext.listItemElement.dataset.nodeId);
const action = getListShortcutAction(listContext, targetSubtype,
- listContext.childElements.length === 1 && isEmptyParagraph(listContext.childElements[0]),
+ isEmptyParagraph(listContext.childElement),
isListItemFocused);
if (action === "cancelList" || action === "convertList") {
const conversionType = action === "convertList" ?
@@ -1884,6 +1884,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
} else if (action === "insertListItem") {
insertEmptyListItem(protyle, listContext.listItemElement, range);
+ } else if (action === "convertChildToList") {
+ turnsIntoOneTransaction({
+ protyle,
+ selectsElement: [listContext.childElement],
+ type: isMatchCheck ? "Blocks2TLs" : (isMatchList ? "Blocks2ULs" : "Blocks2OLs")
+ });
} else {
insertEmptyChildList(protyle, listContext.childElement, targetSubtype, range);
}
diff --git a/app/src/protyle/wysiwyg/listContext.test.ts b/app/src/protyle/wysiwyg/listContext.test.ts
index a3610618f4..093c9e8a79 100644
--- a/app/src/protyle/wysiwyg/listContext.test.ts
+++ b/app/src/protyle/wysiwyg/listContext.test.ts
@@ -145,7 +145,16 @@ describe("getListShortcutAction", () => {
assert.equal(getListShortcutAction(context, "u", false, false), "insertChildList");
});
- it("inserts a child list when the list item has multiple children", () => {
+ it("converts an empty child in a list item with multiple children", () => {
+ const secondChild = new TestElement("NodeParagraph", "second");
+ const {paragraph, editor} = createList("o", secondChild);
+ const context = getListContext(asHTMLElement(paragraph), asHTMLElement(editor))!;
+
+ assert.equal(getListShortcutAction(context, "o", true, false), "convertChildToList");
+ assert.equal(getListShortcutAction(context, "u", true, false), "convertChildToList");
+ });
+
+ it("inserts a child list after a non-empty child in a list item with multiple children", () => {
const secondChild = new TestElement("NodeParagraph", "second");
const {paragraph, editor} = createList("o", secondChild);
const context = getListContext(asHTMLElement(paragraph), asHTMLElement(editor))!;
diff --git a/app/src/protyle/wysiwyg/listContext.ts b/app/src/protyle/wysiwyg/listContext.ts
index 093e8f84ee..a71676488b 100644
--- a/app/src/protyle/wysiwyg/listContext.ts
+++ b/app/src/protyle/wysiwyg/listContext.ts
@@ -1,6 +1,7 @@
export type TListSubtype = "u" | "o" | "t";
-export type TListShortcutAction = "cancelList" | "convertList" | "insertListItem" | "insertChildList";
+export type TListShortcutAction = "cancelList" | "convertList" | "convertChildToList" | "insertListItem" |
+ "insertChildList";
export type TListContext = {
listElement?: HTMLElement,
@@ -67,6 +68,9 @@ export const getListShortcutAction = (context: TListContext, targetSubtype: TLis
if (context.childElements.length === 1 && isSameSubtype && !hasFoldedHeading) {
return "insertListItem";
}
+ if (context.childElements.length > 1 && isEmptyChild) {
+ return "convertChildToList";
+ }
return "insertChildList";
};