mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
reduce flicker of "create new day note"
This commit is contained in:
parent
3a54d00e2b
commit
6bbd4c59bc
@ -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 () => {
|
||||
|
@ -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 code
|
||||
utils.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`);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
|
@ -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 often
|
||||
if (!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 refreshed
|
||||
for (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 refresh
|
||||
continue;
|
||||
}
|
||||
@ -887,7 +896,7 @@ $tree.on('mousedown', '.fancytree-title', e => {
|
||||
|
||||
treeUtils.getNotePath(node).then(notePath => {
|
||||
if (notePath) {
|
||||
noteDetailService.openInTab(notePath);
|
||||
noteDetailService.openInTab(notePath, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user