1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Desktop: Fixes #10685: Fix shift-delete asks to permanently delete the current note, rather than cut text, when the editor is selected. (#10687)

This commit is contained in:
Henry Heino 2024-07-06 03:05:35 -07:00 committed by GitHub
parent a3e04103de
commit 2fd6a3a2fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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();
});
});

View File

@ -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' },
],
};