fix: move cmd+e to toggle organized

This commit is contained in:
Test
2026-04-10 12:08:17 +02:00
parent 2fabc2a1d7
commit b8983f16b2
12 changed files with 67 additions and 17 deletions

View File

@@ -22,6 +22,7 @@ export interface KeyboardActions {
onToggleRawEditor?: () => void
onToggleInspector?: () => void
onToggleFavorite?: (path: string) => void
onToggleOrganized?: (path: string) => void
onOpenInNewWindow?: () => void
activeTabPathRef: MutableRefObject<string | null>
}
@@ -77,7 +78,7 @@ export function createCommandKeyMap(actions: KeyboardActions): ShortcutMap {
s: actions.onSave,
',': actions.onOpenSettings,
d: withActiveTab(activeTabPathRef, (path) => actions.onToggleFavorite?.(path)),
e: withActiveTab(activeTabPathRef, actions.onArchiveNote),
e: withActiveTab(activeTabPathRef, (path) => actions.onToggleOrganized?.(path)),
Backspace: withActiveTab(activeTabPathRef, actions.onDeleteNote),
Delete: withActiveTab(activeTabPathRef, actions.onDeleteNote),
'[': () => actions.onGoBack?.(),

View File

@@ -45,7 +45,7 @@ export function buildNoteCommands(config: NoteCommandsConfig): CommandAction[] {
execute: () => { if (activeTabPath) onDeleteNote(activeTabPath) },
},
{
id: 'archive-note', label: isArchived ? 'Unarchive Note' : 'Archive Note', group: 'Note', shortcut: '⌘E',
id: 'archive-note', label: isArchived ? 'Unarchive Note' : 'Archive Note', group: 'Note',
keywords: ['archive'], enabled: hasActiveNote,
execute: () => { if (activeTabPath) (isArchived ? onUnarchiveNote : onArchiveNote)(activeTabPath) },
},
@@ -62,7 +62,7 @@ export function buildNoteCommands(config: NoteCommandsConfig): CommandAction[] {
execute: () => { if (activeTabPath) onToggleFavorite?.(activeTabPath) },
},
{
id: 'toggle-organized', label: isOrganized ? 'Mark as Unorganized' : 'Mark as Organized', group: 'Note',
id: 'toggle-organized', label: isOrganized ? 'Mark as Unorganized' : 'Mark as Organized', group: 'Note', shortcut: '⌘E',
keywords: ['organized', 'inbox', 'triage', 'done'],
enabled: hasActiveNote && !!onToggleOrganized,
execute: () => { if (activeTabPath) onToggleOrganized?.(activeTabPath) },

View File

@@ -115,6 +115,7 @@ export function useAppCommands(config: AppCommandsConfig): CommandAction[] {
onToggleRawEditor: config.onToggleRawEditor,
onToggleInspector: config.onToggleInspector,
onToggleFavorite: config.onToggleFavorite,
onToggleOrganized: config.onToggleOrganized,
onOpenInNewWindow: config.onOpenInNewWindow,
activeTabPathRef: config.activeTabPathRef,
})
@@ -138,6 +139,7 @@ export function useAppCommands(config: AppCommandsConfig): CommandAction[] {
onToggleRawEditor: config.onToggleRawEditor,
onToggleDiff: config.onToggleDiff,
onToggleAIChat: config.onToggleAIChat,
onToggleOrganized: config.onToggleOrganized,
onGoBack: config.onGoBack,
onGoForward: config.onGoForward,
onCheckForUpdates: config.onCheckForUpdates,

View File

@@ -38,6 +38,7 @@ function makeActions() {
onOpenSettings: vi.fn(),
onDeleteNote: vi.fn(),
onArchiveNote: vi.fn(),
onToggleOrganized: vi.fn(),
onSetViewMode: vi.fn(),
onZoomIn: vi.fn(),
onZoomOut: vi.fn(),
@@ -99,6 +100,14 @@ describe('useAppKeyboard', () => {
expect(actions.onToggleFavorite).toHaveBeenCalledWith('/vault/test.md')
})
it('Cmd+E triggers toggle organized on active note, not archive', () => {
const actions = makeActions()
renderHook(() => useAppKeyboard(actions))
fireKey('e', { metaKey: true })
expect(actions.onToggleOrganized).toHaveBeenCalledWith('/vault/test.md')
expect(actions.onArchiveNote).not.toHaveBeenCalled()
})
it('Cmd+J triggers open daily note', () => {
const actions = makeActions()
renderHook(() => useAppKeyboard(actions))

View File

@@ -16,6 +16,7 @@ function makeConfig(overrides: Record<string, unknown> = {}) {
onDeleteNote: vi.fn(),
onArchiveNote: vi.fn(),
onUnarchiveNote: vi.fn(),
onToggleOrganized: vi.fn(),
onCommitPush: vi.fn(),
onResolveConflicts: vi.fn(),
onSetViewMode: vi.fn(),
@@ -192,6 +193,13 @@ describe('useCommandRegistry', () => {
const cmd = findCommand(result.current, 'customize-inbox-columns')
expect(cmd!.enabled).toBe(false)
})
it('shows Cmd+E on toggle organized and removes it from archive note', () => {
const config = makeConfig()
const { result } = renderHook(() => useCommandRegistry(config))
expect(findCommand(result.current, 'toggle-organized')?.shortcut).toBe('⌘E')
expect(findCommand(result.current, 'archive-note')?.shortcut).toBeUndefined()
})
})
describe('pluralizeType', () => {

View File

@@ -15,6 +15,7 @@ function makeHandlers(): MenuEventHandlers {
onZoomIn: vi.fn(),
onZoomOut: vi.fn(),
onZoomReset: vi.fn(),
onToggleOrganized: vi.fn(),
onArchiveNote: vi.fn(),
onDeleteNote: vi.fn(),
onSearch: vi.fn(),
@@ -143,6 +144,19 @@ describe('dispatchMenuEvent', () => {
expect(h.onArchiveNote).not.toHaveBeenCalled()
})
it('note-toggle-organized triggers organized toggle on active tab', () => {
const h = makeHandlers()
dispatchMenuEvent('note-toggle-organized', h)
expect(h.onToggleOrganized).toHaveBeenCalledWith('/vault/test.md')
})
it('note-toggle-organized does nothing when no active tab', () => {
const h = makeHandlers()
h.activeTabPathRef = { current: null }
dispatchMenuEvent('note-toggle-organized', h)
expect(h.onToggleOrganized).not.toHaveBeenCalled()
})
it('note-delete triggers delete on active tab', () => {
const h = makeHandlers()
dispatchMenuEvent('note-delete', h)

View File

@@ -16,6 +16,7 @@ export interface MenuEventHandlers {
onZoomIn: () => void
onZoomOut: () => void
onZoomReset: () => void
onToggleOrganized?: (path: string) => void
onArchiveNote: (path: string) => void
onDeleteNote: (path: string) => void
onSearch: () => void
@@ -106,7 +107,8 @@ const OPTIONAL_EVENT_MAP: Record<string, OptionalHandler> = {
function dispatchActiveTabEvent(id: string, h: MenuEventHandlers): boolean {
const path = h.activeTabPathRef.current
if (!path) return id === 'note-archive' || id === 'note-delete'
if (!path) return id === 'note-toggle-organized' || id === 'note-archive' || id === 'note-delete'
if (id === 'note-toggle-organized') { h.onToggleOrganized?.(path); return true }
if (id === 'note-archive') { h.onArchiveNote(path); return true }
if (id === 'note-delete') { h.onDeleteNote(path); return true }
return false