Skip to content

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

:bug: Ignore list shortcuts for selected list items https://github.com/siyuan-note/siyuan/issues/14123

Danielaf11995abe00
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 098dc49ce8..a8dcdaa6fd 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -64,7 +64,13 @@ import {
listOutdent,
toggleTaskListItem
} from "./list";
-import {getListContext, getListConversionType, getListShortcutAction, type TListSubtype} from "./listContext";
+import {
+ getListContext,
+ getListConversionType,
+ getListShortcutAction,
+ shouldIgnoreListShortcut,
+ type TListSubtype
+} from "./listContext";
import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {cancelSB, insertEmptyBlock, jumpToParent} from "../../block/util";
import {isEncryptedBox, isLocalPath} from "../../util/pathName";
@@ -1794,6 +1800,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (selectsElement.length === 1) {
const subType = selectsElement[0].dataset.subtype;
const type = selectsElement[0].dataset.type;
+ if (!isMatchQuote && shouldIgnoreListShortcut(hasBlockSelection, type)) {
+ event.preventDefault();
+ event.stopPropagation();
+ return;
+ }
if (isMatchQuote) {
const blockquoteContext = hasBlockSelection ? undefined :
getBlockquoteContext(selectsElement[0], protyle.wysiwyg.element);
diff --git a/app/src/protyle/wysiwyg/listContext.test.ts b/app/src/protyle/wysiwyg/listContext.test.ts
index 6fd42d6834..a3610618f4 100644
--- a/app/src/protyle/wysiwyg/listContext.test.ts
+++ b/app/src/protyle/wysiwyg/listContext.test.ts
@@ -5,6 +5,7 @@ import {
getListContext,
getListConversionType,
getListShortcutAction,
+ shouldIgnoreListShortcut,
type TListSubtype
} from "./listContext";
@@ -175,6 +176,14 @@ describe("getFollowingOrderedListMarkerUpdates", () => {
});
});
+describe("shouldIgnoreListShortcut", () => {
+ it("ignores only a selected list item", () => {
+ assert.equal(shouldIgnoreListShortcut(true, "NodeListItem"), true);
+ assert.equal(shouldIgnoreListShortcut(true, "NodeList"), false);
+ assert.equal(shouldIgnoreListShortcut(false, "NodeListItem"), false);
+ });
+});
+
describe("getListConversionType", () => {
it("maps every list subtype conversion", () => {
assert.equal(getListConversionType("u", "o"), "UL2OL");
diff --git a/app/src/protyle/wysiwyg/listContext.ts b/app/src/protyle/wysiwyg/listContext.ts
index 5050c685c4..093e8f84ee 100644
--- a/app/src/protyle/wysiwyg/listContext.ts
+++ b/app/src/protyle/wysiwyg/listContext.ts
@@ -81,6 +81,10 @@ export const getFollowingOrderedListMarkerUpdates = (currentMarker: string, foll
});
};
+export const shouldIgnoreListShortcut = (hasBlockSelection: boolean, selectedType?: string) => {
+ return hasBlockSelection && selectedType === "NodeListItem";
+};
+
export const getListConversionType = (sourceSubtype: TListSubtype, targetSubtype: TListSubtype) => {
if (sourceSubtype === targetSubtype) {
return;