Skip to content

Commit e65bae5

Browse files
committed
Feat(sidebar): the Delete key moves the sidebar's note to the Trash (#1040)
Mod+Backspace and Vim's `x` were the only keys that did this, and neither is what someone on Windows or Linux reaches for first. A bare Delete now does the same, in either mode: one confirm, or one confirm for the whole selection when the row is part of it. Held down, it still asks about one note. Vim mode off is fine here because it never acts without asking, the same call as Delete on database rows. Unbinding Move sidebar note to Trash means no key trashes from here, so it takes Delete with it. Delete with a modifier is left alone, and in the editor Delete still deletes a character.
1 parent 6df37d1 commit e65bae5

4 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎packages/app-core/src/lib/help.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const HELP_HOW_TO_GUIDES: HelpCard[] = [
204204
{
205205
title: 'Trash notes from the sidebar',
206206
body:
207-
'With the sidebar focused, `Mod+Backspace` (⌘⌫ on macOS, Ctrl+Backspace on Windows and Linux) moves the note under the sidebar cursor to the Trash, after the same confirm Move Note to Trash shows; in Vim mode `x` does the same. When that note is part of a multi-selection, the whole selection goes, with one confirm (“Move 3 notes to Trash?”). Escape on the confirm leaves everything as it was, and after the move the cursor sits on the row that took the note’s place, still in the sidebar. A folder is not trashed this way, since deleting a folder takes everything inside and cannot be undone: delete it from its menu (`m`, or right-click). The palette’s Move Note to Trash and Move Note to Archive, and any key you gave them, follow the sidebar the same way: with the sidebar focused and its cursor on a note, they act on that note (or the selection it is in) rather than the note open in the editor. Rebind the chord as Move sidebar note to Trash (`nav.sidebarTrash`) under Settings → Keymap, or unbind it; `x` is Delete selected result (`nav.delete`).'
207+
'With the sidebar focused, `Mod+Backspace` (⌘⌫ on macOS, Ctrl+Backspace on Windows and Linux) moves the note under the sidebar cursor to the Trash, after the same confirm Move Note to Trash shows; the Delete key does the same, and in Vim mode so does `x`. When that note is part of a multi-selection, the whole selection goes, with one confirm (“Move 3 notes to Trash?”). Escape on the confirm leaves everything as it was, and after the move the cursor sits on the row that took the note’s place, still in the sidebar. A folder is not trashed this way, since deleting a folder takes everything inside and cannot be undone: delete it from its menu (`m`, or right-click). The palette’s Move Note to Trash and Move Note to Archive, and any key you gave them, follow the sidebar the same way: with the sidebar focused and its cursor on a note, they act on that note (or the selection it is in) rather than the note open in the editor. Rebind the chord as Move sidebar note to Trash (`nav.sidebarTrash`) under Settings → Keymap, or unbind it; `x` is Delete selected result (`nav.delete`).'
208208
},
209209
{
210210
title: 'Ctrl, Alt and Cmd keys in list views',
@@ -784,7 +784,7 @@ export const HELP_SHORTCUT_SECTIONS: HelpShortcutSection[] = [
784784
{ keys: '/', action: 'Search notes', detail: 'Open note search directly from keyboard navigation mode.' },
785785
{ keys: 'm', action: 'Open context menu', detail: 'Open the right-click menu for the selected sidebar or note-list row, including move, archive, trash, floating-window, and reveal actions where they apply.' },
786786
{ keys: 'x', action: 'Move to Trash', detail: 'Move the note under the cursor to the Trash after a confirm, or the whole multi-selection when that note is part of it. The cursor stays in the sidebar, on the row that took the note’s place. Folders are left alone: delete one from its menu (`m`).' },
787-
{ keys: 'Mod+Backspace', action: 'Move to Trash, Vim on or off', detail: 'The same as `x`, with Vim mode on or off: ⌘⌫ on macOS, Ctrl+Backspace on Windows and Linux. Rebind or unbind it as Move sidebar note to Trash under Settings → Keymap.' },
787+
{ keys: 'Mod+Backspace / Delete', action: 'Move to Trash, Vim on or off', detail: 'The same as `x`, with Vim mode on or off: ⌘⌫ on macOS, Ctrl+Backspace on Windows and Linux, and the Delete key everywhere. Rebind the chord or unbind both as Move sidebar note to Trash under Settings → Keymap.' },
788788
{ keys: 'Esc', action: 'Return to editor', detail: 'Drop back into the main editor focus path.' }
789789
]
790790
},

‎packages/app-core/src/lib/keymaps.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ const KEYMAP_DEFINITIONS: KeymapDefinition[] = [
14771477
group: "view-actions",
14781478
title: "Move sidebar note to Trash",
14791479
description:
1480-
"With the sidebar focused, move the note under its cursor to the Trash after a confirm, or every selected note when the selection includes that row. Works with Vim mode on or off.",
1480+
"With the sidebar focused, move the note under its cursor to the Trash after a confirm, or every selected note when the selection includes that row. Works with Vim mode on or off. The Delete key does the same; unbinding this turns both off.",
14811481
defaultBinding: "Mod+Backspace",
14821482
},
14831483
{

‎packages/app-core/src/lib/sidebar-note-actions.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,33 @@ describe('the sidebar trash chord (#972)', () => {
271271
expect(run).toHaveBeenCalledTimes(1)
272272
})
273273

274+
it('takes a bare Delete in either mode, and not with a modifier (#1040)', async () => {
275+
const { handleSidebarTrashChord } = await load()
276+
const del = (init: KeyboardEventInit = {}): KeyboardEvent =>
277+
chord({ ...init, key: 'Delete', code: 'Delete' })
278+
for (const vimMode of [true, false]) {
279+
const run = vi.fn()
280+
const event = del()
281+
expect(handleSidebarTrashChord(event, () => ({ ...closedState, vimMode }), run)).toBe(true)
282+
expect(event.defaultPrevented).toBe(true)
283+
expect(run).toHaveBeenCalledTimes(1)
284+
// Held down, it still asks about one note only.
285+
expect(handleSidebarTrashChord(del({ repeat: true }), () => ({ ...closedState, vimMode }), run)).toBe(true)
286+
expect(run).toHaveBeenCalledTimes(1)
287+
}
288+
const run = vi.fn()
289+
expect(handleSidebarTrashChord(del({ shiftKey: true }), () => closedState, run)).toBe(false)
290+
expect(run).not.toHaveBeenCalled()
291+
})
292+
293+
it('lets Delete go with the chord when the chord is unbound (#1040)', async () => {
294+
const { handleSidebarTrashChord } = await load()
295+
const run = vi.fn()
296+
const state = { ...closedState, keymapOverrides: { 'nav.sidebarTrash': '' } }
297+
expect(handleSidebarTrashChord(chord({ key: 'Delete', code: 'Delete' }), () => state, run)).toBe(false)
298+
expect(run).not.toHaveBeenCalled()
299+
})
300+
274301
it('does nothing unless the sidebar holds the keyboard', async () => {
275302
const { handleSidebarTrashChord } = await load()
276303
const run = vi.fn()

‎packages/app-core/src/lib/sidebar-note-actions.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ import { useStore } from '../store'
3333
import { runNoteBatchAction, runNoteLifecycleAction } from './note-lifecycle-actions'
3434
import { resolveSystemFolderLabels } from './system-folder-labels'
3535
import { useToastStore } from './toast'
36-
import { isChordEvent, matchesShortcut, type KeymapOverrides } from './keymaps'
36+
import {
37+
getKeymapBinding,
38+
isChordEvent,
39+
isUnboundBinding,
40+
matchesShortcut,
41+
type KeymapOverrides
42+
} from './keymaps'
3743
import { chordHeldByApp, listViewBindingMatches } from './list-view-keys'
3844
import { commandKeymapsStandDown } from './command-keymap-dispatch'
3945

@@ -283,14 +289,20 @@ export async function trashSidebarCursorRow(): Promise<boolean> {
283289
/* ------------------------------------------------------------------------ */
284290

285291
/** Whether the keydown is one of the sidebar's trash keys: Mod+Backspace
286-
* (or what it was rebound to) in either mode, and `x` (nav.delete) with Vim
287-
* on, or in either mode when it was rebound to a chord. */
292+
* (or what it was rebound to) and a bare Delete in either mode, and `x`
293+
* (nav.delete) with Vim on, or in either mode when it was rebound to a chord.
294+
* Delete is the key a Windows or Linux user reaches for (#1040); it always
295+
* asks first, so it is safe with Vim off. Unbinding the chord says "no key
296+
* trashes from here", so it takes Delete with it. */
288297
export function isSidebarTrashKey(
289298
event: KeyboardEvent,
290299
overrides: KeymapOverrides | null | undefined,
291300
vimMode: boolean
292301
): boolean {
302+
const bareDelete =
303+
event.key === 'Delete' && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey
293304
return (
305+
(bareDelete && !isUnboundBinding(getKeymapBinding(overrides, 'nav.sidebarTrash'))) ||
294306
matchesShortcut(event, overrides, 'nav.sidebarTrash') ||
295307
listViewBindingMatches(event, overrides, 'nav.delete', vimMode)
296308
)

0 commit comments

Comments
 (0)