An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support prepending a list item to the current list https://github.com/siyuan-note/siyuan/issues/17635
Daniel4ad26acb57e6
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex 2e617f016b..5327583834 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,6 @@{+ "listBlock": "كتلة قائمة",+ "prependListItem": "إضافة عنصر قائمة إلى بداية القائمة الحالية","selectToPageStart": "تحديد النص من المؤشر إلى بداية الصفحة","selectToPageEnd": "تحديد النص من المؤشر إلى نهاية الصفحة","appendListItem": "إضافة عنصر قائمة إلى نهاية القائمة الحالية",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex 0e0f39227f..b4dcc3f252 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,6 @@{+ "listBlock": "Listenblock",+ "prependListItem": "Listenelement am Anfang der aktuellen Liste hinzufügen","selectToPageStart": "Text vom Cursor bis zum Seitenanfang auswählen","selectToPageEnd": "Text vom Cursor bis zum Seitenende auswählen","appendListItem": "Listenelement am Ende der aktuellen Liste hinzufügen",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex a96755bc62..5559e79566 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,6 @@{+ "listBlock": "List block",+ "prependListItem": "Add a list item to the beginning of the current list","selectToPageStart": "Select text from the cursor to the beginning of the page","selectToPageEnd": "Select text from the cursor to the end of the page","appendListItem": "Add a list item to the end of the current list",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex fb88b8d2ac..413af259a4 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,6 @@{+ "listBlock": "Bloque de lista",+ "prependListItem": "Añadir un elemento al principio de la lista actual","selectToPageStart": "Seleccionar texto desde el cursor hasta el principio de la página","selectToPageEnd": "Seleccionar texto desde el cursor hasta el final de la página","appendListItem": "Añadir un elemento al final de la lista actual",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex dee3180705..0402b99d86 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,6 @@{+ "listBlock": "Bloc de liste",+ "prependListItem": "Ajouter un élément au début de la liste actuelle","selectToPageStart": "Sélectionner le texte du curseur jusqu'au début de la page","selectToPageEnd": "Sélectionner le texte du curseur jusqu'à la fin de la page","appendListItem": "Ajouter un élément à la fin de la liste actuelle",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex 23e983fb51..e1b18956d1 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,6 @@{+ "listBlock": "בלוק רשימה",+ "prependListItem": "הוספת פריט לתחילת הרשימה הנוכחית","selectToPageStart": "בחירת טקסט מהסמן עד לתחילת הדף","selectToPageEnd": "בחירת טקסט מהסמן עד לסוף הדף","appendListItem": "הוספת פריט לסוף הרשימה הנוכחית",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex 06c4d5d5df..b372f19839 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,6 @@{+ "listBlock": "सूची ब्लॉक",+ "prependListItem": "वर्तमान सूची की शुरुआत में सूची आइटम जोड़ें","selectToPageStart": "कर्सर से पृष्ठ के आरंभ तक टेक्स्ट चुनें","selectToPageEnd": "कर्सर से पृष्ठ के अंत तक टेक्स्ट चुनें","appendListItem": "वर्तमान सूची के अंत में सूची आइटम जोड़ें",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex 340b4e5d58..813f42ed7f 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,6 @@{+ "listBlock": "Blok daftar",+ "prependListItem": "Tambahkan item daftar ke awal daftar saat ini","selectToPageStart": "Pilih teks dari kursor hingga awal halaman","selectToPageEnd": "Pilih teks dari kursor hingga akhir halaman","appendListItem": "Tambahkan item daftar ke akhir daftar saat ini",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex b8e89d1d5f..61ea02a20a 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,6 @@{+ "listBlock": "Blocco elenco",+ "prependListItem": "Aggiungi un elemento all'inizio dell'elenco corrente","selectToPageStart": "Seleziona il testo dal cursore all'inizio della pagina","selectToPageEnd": "Seleziona il testo dal cursore alla fine della pagina","appendListItem": "Aggiungi un elemento alla fine dell'elenco corrente",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 98ae50e2a2..0d9c58d8b0 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,6 @@{+ "listBlock": "リストブロック",+ "prependListItem": "現在のリストの先頭にリスト項目を追加","selectToPageStart": "カーソルからページの先頭までのテキストを選択","selectToPageEnd": "カーソルからページの末尾までのテキストを選択","appendListItem": "現在のリストの末尾にリスト項目を追加",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex 73f61b73e8..16f43b76ba 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,6 @@{+ "listBlock": "목록 블록",+ "prependListItem": "현재 목록 시작 부분에 목록 항목 추가","selectToPageStart": "커서부터 페이지 시작까지 텍스트 선택","selectToPageEnd": "커서부터 페이지 끝까지 텍스트 선택","appendListItem": "현재 목록 끝에 목록 항목 추가",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex caba16c5ea..c7484ca29d 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,6 @@{+ "listBlock": "Lijstblok",+ "prependListItem": "Lijstitem toevoegen aan het begin van de huidige lijst","selectToPageStart": "Tekst vanaf de cursor tot het begin van de pagina selecteren","selectToPageEnd": "Tekst vanaf de cursor tot het einde van de pagina selecteren","appendListItem": "Lijstitem toevoegen aan het einde van de huidige lijst",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 19745a4891..c9965aa5a5 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,6 @@{+ "listBlock": "Blok listy",+ "prependListItem": "Dodaj element na początku bieżącej listy","selectToPageStart": "Zaznacz tekst od kursora do początku strony","selectToPageEnd": "Zaznacz tekst od kursora do końca strony","appendListItem": "Dodaj element na końcu bieżącej listy",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex 5831d3835d..90814dc231 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,6 @@{+ "listBlock": "Bloco de lista",+ "prependListItem": "Adicionar item ao início da lista atual","selectToPageStart": "Selecionar texto do cursor até o início da página","selectToPageEnd": "Selecionar texto do cursor até o fim da página","appendListItem": "Adicionar item ao final da lista atual",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex 3a221d5d06..972c7e05cb 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,6 @@{+ "listBlock": "Блок списка",+ "prependListItem": "Добавить элемент в начало текущего списка","selectToPageStart": "Выделить текст от курсора до начала страницы","selectToPageEnd": "Выделить текст от курсора до конца страницы","appendListItem": "Добавить элемент в конец текущего списка",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex e4781eea2c..e16c843169 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,6 @@{+ "listBlock": "Blok zoznamu",+ "prependListItem": "Pridať položku na začiatok aktuálneho zoznamu","selectToPageStart": "Vybrať text od kurzora po začiatok stránky","selectToPageEnd": "Vybrať text od kurzora po koniec stránky","appendListItem": "Pridať položku na koniec aktuálneho zoznamu",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 6f5f054b62..c4a394b4c4 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,6 @@{+ "listBlock": "บล็อกรายการ",+ "prependListItem": "เพิ่มรายการที่จุดเริ่มต้นของรายการปัจจุบัน","selectToPageStart": "เลือกข้อความจากเคอร์เซอร์ถึงจุดเริ่มต้นของหน้า","selectToPageEnd": "เลือกข้อความจากเคอร์เซอร์ถึงจุดสิ้นสุดของหน้า","appendListItem": "เพิ่มรายการที่ท้ายรายการปัจจุบัน",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex d0421492d3..5eae3450b0 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,6 @@{+ "listBlock": "Liste bloğu",+ "prependListItem": "Geçerli listenin başına liste öğesi ekle","selectToPageStart": "İmleçten sayfanın başına kadar metni seç","selectToPageEnd": "İmleçten sayfanın sonuna kadar metni seç","appendListItem": "Geçerli listenin sonuna liste öğesi ekle",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex 5644723bd4..f5614475d2 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,6 @@{+ "listBlock": "Блок списку",+ "prependListItem": "Додати елемент на початок поточного списку","selectToPageStart": "Виділити текст від курсора до початку сторінки","selectToPageEnd": "Виділити текст від курсора до кінця сторінки","appendListItem": "Додати елемент у кінець поточного списку",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex 4d346539c7..11774aa790 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,6 @@{+ "listBlock": "列表块",+ "prependListItem": "在当前列表开头添加列表项","selectToPageStart": "选中光标至页首的文本","selectToPageEnd": "选中光标至页尾的文本","appendListItem": "在当前列表末尾添加列表项",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex 9e26d38ec3..465f455180 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,6 @@{+ "listBlock": "列表區塊",+ "prependListItem": "在目前列表開頭新增列表項","selectToPageStart": "選取游標至頁首的文字","selectToPageEnd": "選取游標至頁尾的文字","appendListItem": "在目前列表末尾新增列表項",diff --git a/app/src/config/entryVisibility/catalog.test.ts b/app/src/config/entryVisibility/catalog.test.tsindex 5e8f28b5c5..3c175fb57b 100644--- a/app/src/config/entryVisibility/catalog.test.ts+++ b/app/src/config/entryVisibility/catalog.test.ts@@ -73,15 +73,19 @@ test("sortable entry catalog groups contain valid separator positions", () => {});});-test("append list item follows the insert entries in the block menu", () => {+test("list block submenu follows the base block entries", () => {const children = getEntryCatalogChildren("gutter.single");- const insertAfterIndex = children.findIndex((item) => item.key === "insertAfter");- const appendListItem = children[insertAfterIndex + 1];+ const deleteIndex = children.findIndex((item) => item.key === "delete");+ const separator = children[deleteIndex + 1];+ const listBlock = children[deleteIndex + 2];- assert.ok(0 <= insertAfterIndex);- assert.equal(appendListItem?.key, "appendListItem");- assert.equal(appendListItem?.type, "entry");- assert.equal(appendListItem?.simple, true);+ assert.ok(0 <= deleteIndex);+ assert.equal(separator?.key, "separator_listBlock");+ assert.equal(separator?.type, "separator");+ assert.equal(listBlock?.key, "listBlock");+ assert.equal(listBlock?.type, "entry");+ assert.equal(listBlock?.simple, true);+ assert.deepEqual(listBlock?.children?.map((item) => item.key), ["prependListItem", "appendListItem"]);});test("simple profile follows the reviewed defaults", () => {diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.tsindex 53391fb91e..73647c0cf6 100644--- a/app/src/config/entryVisibility/catalog.ts+++ b/app/src/config/entryVisibility/catalog.ts@@ -280,6 +280,11 @@ const gutterMultiple = () => [const gutterSingle = () => [...gutterBase(false),+ separator("separator_listBlock"),+ node("listBlock", lang("listBlock"), true, [+ node("prependListItem", lang("prependListItem")),+ node("appendListItem", lang("appendListItem")),+ ]),separator("separator_cancelSuperBlock"),node("superBlock", lang("superBlock"), true, [node("cancelSuperBlock", () => `${window.siyuan.languages.cancel} ${window.siyuan.languages.superBlock}`),@@ -361,7 +366,6 @@ const gutterSingle = () => [node("enterBack", lang("enterBack"), false),node("insertBefore", lang("insertBefore")),node("insertAfter", lang("insertAfter")),- node("appendListItem", lang("appendListItem")),node("jumpTo", lang("jumpTo"), false, [node("jumpToParentPrev", lang("jumpToParentPrev"), false),node("jumpToParentNext", lang("jumpToParentNext"), false),diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 63160bebbb..149b0fa4f0 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -91,7 +91,7 @@ import {showMessage} from "../../dialog/message";import {checkFold} from "../../util/noRelyPCFunction";import {clearSelect} from "../util/clear";import {chartRender} from "../render/chartRender";-import {appendListItem} from "../wysiwyg/list";+import {appendListItem, prependListItem} from "../wysiwyg/list";// 块类型 data-type 到本地化名称键的映射,用于块标提示中的 ${x}const BLOCK_TYPE_LANG_KEYS: { [key: string]: string } = {@@ -1898,7 +1898,36 @@ export class Gutter {}}).element);}- if (type === "NodeSuperBlock" && !protyle.disabled) {+ if ((type === "NodeList" || type === "NodeListItem") && allowStructuralMutation) {+ const listBlockSubmenu: IMenu[] = [{+ id: "prependListItem",+ icon: "iconBefore",+ label: window.siyuan.languages.prependListItem,+ click() {+ hideElements(["select"], protyle);+ countBlockWord([], protyle.block.rootID);+ void prependListItem(protyle, nodeElement as HTMLElement, range);+ }+ }, {+ id: "appendListItem",+ icon: "iconAfter",+ label: window.siyuan.languages.appendListItem,+ accelerator: window.siyuan.config.keymap.editor.list.appendListItem.custom,+ click() {+ hideElements(["select"], protyle);+ countBlockWord([], protyle.block.rootID);+ void appendListItem(protyle, nodeElement as HTMLElement, range);+ }+ }];+ window.siyuan.menus.menu.append(new MenuItem({id: "separator_listBlock", type: "separator"}).element);+ window.siyuan.menus.menu.append(new MenuItem({+ id: "listBlock",+ icon: "iconList",+ label: window.siyuan.languages.listBlock,+ type: "submenu",+ submenu: listBlockSubmenu,+ }).element);+ } else if (type === "NodeSuperBlock" && !protyle.disabled) {window.siyuan.menus.menu.append(new MenuItem({id: "separator_cancelSuperBlock",type: "separator"@@ -2521,19 +2550,6 @@ export class Gutter {insertEmptyBlock(protyle, "afterend", nodeElement);}}).element);- if (type === "NodeList" || type === "NodeListItem") {- window.siyuan.menus.menu.append(new MenuItem({- id: "appendListItem",- icon: "iconListItem",- label: window.siyuan.languages.appendListItem,- accelerator: window.siyuan.config.keymap.editor.list.appendListItem.custom,- click() {- hideElements(["select"], protyle);- countBlockWord([], protyle.block.rootID);- void appendListItem(protyle, nodeElement as HTMLElement, range);- }- }).element);- }}if (!protyle.disabled) {const countElement = nodeElement.lastElementChild?.querySelector(".protyle-attr--refcount");diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex 46cef752db..a5a2c36b84 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -10,6 +10,7 @@ import {setFold} from "../util/blockFold";import {scrollCenter} from "../../util/highlightById";import {getAppendListContext,+ getFirstListItemElement,getFollowingOrderedListMarkerUpdates,getLastListItemElement,getOrderedListMarkerUpdates,@@ -157,7 +158,21 @@ const getFocusedOrderedListUpdates = async (protyle: IProtyle, listItemElement:const insertingFocusedListItems = new WeakSet<IProtyle>();-const appendingListItems = new WeakSet<IProtyle>();+const insertingBoundaryListItems = new WeakSet<IProtyle>();++const getFocusedListElement = async (protyle: IProtyle, listID: string) => {+ const response = await fetchSyncPost("/api/block/getBlockDOM", {+ id: listID,+ notebook: protyle.notebookId,+ });+ const template = document.createElement("template");+ template.innerHTML = response.data?.dom || "";+ const listElement = template.content.firstElementChild as HTMLElement;+ if (listElement?.getAttribute("data-type") !== "NodeList") {+ return;+ }+ return listElement;+};const getFocusedListTailItem = async (protyle: IProtyle, listID: string, currentListItem?: HTMLElement) => {const tailResponse = await fetchSyncPost("/api/block/getTailChildBlocks", {@@ -187,7 +202,7 @@ const getFocusedListTailItem = async (protyle: IProtyle, listID: string, current};export const appendListItem = async (protyle: IProtyle, nodeElement: HTMLElement, range?: Range) => {- if (appendingListItems.has(protyle)) {+ if (insertingBoundaryListItems.has(protyle)) {return;}const context = getAppendListContext(nodeElement, protyle.wysiwyg.element);@@ -195,7 +210,7 @@ export const appendListItem = async (protyle: IProtyle, nodeElement: HTMLElementreturn;}- appendingListItems.add(protyle);+ insertingBoundaryListItems.add(protyle);try {let tailItemElement: HTMLElement | undefined;if (context.listElement) {@@ -234,7 +249,106 @@ export const appendListItem = async (protyle: IProtyle, nodeElement: HTMLElementfocusByWbr(newListItemElement, editorRange);scrollCenter(protyle, newListItemElement);} finally {- appendingListItems.delete(protyle);+ insertingBoundaryListItems.delete(protyle);+ }+};++export const prependListItem = async (protyle: IProtyle, nodeElement: HTMLElement, range?: Range) => {+ if (insertingBoundaryListItems.has(protyle)) {+ return;+ }+ const context = getAppendListContext(nodeElement, protyle.wysiwyg.element);+ if (!context) {+ return;+ }++ insertingBoundaryListItems.add(protyle);+ try {+ let listElement = context.listElement;+ if (!listElement && protyle.block.parentID) {+ listElement = await getFocusedListElement(protyle, protyle.block.parentID);+ }+ if (!listElement) {+ return;+ }+ const firstListItemElement = getFirstListItemElement(listElement);+ const firstID = firstListItemElement?.getAttribute("data-node-id");+ if (!firstListItemElement || !firstID) {+ return;+ }++ let startIndex: number | undefined;+ if (firstListItemElement.getAttribute("data-subtype") === "o") {+ const parsedIndex = Number.parseInt(firstListItemElement.getAttribute("data-marker"), 10);+ startIndex = Number.isFinite(parsedIndex) ? Math.trunc(parsedIndex) : 1;+ }+ const newListItemElement = genListItemElement(firstListItemElement, 0, true, startIndex);+ const id = newListItemElement.getAttribute("data-node-id");+ const doOperations: IOperation[] = [{+ action: "insert",+ id,+ data: newListItemElement.outerHTML,+ nextID: firstID,+ }];+ const undoOperations: IOperation[] = [];+ if (startIndex !== undefined) {+ const listItemElements = Array.from(listElement.children).filter((item) =>+ item.getAttribute("data-type") === "NodeListItem") as HTMLElement[];+ const markerUpdates = getFollowingOrderedListMarkerUpdates(+ newListItemElement.getAttribute("data-marker"),+ listItemElements.map((item) => item.getAttribute("data-marker")));+ listItemElements.forEach((item, index) => {+ const marker = markerUpdates[index];+ if (!marker) {+ return;+ }+ const itemID = item.getAttribute("data-node-id");+ undoOperations.push({+ action: "update",+ id: itemID,+ data: item.outerHTML,+ });+ item.setAttribute("data-marker", marker);+ const actionElement = item.querySelector(".protyle-action--order");+ if (actionElement) {+ actionElement.textContent = marker;+ }+ doOperations.push({+ action: "update",+ id: itemID,+ data: item.outerHTML,+ });+ });+ }++ const editorRange = range || getEditorRange(protyle.wysiwyg.element);+ const localNextElement = context.listElement ? firstListItemElement : context.listItemElement;+ if (!localNextElement?.isConnected) {+ return;+ }+ if (!context.listElement && startIndex !== undefined) {+ const currentItemElement = Array.from(listElement.children).find((item) =>+ item.getAttribute("data-node-id") === context.listItemElement?.getAttribute("data-node-id"));+ const marker = currentItemElement?.getAttribute("data-marker");+ if (marker) {+ context.listItemElement.setAttribute("data-marker", marker);+ const actionElement = context.listItemElement.querySelector(".protyle-action--order");+ if (actionElement) {+ actionElement.textContent = marker;+ }+ }+ }+ localNextElement.insertAdjacentElement("beforebegin", newListItemElement);+ undoOperations.unshift({+ action: "delete",+ id,+ context: getUndoFocusContext(protyle.wysiwyg.element, editorRange, true),+ });+ transaction(protyle, doOperations, undoOperations);+ focusByWbr(newListItemElement, editorRange);+ scrollCenter(protyle, newListItemElement);+ } finally {+ insertingBoundaryListItems.delete(protyle);}};diff --git a/app/src/protyle/wysiwyg/listContext.test.ts b/app/src/protyle/wysiwyg/listContext.test.tsindex 1aa4d10610..4e9d16dccb 100644--- a/app/src/protyle/wysiwyg/listContext.test.ts+++ b/app/src/protyle/wysiwyg/listContext.test.ts@@ -2,6 +2,7 @@ import {describe, it} from "node:test";import * as assert from "node:assert/strict";import {getAppendListContext,+ getFirstListItemElement,getFollowingOrderedListMarkerUpdates,getLastListItemElement,getListContext,@@ -174,6 +175,16 @@ describe("getLastListItemElement", () => {});});+describe("getFirstListItemElement", () => {+ it("ignores non-list-item children at the beginning", () => {+ const first = new TestElement("NodeListItem", "first", "u");+ const last = new TestElement("NodeListItem", "last", "u");+ const list = new TestElement("NodeList", "list", "u").append(new TestElement(), first, last);++ assert.equal(getFirstListItemElement(asHTMLElement(list)), asHTMLElement(first));+ });+});+describe("getListShortcutAction", () => {it("cancels or converts a single empty list", () => {const {paragraph, editor} = createList("u");diff --git a/app/src/protyle/wysiwyg/listContext.ts b/app/src/protyle/wysiwyg/listContext.tsindex e0ced55016..c2ea4a87aa 100644--- a/app/src/protyle/wysiwyg/listContext.ts+++ b/app/src/protyle/wysiwyg/listContext.ts@@ -47,6 +47,11 @@ export const getLastListItemElement = (listElement: HTMLElement) => {item.getAttribute("data-type") === "NodeListItem") as HTMLElement | undefined;};+export const getFirstListItemElement = (listElement: HTMLElement) => {+ return Array.from(listElement.children).find((item) =>+ item.getAttribute("data-type") === "NodeListItem") as HTMLElement | undefined;+};+export const getListContext = (nodeElement: HTMLElement, editorElement: HTMLElement): TListContext | undefined => {let listItemElement: HTMLElement | null = nodeElement;while (listItemElement && listItemElement !== editorElement &&