Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Add shortcut to delete newly created note quickly (#2177)
Abitofevrything3d9260c974c4
diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.jsindex b60888365e..dff5497cf9 100644--- a/src/public/app/services/entrypoints.js+++ b/src/public/app/services/entrypoints.js@@ -80,7 +80,7 @@ export default class Entrypoints extends Component {await appContext.tabManager.openContextWithNote(note.noteId, true, null, hoistedNoteId);- appContext.triggerEvent('focusAndSelectTitle');+ appContext.triggerEvent('focusAndSelectTitle', {isNewNote: true});}async toggleNoteHoistingCommand() {diff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.jsindex 641b5e3776..778cf237db 100644--- a/src/public/app/services/note_create.js+++ b/src/public/app/services/note_create.js@@ -52,7 +52,7 @@ async function createNote(parentNotePath, options = {}) {await activeNoteContext.setNote(`${parentNotePath}/${note.noteId}`);if (options.focus === 'title') {- appContext.triggerEvent('focusAndSelectTitle');+ appContext.triggerEvent('focusAndSelectTitle', {isNewNote: true});}else if (options.focus === 'content') {appContext.triggerEvent('focusOnDetail', {ntxId: activeNoteContext.ntxId});diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.jsindex 4003b79420..71cf0db423 100644--- a/src/public/app/widgets/note_title.js+++ b/src/public/app/widgets/note_title.js@@ -4,6 +4,7 @@ import protectedSessionHolder from "../services/protected_session_holder.js";import server from "../services/server.js";import SpacedUpdate from "../services/spaced_update.js";import appContext from "../services/app_context.js";+import branchService from "../services/branches.js";const TPL = `<div class="note-title-widget">@@ -40,6 +41,8 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {await server.put(`notes/${this.noteId}/change-title`, {title}, this.componentId);});+ this.deleteNoteOnEscape = false;+appContext.addBeforeUnloadListener(this);}@@ -49,6 +52,14 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate());+ this.$noteTitle.on('blur', () => { this.deleteNoteOnEscape = false });++ utils.bindElShortcut(this.$noteTitle, 'esc', () => {+ if (this.deleteNoteOnEscape && this.noteContext.isActive()) {+ branchService.deleteNotes(Object.values(this.noteContext.note.parentToBranch));+ }+ });+utils.bindElShortcut(this.$noteTitle, 'return', () => {this.triggerCommand('focusOnAttributes', {ntxId: this.noteContext.ntxId});});@@ -84,11 +95,13 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {}}- focusAndSelectTitleEvent() {+ focusAndSelectTitleEvent({isNewNote} = {isNewNote: false}) {if (this.noteContext && this.noteContext.isActive()) {this.$noteTitle.trigger('focus').trigger('select');++ this.deleteNoteOnEscape = isNewNote;}}