Something went wrong. Try again.
A local-first note taking app
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import type { MutableRefObject } from 'react';import type { ActionSet, ActionDefinition } from '../types';
/** * Bridge type that TilingWorkspace writes into and the ActionSet reads from. */export interface TilingHandle { splitRight(): void; splitDown(): void; newTab(): void; closeActiveTab(): void; nextTab(): void; prevTab(): void;}
/** * ActionSet for tiling workspace actions. * * The handle is populated by TilingWorkspace via a ref bridge so the * ActionSet can trigger splits without owning tiling state. */export class TilingActionSet implements ActionSet { readonly id = 'tiling';
constructor(private handleRef: MutableRefObject<TilingHandle | null>) {}
getActions(): ActionDefinition[] { return [ { id: 'split-right', name: 'Split view to the right', description: 'Split the active tile vertically', checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.splitRight(), }, { id: 'split-down', name: 'Split view down', description: 'Split the active tile horizontally', checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.splitDown(), }, { id: 'new-tab', name: 'New tab', description: 'Open a new tab in the active tile', hotkeys: [{ modifiers: ['Mod'], key: 't' }], checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.newTab(), }, { id: 'close-tab', name: 'Close tab', description: 'Close the active tab in the active tile', // Mod+W is reserved by the native window menu (Close Window), so the // default binding is left to the command palette / tab close button. checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.closeActiveTab(), }, { id: 'next-tab', name: 'Next tab', description: 'Activate the next tab in the active tile', hotkeys: [{ modifiers: ['Mod', 'Alt'], key: 'ArrowRight' }], checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.nextTab(), }, { id: 'prev-tab', name: 'Previous tab', description: 'Activate the previous tab in the active tile', hotkeys: [{ modifiers: ['Mod', 'Alt'], key: 'ArrowLeft' }], checkAvailable: () => this.handleRef.current !== null, execute: () => this.handleRef.current?.prevTab(), }, ]; }}