diff --git a/packages/app-desktop/gui/NoteList/utils/useOnKeyDown.ts b/packages/app-desktop/gui/NoteList/utils/useOnKeyDown.ts index 3cb5767a6f..ec17c1764a 100644 --- a/packages/app-desktop/gui/NoteList/utils/useOnKeyDown.ts +++ b/packages/app-desktop/gui/NoteList/utils/useOnKeyDown.ts @@ -104,10 +104,17 @@ const useOnKeyDown = ( event.preventDefault(); } - if (noteIds.length && (key === 'Delete' || (key === 'Backspace' && event.metaKey))) { - event.preventDefault(); - if (CommandService.instance().isEnabled('deleteNote')) { - void CommandService.instance().execute('deleteNote', noteIds); + if (noteIds.length) { + if (key === 'Delete' && event.shiftKey) { + event.preventDefault(); + if (CommandService.instance().isEnabled('permanentlyDeleteNote')) { + void CommandService.instance().execute('permanentlyDeleteNote', noteIds); + } + } else if (key === 'Delete' || (key === 'Backspace' && event.metaKey)) { + event.preventDefault(); + if (CommandService.instance().isEnabled('deleteNote')) { + void CommandService.instance().execute('deleteNote', noteIds); + } } } diff --git a/packages/app-desktop/integration-tests/noteList.spec.ts b/packages/app-desktop/integration-tests/noteList.spec.ts index 01117ab7af..8eb0eb7886 100644 --- a/packages/app-desktop/integration-tests/noteList.spec.ts +++ b/packages/app-desktop/integration-tests/noteList.spec.ts @@ -1,5 +1,7 @@ import { test, expect } from './util/test'; import MainScreen from './models/MainScreen'; +import activateMainMenuItem from './util/activateMainMenuItem'; +import setMessageBoxResponse from './util/setMessageBoxResponse'; test.describe('noteList', () => { test('should be possible to edit notes in a different notebook when searching', async ({ mainWindow }) => { @@ -35,4 +37,42 @@ test.describe('noteList', () => { // Updating the title should force the sidebar to update sooner await expect(editor.noteTitleInput).toHaveValue('note-1'); }); + + test('shift-delete should ask to permanently delete notes, but only when the note list is focused', async ({ electronApp, mainWindow }) => { + const mainScreen = new MainScreen(mainWindow); + const sidebar = mainScreen.sidebar; + + const folderBHeader = await sidebar.createNewFolder('Folder B'); + const folderAHeader = await sidebar.createNewFolder('Folder A'); + await expect(folderAHeader).toBeVisible(); + + await mainScreen.createNewNote('test note 1'); + await mainScreen.createNewNote('test note 2'); + + await activateMainMenuItem(electronApp, 'Note list', 'Focus'); + await expect(mainScreen.noteListContainer.getByText('test note 1')).toBeVisible(); + + await setMessageBoxResponse(electronApp, /^Delete/i); + + const pressShiftDelete = async () => { + await mainWindow.keyboard.press('Shift'); + await mainWindow.keyboard.press('Delete'); + await mainWindow.keyboard.up('Delete'); + await mainWindow.keyboard.up('Shift'); + }; + await pressShiftDelete(); + + await folderBHeader.click(); + await folderAHeader.click(); + await expect(mainScreen.noteListContainer.getByText('test note 2')).not.toBeVisible(); + + // Should not delete when the editor is focused + await mainScreen.noteEditor.focusCodeMirrorEditor(); + await mainWindow.keyboard.type('test'); + await pressShiftDelete(); + + await folderBHeader.click(); + await folderAHeader.click(); + await expect(mainScreen.noteListContainer.getByText('test note 1')).toBeVisible(); + }); }); diff --git a/packages/lib/services/KeymapService.ts b/packages/lib/services/KeymapService.ts index fc8f95fa7a..3194e021a2 100644 --- a/packages/lib/services/KeymapService.ts +++ b/packages/lib/services/KeymapService.ts @@ -108,7 +108,6 @@ const defaultKeymapItems = { { accelerator: 'Ctrl+Alt+1', command: 'switchProfile1' }, { accelerator: 'Ctrl+Alt+2', command: 'switchProfile2' }, { accelerator: 'Ctrl+Alt+3', command: 'switchProfile3' }, - { accelerator: 'Shift+Delete', command: 'permanentlyDeleteNote' }, ], };