Skip to content

Build your personal knowledge base with Trilium Notes

fixed double refresh of note detail

zadamb2a3e1cc048f
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 2089642ec4..bf3079613d 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -17,7 +17,7 @@ class TabContext extends Component {
this.tabId = tabId || utils.randomString(4);
}
- async setNote(inputNotePath) {
+ async setNote(inputNotePath, triggerSwitchEvent = true) {
const notePath = await treeService.resolveNotePath(inputNotePath);
if (!notePath) {
@@ -59,10 +59,12 @@ class TabContext extends Component {
protectedSessionHolder.touchProtectedSession();
}
- this.triggerEvent('tabNoteSwitched', {
- tabId: this.tabId,
- notePath: this.notePath
- });
+ if (triggerSwitchEvent) {
+ this.triggerEvent('tabNoteSwitched', {
+ tabId: this.tabId,
+ notePath: this.notePath
+ });
+ }
}
/** @property {NoteShort} */
diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js
index 771d36d577..da21c92a0a 100644
--- a/src/public/javascripts/services/tab_manager.js
+++ b/src/public/javascripts/services/tab_manager.js
@@ -88,13 +88,7 @@ export default class TabManager extends Component {
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
for (const tab of filteredTabs) {
- const tabContext = this.openEmptyTab(tab.tabId);
-
- if (tab.active) {
- this.activateTab(tabContext.tabId);
- }
-
- await tabContext.setNote(tab.notePath);
+ await this.openTabWithNote(tab.notePath, tab.active, tab.tabId);
}
});
}
@@ -185,11 +179,23 @@ export default class TabManager extends Component {
const tabContext = new TabContext(tabId);
this.child(tabContext);
- this.triggerEvent('newTabOpened', {tabId: this.tabId})
+ this.triggerEvent('newTabOpened', {tabId: this.tabId});
return tabContext;
}
+ async openTabWithNote(notePath, activate, tabId = null) {
+ const tabContext = this.openEmptyTab(tabId);
+
+ await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
+
+ if (activate) {
+ this.activateTab(tabContext.tabId, false);
+
+ this.triggerEvent('tabNoteSwitchedAndActivated');
+ }
+ }
+
async activateOrOpenNote(noteId) {
for (const tabContext of this.getTabContexts()) {
if (tabContext.note && tabContext.note.noteId === noteId) {
@@ -204,14 +210,16 @@ export default class TabManager extends Component {
await tabContext.setNote(noteId);
}
- activateTab(tabId) {
+ activateTab(tabId, triggerEvent = true) {
if (tabId === this.activeTabId) {
return;
}
this.activeTabId = tabId;
- this.triggerEvent('activeTabChanged');
+ if (triggerEvent) {
+ this.triggerEvent('activeTabChanged');
+ }
this.tabsUpdate.scheduleUpdate();
diff --git a/src/public/javascripts/widgets/layout.js b/src/public/javascripts/widgets/layout.js
index 8480bdcfe2..45820c1a5b 100644
--- a/src/public/javascripts/widgets/layout.js
+++ b/src/public/javascripts/widgets/layout.js
@@ -28,7 +28,9 @@ import SidePaneToggles from "./side_pane_toggles.js";
export default class Layout {
getRootWidget(appContext) {
- const root = new FlexContainer('column').id('root-widget')
+ return new FlexContainer('column')
+ .setParent(appContext)
+ .id('root-widget')
.child(new FlexContainer('row')
.child(new GlobalMenuWidget())
.child(new TabRowWidget())
@@ -65,9 +67,5 @@ export default class Layout {
)
.child(new SidePaneToggles())
);
-
- root.setParent(appContext);
-
- return root;
}
}
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js
index b2e12de042..9e7754c414 100644
--- a/src/public/javascripts/widgets/note_detail.js
+++ b/src/public/javascripts/widgets/note_detail.js
@@ -236,13 +236,6 @@ export default class NoteDetailWidget extends TabAwareWidget {
this.refresh();
}
- async handleEventInChildren(name, data) {
- // done manually in refresh()
- if (name !== 'setTabContext') {
- await super.handleEventInChildren(name, data);
- }
- }
-
async cutIntoNoteCommand() {
const note = appContext.tabManager.getActiveTabNote();
diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js
index df94d0115f..4435fad56a 100644
--- a/src/public/javascripts/widgets/tab_aware_widget.js
+++ b/src/public/javascripts/widgets/tab_aware_widget.js
@@ -5,8 +5,6 @@ export default class TabAwareWidget extends BasicWidget {
setTabContextEvent({tabContext}) {
/** @var {TabContext} */
this.tabContext = tabContext;
-
- this.noteSwitched();
}
isTab(tabId) {
@@ -80,6 +78,13 @@ export default class TabAwareWidget extends BasicWidget {
this.activeTabChanged();
}
+ // when note is both switched and activated, this should not produce double refresh
+ tabNoteSwitchedAndActivatedEvent() {
+ this.tabContext = appContext.tabManager.getActiveTabContext();
+
+ this.refresh();
+ }
+
treeCacheReloadedEvent() {
this.refresh();
}
diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js
index eb587d7f4f..ad69798ae3 100644
--- a/src/public/javascripts/widgets/tab_caching_widget.js
+++ b/src/public/javascripts/widgets/tab_caching_widget.js
@@ -39,8 +39,8 @@ export default class TabCachingWidget extends TabAwareWidget {
let widget = this.widgets[this.tabContext.tabId];
if (!widget) {
- widget = this.widgets[this.tabContext.tabId] = this.widgetFactory(this);
- this.children.push(widget);
+ widget = this.widgets[this.tabContext.tabId] = this.widgetFactory();
+ this.child(widget);
const $renderedWidget = widget.render();
keyboardActionsService.updateDisplayedShortcuts($renderedWidget);