Skip to content

Build your personal knowledge base with Trilium Notes

fix setting path

zadam9f4a5145629a
diff --git a/src/public/javascripts/services/spaced_update.js b/src/public/javascripts/services/spaced_update.js
index ed67f8a2b9..e12aef32ce 100644
--- a/src/public/javascripts/services/spaced_update.js
+++ b/src/public/javascripts/services/spaced_update.js
@@ -36,11 +36,11 @@ export default class SpacedUpdate {
}
}
- allowUpdateWithoutChange(callback) {
+ async allowUpdateWithoutChange(callback) {
this.changeForbidden = true;
try {
- callback();
+ await callback();
}
finally {
this.changeForbidden = false;
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 5a8ef60b5f..e65eabb126 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -69,8 +69,6 @@ class TabContext extends Component {
tabId: this.tabId,
notePath: this.notePath
});
-
- this.trigger('openTabsChanged');
}
/** @property {NoteShort} */
@@ -99,14 +97,10 @@ class TabContext extends Component {
return {
tabId: this.tabId,
notePath: this.notePath,
- active: this.tabManager.activeTabId === this.tabId
+ active: this.isActive()
}
}
- stateChanged() {
- appContext.openTabsChangedListener();
- }
-
noteDeletedListener({noteId}) {
if (this.noteId === noteId) {
this.noteId = null;
diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js
index 2f38e07a89..b866deae7d 100644
--- a/src/public/javascripts/services/tab_manager.js
+++ b/src/public/javascripts/services/tab_manager.js
@@ -83,10 +83,10 @@ export default class TabManager extends Component {
filteredTabs[0].active = true;
}
- this.tabsUpdate.allowUpdateWithoutChange(() => {
+ await this.tabsUpdate.allowUpdateWithoutChange(async () => {
for (const tab of filteredTabs) {
const tabContext = this.openEmptyTab();
- tabContext.setNote(tab.notePath);
+ await tabContext.setNote(tab.notePath);
if (tab.active) {
this.activateTab(tabContext.tabId);
@@ -97,11 +97,13 @@ export default class TabManager extends Component {
tabNoteSwitchedListener({tabId}) {
if (tabId === this.activeTabId) {
- this._setCurrentNotePathToHash();
+ this.setCurrentNotePathToHash();
}
+
+ this.tabsUpdate.scheduleUpdate();
}
- _setCurrentNotePathToHash() {
+ setCurrentNotePathToHash() {
const activeTabContext = this.getActiveTabContext();
if (activeTabContext && activeTabContext.notePath) {
@@ -185,10 +187,6 @@ export default class TabManager extends Component {
await tabContext.setNote(noteId);
}
- openTabsChangedListener() {
- this.tabsUpdate.scheduleUpdate();
- }
-
activateTab(tabId) {
if (tabId === this.activeTabId) {
return;
@@ -199,6 +197,10 @@ export default class TabManager extends Component {
this.activeTabId = tabId;
this.trigger('activeTabChanged', { oldActiveTabId, newActiveTabId: tabId });
+
+ this.tabsUpdate.scheduleUpdate();
+
+ this.setCurrentNotePathToHash();
}
async removeTab(tabId) {
@@ -221,7 +223,7 @@ export default class TabManager extends Component {
this.trigger('tabRemoved', {tabId});
- this.openTabsChangedListener();
+ this.tabsUpdate.scheduleUpdate();
}
tabReorderListener({tabIdsInOrder}) {
@@ -233,7 +235,7 @@ export default class TabManager extends Component {
this.tabContexts.sort((a, b) => order[a.tabId] < order[b.tabId] ? -1 : 1);
- this.openTabsChangedListener();
+ this.tabsUpdate.scheduleUpdate();
}
activateNextTabListener() {
diff --git a/src/public/javascripts/services/ws.js b/src/public/javascripts/services/ws.js
index 8e7d146937..c2ba50234a 100644
--- a/src/public/javascripts/services/ws.js
+++ b/src/public/javascripts/services/ws.js
@@ -5,6 +5,7 @@ import LoadResults from "./load_results.js";
import Branch from "../entities/branch.js";
import Attribute from "../entities/attribute.js";
import options from "./options.js";
+import treeCache from "./tree_cache.js";
const $outstandingSyncsCount = $("#outstanding-syncs-count");
@@ -203,7 +204,7 @@ async function processSyncRows(syncRows) {
const loadResults = new LoadResults(this);
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => {
- const note = this.notes[sync.entityId];
+ const note = treeCache.notes[sync.entityId];
if (note) {
note.update(sync.entity);
@@ -212,9 +213,9 @@ async function processSyncRows(syncRows) {
});
syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
- let branch = this.branches[sync.entityId];
- const childNote = this.notes[sync.entity.noteId];
- const parentNote = this.notes[sync.entity.parentNoteId];
+ let branch = treeCache.branches[sync.entityId];
+ const childNote = treeCache.notes[sync.entity.noteId];
+ const parentNote = treeCache.notes[sync.entity.parentNoteId];
if (branch) {
if (sync.entity.isDeleted) {
@@ -244,7 +245,7 @@ async function processSyncRows(syncRows) {
else if (!sync.entity.isDeleted) {
if (childNote || parentNote) {
branch = new Branch(this, sync.entity);
- this.branches[branch.branchId] = branch;
+ treeCache.branches[branch.branchId] = branch;
loadResults.addBranch(sync.entityId, sync.sourceId);
@@ -261,7 +262,7 @@ async function processSyncRows(syncRows) {
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => {
for (const branchId in sync.positions) {
- const branch = this.branches[branchId];
+ const branch = treeCache.branches[branchId];
if (branch) {
branch.notePosition = sync.positions[branchId];
@@ -273,9 +274,9 @@ async function processSyncRows(syncRows) {
// missing reloading the relation target note
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => {
- let attribute = this.attributes[sync.entityId];
- const sourceNote = this.notes[sync.entity.noteId];
- const targetNote = sync.entity.type === 'relation' && this.notes[sync.entity.value];
+ let attribute = treeCache.attributes[sync.entityId];
+ const sourceNote = treeCache.notes[sync.entity.noteId];
+ const targetNote = sync.entity.type === 'relation' && treeCache.notes[sync.entity.value];
if (attribute) {
attribute.update(sync.entity);
@@ -295,7 +296,7 @@ async function processSyncRows(syncRows) {
if (sourceNote || targetNote) {
attribute = new Attribute(this, sync.entity);
- this.attributes[attribute.attributeId] = attribute;
+ treeCache.attributes[attribute.attributeId] = attribute;
loadResults.addAttribute(sync.entityId, sync.sourceId);
@@ -311,7 +312,7 @@ async function processSyncRows(syncRows) {
});
syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => {
- delete this.noteComplementPromises[sync.entityId];
+ delete treeCache.noteComplementPromises[sync.entityId];
loadResults.addNoteContent(sync.entityId, sync.sourceId);
});