Skip to content

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

:bug: Preserve list item content when entering list markers https://github.com/siyuan-note/siyuan/issues/18355

Danielecf87ea42729
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index a62429e149..27795f8395 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -22,6 +22,7 @@ import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {headingTurnIntoList, turnIntoTaskList} from "./turnIntoList";
import {updateAVName} from "../render/av/action";
import {setFold} from "../util/blockFold";
+import {nbsp2space} from "../util/normalizeText";
export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: Range, needRender = true, event?: InputEvent) => {
if (!blockElement.parentElement) {
@@ -213,11 +214,20 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
}
const tempElement = document.createElement("template");
tempElement.innerHTML = html;
- // 列表项内紧挨标记的第一个段落块不允许产生子列表 https://github.com/siyuan-note/siyuan/issues/17890
+ // 列表项内紧挨标记的首个段落块不生成子列表,仅移除触发标记并保留现有内容
+ // https://github.com/siyuan-note/siyuan/issues/17890 https://github.com/siyuan-note/siyuan/issues/18355
if (blockElement.closest('[data-type="NodeListItem"]') &&
blockElement.previousElementSibling?.classList.contains("protyle-action")) {
if (tempElement.content.firstElementChild.classList.contains("list")) {
- getContenteditableElement(blockElement).innerHTML = "<wbr>";
+ if (editElement.contains(wbrElement)) {
+ const markerRange = document.createRange();
+ markerRange.setStart(editElement, 0);
+ markerRange.setEndBefore(wbrElement);
+ const marker = nbsp2space(markerRange.toString()).split(Constants.ZWSP).join("");
+ if (/^ {0,3}(?:[-+*]|\d{1,9}[.)]) $/.test(marker)) {
+ markerRange.deleteContents();
+ }
+ }
html = blockElement.outerHTML;
tempElement.innerHTML = html;
}