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
reduce flicker of "create new day note"
zadam6bbd4c59bc36
diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.jsindex 3e421e247b..c31505350c 100644--- a/src/public/javascripts/services/entrypoints.js+++ b/src/public/javascripts/services/entrypoints.js@@ -220,17 +220,17 @@ function registerEntrypoints() {}));keyboardActionService.setGlobalActionHandler("CreateNoteIntoDayNote", async () => {- const todayNote = await dateNoteService.getTodayNote();console.log(todayNote);+ const todayNote = await dateNoteService.getTodayNote();const notePath = await treeService.getSomeNotePath(todayNote);const node = await treeService.expandToNote(notePath);- await noteDetailService.openEmptyTab(false);-- await treeService.createNote(node, todayNote.noteId, 'into', {+ const {note} = await treeService.createNote(node, todayNote.noteId, 'into', {type: "text",isProtected: node.data.isProtected});++ await noteDetailService.openInTab(note.noteId, true);});keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => {diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.jsindex 5e54991181..5aeee022c4 100644--- a/src/public/javascripts/services/keyboard_actions.js+++ b/src/public/javascripts/services/keyboard_actions.js@@ -1,35 +1,11 @@import server from "./server.js";import utils from "./utils.js";-class KeyboardAction {- constructor(params) {- /** @property {string} */- this.actionName = params.actionName;- /** @property {string[]} */- this.defaultShortcuts = params.defaultShortcuts;- /** @property {string[]} */- this.effectiveShortcuts = params.effectiveShortcuts;- /** @property {string} */- this.description = params.description;- }-- addShortcut(shortcut) {- this.effectiveShortcuts.push(shortcut);- }-- /**- * @param {string|string[]} shortcuts- */- replaceShortcuts(shortcuts) {- this.effectiveShortcuts = Array.isArray(shortcuts) ? shortcuts : [shortcuts];- }-}-const keyboardActionRepo = {};const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {for (const action of actions) {- keyboardActionRepo[action.actionName] = new KeyboardAction(action);+ keyboardActionRepo[action.actionName] = action;}});@@ -54,7 +30,7 @@ function setGlobalActionHandler(actionName, handler) {action.handler = handler;for (const shortcut of action.effectiveShortcuts) {- if (shortcut) {+ if (shortcut && !shortcut.startsWith("global:")) { // global shortcuts should be handled in the electron codeutils.bindGlobalShortcut(shortcut, handler);}}@@ -80,7 +56,7 @@ function setElementActionHandler($el, actionName, handler) {}async function triggerAction(actionName) {- const action = getAction(actionName);+ const action = await getAction(actionName);if (!action.handler) {throw new Error(`Action ${actionName} has no handler`);diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.jsindex eb1b2ffc4e..0cb4f2714d 100644--- a/src/public/javascripts/services/link.js+++ b/src/public/javascripts/services/link.js@@ -72,7 +72,7 @@ function goToLink(e) {if (notePath) {if ((e.which === 1 && e.ctrlKey) || e.which === 2) {- noteDetailService.openInTab(notePath);+ noteDetailService.openInTab(notePath, false);}else if (e.which === 1) {treeService.activateNote(notePath);diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex 7a65b982d3..b74d031346 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -35,8 +35,8 @@ async function reloadAllTabs() {}}-async function openInTab(notePath) {- await loadNoteDetail(notePath, { newTab: true });+async function openInTab(notePath, activate) {+ await loadNoteDetail(notePath, { newTab: true, activate });}async function switchToNote(notePath) {diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.jsindex dfc692e93e..61af483c00 100644--- a/src/public/javascripts/services/note_detail_relation_map.js+++ b/src/public/javascripts/services/note_detail_relation_map.js@@ -159,7 +159,7 @@ class NoteDetailRelationMap {const noteId = this.idToNoteId($noteBox.prop("id"));if (cmd === "open-in-new-tab") {- noteDetailService.openInTab(noteId);+ noteDetailService.openInTab(noteId, false);}else if (cmd === "remove") {const confirmDialog = await import('../dialogs/confirm.js');diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex 58fbf25690..fad10a435e 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -626,6 +626,8 @@ async function createNewTopLevelNote() {async function createNote(node, parentNoteId, target, extraOptions = {}) {utils.assertArguments(node, parentNoteId, target);+ extraOptions.activate = extraOptions.activate === undefined ? true : !!extraOptions.activate;+// if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted// but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur oftenif (!extraOptions.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) {@@ -667,7 +669,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {const noteEntity = await treeCache.getNote(note.noteId);const branchEntity = treeCache.getBranch(branch.branchId);- let newNode = {+ let newNodeData = {title: newNoteName,noteId: branchEntity.noteId,parentNoteId: parentNoteId,@@ -682,8 +684,11 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {key: utils.randomString(12) // this should prevent some "duplicate key" errors};+ /** @var {FancytreeNode} */+ let newNode;+if (target === 'after') {- await node.appendSibling(newNode).setActive(true);+ newNode = node.appendSibling(newNodeData);}else if (target === 'into') {if (!node.getChildren() && node.isFolder()) {@@ -693,10 +698,10 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {await node.setExpanded();}else {- node.addChildren(newNode);+ node.addChildren(newNodeData);}- await node.getLastChild().setActive(true);+ newNode = node.getLastChild();const parentNoteEntity = await treeCache.getNote(node.data.noteId);@@ -708,14 +713,18 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {toastService.throwError("Unrecognized target: " + target);}+ if (extraOptions.activate) {+ await newNode.setActive(true);+ }+clearSelectedNodes(); // to unmark previously active node// need to refresh because original doesn't have methods like .getParent()- newNode = getNodesByNoteId(branchEntity.noteId)[0];+ newNodeData = getNodesByNoteId(branchEntity.noteId)[0];// following for cycle will make sure that also clones of a parent are refreshedfor (const newParentNode of getNodesByNoteId(parentNoteId)) {- if (newParentNode.key === newNode.getParent().key) {+ if (newParentNode.key === newNodeData.getParent().key) {// we've added a note into this one so no need to refreshcontinue;}@@ -887,7 +896,7 @@ $tree.on('mousedown', '.fancytree-title', e => {treeUtils.getNotePath(node).then(notePath => {if (notePath) {- noteDetailService.openInTab(notePath);+ noteDetailService.openInTab(notePath, false);}});diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.jsindex 6cdc257d6b..b10f5da056 100644--- a/src/public/javascripts/services/tree_context_menu.js+++ b/src/public/javascripts/services/tree_context_menu.js@@ -97,7 +97,7 @@ class TreeContextMenu {if (cmd === 'openInTab') {const notePath = await treeUtils.getNotePath(this.node);- noteDetailService.openInTab(notePath);+ noteDetailService.openInTab(notePath, false);}else if (cmd.startsWith("insertNoteAfter")) {const parentNoteId = this.node.data.parentNoteId;diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.jsindex 77c62d41fe..e66c161ae1 100644--- a/src/services/keyboard_actions.js+++ b/src/services/keyboard_actions.js@@ -48,14 +48,10 @@ const DEFAULT_KEYBOARD_ACTIONS = [defaultShortcuts: ["Alt+-"],description: "Collapses subtree of current note"},- {- actionName: "FocusNote",- defaultShortcuts: ["Enter"]- },{actionName: "ActivateParentNote",defaultShortcuts: ["Backspace"],- description: "Activates parent note of currently active note"+ description: "Activates the parent note of currently active note"},{actionName: "SortChildNotes",