Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(text): move list collapse shortcut to Ctrl+Alt+Enter
Elian Doran1620a54c4df4
diff --git a/packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts b/packages/ckeditor5/src/plugins/collapsible_list_items.spec.tsindex a5040eaf01..00d2bf8d50 100644--- a/packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts+++ b/packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts@@ -255,26 +255,37 @@ describe("CollapsibleListItems", () => {expect(getBlock(editor, 0).getAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(true);});- it("toggles via Ctrl+Enter on a collapsible item and ignores leaves", () => {- pressCtrlEnter(editor); // selection starts in the parent+ it("toggles via Ctrl+Alt+Enter on a collapsible item and ignores leaves", () => {+ pressCtrlAltEnter(editor); // selection starts in the parentexpect(getBlock(editor, 0).getAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(true);- pressCtrlEnter(editor);+ pressCtrlAltEnter(editor);expect(getBlock(editor, 0).hasAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(false);setSelectionIn(editor, 1); // leaf child: nothing to collapse- pressCtrlEnter(editor);+ pressCtrlAltEnter(editor);expect(getBlock(editor, 1).hasAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(false);});- it("leaves Ctrl+Enter to the native to-do check on to-do items", () => {+ it("collapses to-do items via Ctrl+Alt+Enter without checking them", () => {+ setModelData(editor.model,+ '<paragraph listIndent="0" listItemId="ta-a" listType="todo">Parent[]</paragraph>' ++ '<paragraph listIndent="1" listItemId="ta-b" listType="todo">Child</paragraph>');++ pressCtrlAltEnter(editor);++ expect(getBlock(editor, 0).getAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(true);+ expect(getBlock(editor, 0).hasAttribute("todoListChecked")).toBe(false);+ });++ it("leaves Ctrl+Enter to the native to-do check (no longer bound to collapse)", () => {setModelData(editor.model,'<paragraph listIndent="0" listItemId="t-a" listType="todo">Parent[]</paragraph>' +'<paragraph listIndent="1" listItemId="t-b" listType="todo">Child</paragraph>');pressCtrlEnter(editor);- // The collapse toggle must not fire; the native checkTodoList command handles it.+ // Collapse no longer touches Ctrl+Enter, so the native checkTodoList handles it.expect(getBlock(editor, 0).hasAttribute(LIST_COLLAPSED_ATTRIBUTE)).toBe(false);expect(getBlock(editor, 0).getAttribute("todoListChecked")).toBe(true);});@@ -294,6 +305,16 @@ function setSelectionIn(editor: ClassicEditor, blockIndex: number): void {});}+function pressCtrlAltEnter(editor: ClassicEditor): void {+ editor.editing.view.document.fire("keydown", {+ keyCode: keyCodes.enter,+ ctrlKey: true,+ altKey: true,+ preventDefault: () => {},+ stopPropagation: () => {}+ });+}+function pressCtrlEnter(editor: ClassicEditor): void {editor.editing.view.document.fire("keydown", {keyCode: keyCodes.enter,diff --git a/packages/ckeditor5/src/plugins/collapsible_list_items.ts b/packages/ckeditor5/src/plugins/collapsible_list_items.tsindex f40e164c7f..2cc3698b40 100644--- a/packages/ckeditor5/src/plugins/collapsible_list_items.ts+++ b/packages/ckeditor5/src/plugins/collapsible_list_items.ts@@ -1,6 +1,6 @@import "../theme/collapsible_list_items.css";-import { Command, getCode, ListEditing, MouseObserver, parseKeystroke, Plugin, type Editor, type ModelElement, type ModelNode, type ModelWriter, type ViewDocumentKeyDownEvent, type ViewDocumentMouseDownEvent, type ViewElement } from "ckeditor5";+import { Command, ListEditing, MouseObserver, Plugin, type Editor, type ModelElement, type ModelNode, type ModelWriter, type ViewDocumentMouseDownEvent, type ViewElement } from "ckeditor5";export const LIST_COLLAPSED_ATTRIBUTE = "listCollapsed";@@ -52,30 +52,21 @@ export default class CollapsibleListItems extends Plugin {}/**- * Toggles the collapsed state on Ctrl+Enter. To-do items keep the native Ctrl+Enter- * (check the item), so the handler bails on them; it runs at the highest priority because- * the native to-do binding stops the event unconditionally on every Ctrl+Enter.+ * Toggles the collapsed state on Ctrl+Alt+Enter, uniformly for every list type. Ctrl+Enter is+ * deliberately avoided: it is already the native to-do "check item" shortcut (and a Trilium+ * global), so collapse gets its own conflict-free binding rather than fighting over it.*/private _enableToggleOnKeystroke() {const editor = this.editor;- const toggleKeystroke = parseKeystroke("Ctrl+Enter");- this.listenTo<ViewDocumentKeyDownEvent>(editor.editing.view.document, "keydown", (evt, data) => {- if (getCode(data) !== toggleKeystroke) {- return;- }+ editor.keystrokes.set("Ctrl+Alt+Enter", (_data, cancel) => {const command = editor.commands.get("toggleListCollapse");if (!command?.isEnabled) {return;}- const block = getSelectedListBlock(editor);- if (block?.getAttribute("listType") === "todo") {- return;- }editor.execute("toggleListCollapse");- data.preventDefault();- evt.stop();- }, {priority: "highest"});+ cancel();+ });}/**