An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve focused ordered list numbering and caret https://github.com/siyuan-note/siyuan/issues/11990
Daniel0c93bbb82e4b
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex b76dbdf680..86f6a71608 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -240,6 +240,28 @@ export const getFocusedOrderedListInsertOperations = (listElement: HTMLElement,return {doOperations, undoOperations};};+export const getFocusedOrderedListRemoveOperations = (listElement: HTMLElement,+ previousListItemElement: HTMLElement,+ removedListItemID: string) => {+ const doOperations: IOperation[] = [];+ const undoOperations: IOperation[] = [];+ if (listElement.getAttribute("data-subtype") !== "o") {+ return {doOperations, undoOperations};+ }+ const previousClone = getDirectListItemByID(listElement,+ previousListItemElement.getAttribute("data-node-id"));+ const removedClone = getDirectListItemByID(listElement, removedListItemID);+ if (!previousClone || !removedClone) {+ return {doOperations, undoOperations};+ }+ const oldHTML = listElement.outerHTML;+ const startIndex = Number.parseInt(getOrderedListItemElements(listElement)[0]?.getAttribute("data-marker"), 10);+ previousClone.replaceWith(previousListItemElement.cloneNode(true));+ removedClone.remove();+ appendFocusedListUpdate(listElement, oldHTML, doOperations, undoOperations, startIndex);+ return {doOperations, undoOperations};+};+const appendFocusedIndentListUpdate = (listElement: HTMLElement, previousElement: HTMLElement,movedElements: Element[], doOperations: IOperation[],undoOperations: IOperation[]) => {@@ -753,6 +775,7 @@ export const listIndent = async (protyle: IProtyle, liItemElements: Element[], rappendFocusedIndentListUpdate(focusedParentListElement, previousElement as HTMLElement,liItemElements, doOperations, undoOperations);}+ newLastPreviousElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");transaction(protyle, doOperations, undoOperations);}} else {@@ -873,6 +896,7 @@ export const listIndent = async (protyle: IProtyle, liItemElements: Element[], rappendFocusedIndentListUpdate(focusedParentListElement, previousElement as HTMLElement,liItemElements, doOperations, undoOperations);}+ previousElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");transaction(protyle, doOperations, undoOperations);}}diff --git a/app/src/protyle/wysiwyg/listContext.test.ts b/app/src/protyle/wysiwyg/listContext.test.tsindex 03a34ade9f..e2663fbe2e 100644--- a/app/src/protyle/wysiwyg/listContext.test.ts+++ b/app/src/protyle/wysiwyg/listContext.test.ts@@ -281,6 +281,8 @@ describe("getOrderedListMarkerUpdates", () => {[undefined, undefined, "12.", "13.", "14.", "15."]);assert.deepEqual(getOrderedListMarkerUpdates(["10.", "11.", "1.", "12.", "13.", "14.", "15."]),[undefined, undefined, "12.", "13.", "14.", "15.", "16."]);+ assert.deepEqual(getOrderedListMarkerUpdates(["10.", "11.", "14.", "15.", "16.", "17.", "18."]),+ [undefined, undefined, "12.", "13.", "14.", "15.", "16."]);});});diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex 28c1c60402..a132684fee 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -27,7 +27,12 @@ import {} from "./getBlock";import {transaction, turnsIntoOneTransaction, turnsIntoTransaction, updateTransaction} from "./transaction";import {cancelSB, genEmptyElement, rebalanceSbWidth, refreshSbResize} from "../../block/util";-import {listOutdent, updateListOrder} from "./list";+import {+ getFocusedOrderedListRemoveOperations,+ getFocusedParentOrderedList,+ listOutdent,+ updateListOrder+} from "./list";import {zoomOut} from "../../menus/protyle";import {preventScroll} from "../scroll/preventScroll";import {hideElements} from "../ui/hideElements";@@ -1637,6 +1642,16 @@ const removeLi = async (protyle: IProtyle, blockElement: Element, range: Range,protyle, deletedListItemIDs, [listItemElement], [listItemId])) {return;}+ const shouldUpdateParentList = listElement.classList.contains("protyle-wysiwyg") &&+ listItemElement.getAttribute("data-subtype") === "o";+ const focusedParentListElement = shouldUpdateParentList ?+ await getFocusedParentOrderedList(protyle, listElement) : undefined;+ if (shouldUpdateParentList && !focusedParentListElement) {+ return;+ }+ if (!listItemElement.isConnected || !previousListItem.isConnected) {+ return;+ }moveToPrevious(blockElement, range, isDelete);range.insertNode(document.createElement("wbr"));const html = listElement.outerHTML;@@ -1732,7 +1747,11 @@ const removeLi = async (protyle: IProtyle, blockElement: Element, range: Range,}transaction(protyle, doOperations, undoOperations);} else if (listElement.classList.contains("protyle-wysiwyg")) {- transaction(protyle, doOperations, undoOperations);+ const orderOperations = focusedParentListElement ?+ getFocusedOrderedListRemoveOperations(focusedParentListElement,+ previousListItem as HTMLElement, listItemId) : {doOperations: [], undoOperations: []};+ transaction(protyle, [...doOperations, ...orderOperations.doOperations],+ [...undoOperations, ...orderOperations.undoOperations]);} else {if (listElement.getAttribute("data-subtype") === "o") {updateListOrder(listElement);