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(splits): move the focus between splits from the keyboard
Elian Doran917805477558
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex b2116f2a2b..9e4c689683 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -313,6 +313,8 @@ export type CommandMappings = {closeActiveNoteSplit: CommandData;moveActiveNoteSplitLeft: CommandData;moveActiveNoteSplitRight: CommandData;+ focusNoteSplitLeft: CommandData;+ focusNoteSplitRight: CommandData;jumpToNote: CommandData;openTodayNote: CommandData;commandPalette: CommandData;diff --git a/apps/client/src/components/tab_manager.spec.ts b/apps/client/src/components/tab_manager.spec.tsindex 5c499f415b..a10e969f04 100644--- a/apps/client/src/components/tab_manager.spec.ts+++ b/apps/client/src/components/tab_manager.spec.ts@@ -190,6 +190,37 @@ describe("buildNoteContextStatesFromUrl", () => {});});+describe("moving the focus between splits", () => {+ it("steps one pane at a time and stops at both ends of the tab", async () => {+ const tm = new TabManager();+ // a pane resolves its siblings by asking the app which contexts are open+ appContext.tabManager = tm;+ const [ main ] = await openEmptyTabs(tm, 1);+ const split = await tm.openEmptyTab(null, "root", main.ntxId);+ const otherTab = await tm.openEmptyTab();+ expect(tm.children.map((nc) => nc.ntxId)).toEqual([ main.ntxId, split.ntxId, otherTab.ntxId ]);++ await tm.activateNoteContext(main.ntxId);+ const triggerEvent = vi.spyOn(tm, "triggerEvent").mockReturnValue(undefined);++ await tm.focusNoteSplitRightCommand();+ expect(tm.activeNtxId).toBe(split.ntxId);+ // activating the pane moves the tree; the caret follows on its own event+ expect(triggerEvent).toHaveBeenCalledWith("focusOnDetail", { ntxId: split.ntxId });++ // the tab next door is not the next pane+ await tm.focusNoteSplitRightCommand();+ expect(tm.activeNtxId).toBe(split.ntxId);++ await tm.focusNoteSplitLeftCommand();+ expect(tm.activeNtxId).toBe(main.ntxId);++ // and nothing sits to the left of the first pane+ await tm.focusNoteSplitLeftCommand();+ expect(tm.activeNtxId).toBe(main.ntxId);+ });+});+function openEmptyTabs(tm: TabManager, count: number) {return Promise.all(Array.from({ length: count }, () => tm.openEmptyTab()));}diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.tsindex d4688f1604..ae266792b4 100644--- a/apps/client/src/components/tab_manager.ts+++ b/apps/client/src/components/tab_manager.ts@@ -660,6 +660,34 @@ export default class TabManager extends Component {await this.activateTabContext(newActiveNtxId);}+ async focusNoteSplitLeftCommand() {+ await this.focusAdjacentNoteSplit(-1);+ }++ async focusNoteSplitRightCommand() {+ await this.focusAdjacentNoteSplit(1);+ }++ /**+ * Moves the focus one pane along inside the active tab. The panes of a tab are a row, so this+ * stops at either end rather than wrapping around to the far side, and it never crosses into a+ * neighbouring tab.+ */+ private async focusAdjacentNoteSplit(offset: number) {+ const activeContext = this.noteContexts.find((nc) => nc.ntxId === this.activeNtxId);+ if (!activeContext) return;++ const panes = activeContext.getMainContext().getSubContexts();+ const currentIndex = panes.indexOf(activeContext);+ const targetNtxId = panes[currentIndex + offset]?.ntxId;+ if (!targetNtxId) return;++ // Activating the pane is what the tree and hoisting follow; the caret is a separate event,+ // which the type widgets pick up for the pane it names.+ await this.activateNoteContext(targetNtxId);+ await this.triggerEvent("focusOnDetail", { ntxId: targetNtxId });+ }+async closeActiveTabCommand() {await this.removeNoteContext(this.activeNtxId);}diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex 4e9c23851d..1014fd6d5f 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -72,7 +72,9 @@"toggle-classic-editor-toolbar": "Toggle the Formatting tab for the editor with fixed toolbar","toggle-zen-mode": "Enables/disables the zen mode (minimal UI for more focused editing)","create-new-split": "Open a new empty split to the right of the active one",- "close-active-split": "Close the active split, keeping the other splits of the tab open"+ "close-active-split": "Close the active split, keeping the other splits of the tab open",+ "focus-split-left": "Move the focus to the split on the left of the active one",+ "focus-split-right": "Move the focus to the split on the right of the active one"},"keyboard_action_names": {"back-in-note-history": "Back in Note History",@@ -179,7 +181,9 @@"create-new-split": "Create New Split","close-active-split": "Close Active Split","move-split-left": "Move Split Left",- "move-split-right": "Move Split Right"+ "move-split-right": "Move Split Right",+ "focus-split-left": "Focus Split to the Left",+ "focus-split-right": "Focus Split to the Right"},"login": {"title": "Login",diff --git a/packages/commons/src/lib/keyboard_actions_interface.ts b/packages/commons/src/lib/keyboard_actions_interface.tsindex 7e9391fc03..c479ae1e30 100644--- a/packages/commons/src/lib/keyboard_actions_interface.ts+++ b/packages/commons/src/lib/keyboard_actions_interface.ts@@ -53,6 +53,8 @@ const enum KeyboardActionNamesEnum {closeActiveNoteSplit,moveActiveNoteSplitLeft,moveActiveNoteSplitRight,+ focusNoteSplitLeft,+ focusNoteSplitRight,showNoteSource,showOptions,showRevisions,diff --git a/packages/trilium-core/src/services/keyboard_actions.spec.ts b/packages/trilium-core/src/services/keyboard_actions.spec.tsindex 9b98cd00b5..47a926f893 100644--- a/packages/trilium-core/src/services/keyboard_actions.spec.ts+++ b/packages/trilium-core/src/services/keyboard_actions.spec.ts@@ -54,7 +54,12 @@ describe("keyboard_actions service", () => {it("ships the split actions unbound, so no layout is left unable to press them", () => {const actions = keyboardActions.getDefaultKeyboardActions();- for (const actionName of [ "openNewNoteSplit", "closeActiveNoteSplit", "moveActiveNoteSplitLeft", "moveActiveNoteSplitRight" ]) {+ const splitActions = [+ "openNewNoteSplit", "closeActiveNoteSplit", "moveActiveNoteSplitLeft", "moveActiveNoteSplitRight",+ "focusNoteSplitLeft", "focusNoteSplitRight"+ ];++ for (const actionName of splitActions) {const action = actions.find((a) => "actionName" in a && a.actionName === actionName);expect(action, actionName).toBeDefined();expect(action && "defaultShortcuts" in action && action.defaultShortcuts, actionName).toEqual([]);diff --git a/packages/trilium-core/src/services/keyboard_actions.ts b/packages/trilium-core/src/services/keyboard_actions.tsindex 0342e1bc10..b2f89fcd9b 100644--- a/packages/trilium-core/src/services/keyboard_actions.ts+++ b/packages/trilium-core/src/services/keyboard_actions.ts@@ -442,6 +442,22 @@ function getDefaultKeyboardActions() {defaultShortcuts: [],scope: "window"},+ {+ actionName: "focusNoteSplitLeft",+ friendlyName: t("keyboard_action_names.focus-split-left"),+ iconClass: "bx bx-left-arrow-alt",+ defaultShortcuts: [],+ description: t("keyboard_actions.focus-split-left"),+ scope: "window"+ },+ {+ actionName: "focusNoteSplitRight",+ friendlyName: t("keyboard_action_names.focus-split-right"),+ iconClass: "bx bx-right-arrow-alt",+ defaultShortcuts: [],+ description: t("keyboard_actions.focus-split-right"),+ scope: "window"+ },{separator: t("keyboard_actions.dialogs")