Desktop: Delete note using keyboard

pull/1157/head
Laurent Cozic 2019-01-26 15:15:16 +00:00
parent 998bdf3b56
commit ed541dac3b
1 changed files with 15 additions and 5 deletions

View File

@ -176,14 +176,19 @@ class NoteListComponent extends React.Component {
} }
menu.append(new MenuItem({label: _('Delete'), click: async () => { menu.append(new MenuItem({label: _('Delete'), click: async () => {
const ok = bridge().showConfirmMessageBox(noteIds.length > 1 ? _('Delete notes?') : _('Delete note?')); await this.confirmDeleteNotes(noteIds);
if (!ok) return;
await Note.batchDelete(noteIds);
}})); }}));
menu.popup(bridge().window()); menu.popup(bridge().window());
} }
async confirmDeleteNotes(noteIds) {
if (!noteIds.length) return;
const ok = bridge().showConfirmMessageBox(noteIds.length > 1 ? _('Delete notes?') : _('Delete note?'));
if (!ok) return;
await Note.batchDelete(noteIds);
}
itemRenderer(item) { itemRenderer(item) {
const theme = themeStyle(this.props.theme); const theme = themeStyle(this.props.theme);
const width = this.props.style.width; const width = this.props.style.width;
@ -337,7 +342,7 @@ class NoteListComponent extends React.Component {
return null; return null;
} }
onKeyDown(event) { async onKeyDown(event) {
const keyCode = event.keyCode; const keyCode = event.keyCode;
const noteIds = this.props.selectedNoteIds; const noteIds = this.props.selectedNoteIds;
@ -379,6 +384,11 @@ class NoteListComponent extends React.Component {
event.preventDefault(); event.preventDefault();
} }
if (noteIds.length && keyCode === 46) { // DELETE
event.preventDefault();
await this.confirmDeleteNotes(noteIds);
}
} }
componentWillUnmount() { componentWillUnmount() {