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
event fixes
zadam8909d175d001
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex da0e7c7d0e..2974597214 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -19,7 +19,7 @@ class TabContext extends Component {setEmpty() {this.triggerEvent('tabNoteSwitched', {- tabId: this.tabId,+ tabContext: this,notePath: this.notePath});}@@ -66,7 +66,7 @@ class TabContext extends Component {if (triggerSwitchEvent) {this.triggerEvent('tabNoteSwitched', {- tabId: this.tabId,+ tabContext: this,notePath: this.notePath});}@@ -111,7 +111,7 @@ class TabContext extends Component {this.notePath = null;this.triggerEvent('tabNoteSwitched', {- tabId: this.tabId,+ tabContext: this,notePath: this.notePath});}diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.jsindex 1a63abeba0..fac7805f51 100644--- a/src/public/javascripts/services/tab_manager.js+++ b/src/public/javascripts/services/tab_manager.js@@ -93,8 +93,8 @@ export default class TabManager extends Component {});}- tabNoteSwitchedEvent({tabId}) {- if (tabId === this.activeTabId) {+ tabNoteSwitchedEvent({tabContext}) {+ if (tabContext.isActive()) {this.setCurrentNotePathToHash();}@@ -195,7 +195,7 @@ export default class TabManager extends Component {this.activateTab(tabContext.tabId, false);this.triggerEvent('tabNoteSwitchedAndActivated', {- tabId: tabContext.tabId,+ tabContext,notePath});}@@ -222,7 +222,9 @@ export default class TabManager extends Component {this.activeTabId = tabId;if (triggerEvent) {- this.triggerEvent('activeTabChanged', {tabId});+ this.triggerEvent('activeTabChanged', {+ tabContext: this.getTabContextById(tabId)+ });}this.tabsUpdate.scheduleUpdate();diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.jsindex 5586e45014..d0feaf6472 100644--- a/src/public/javascripts/widgets/tab_aware_widget.js+++ b/src/public/javascripts/widgets/tab_aware_widget.js@@ -46,9 +46,9 @@ export default class TabAwareWidget extends BasicWidget {async refreshWithNote(note, notePath) {}- async tabNoteSwitchedEvent({tabId, notePath}) {+ async tabNoteSwitchedEvent({tabContext, notePath}) {// if notePath does not match then the tabContext has been switched to another note in the mean time- if (this.notePath === notePath) {+ if (tabContext.notePath === notePath) {await this.noteSwitched();}}@@ -57,8 +57,8 @@ export default class TabAwareWidget extends BasicWidget {await this.refresh();}- async activeTabChangedEvent({tabId}) {- this.tabContext = appContext.tabManager.getTabContextById(tabId);+ async activeTabChangedEvent({tabContext}) {+ this.tabContext = tabContext;await this.activeTabChanged();}@@ -68,8 +68,8 @@ export default class TabAwareWidget extends BasicWidget {}// when note is both switched and activated, this should not produce double refresh- async tabNoteSwitchedAndActivatedEvent({tabId, notePath}) {- this.tabContext = appContext.tabManager.getTabContextById(tabId);+ async tabNoteSwitchedAndActivatedEvent({tabContext, notePath}) {+ this.tabContext = tabContext;// if notePath does not match then the tabContext has been switched to another note in the mean timeif (this.notePath === notePath) {@@ -84,11 +84,6 @@ export default class TabAwareWidget extends BasicWidget {this.refresh();}- async newTabOpenedEvent({tabContext}) {- /** @var {TabContext} */- this.tabContext = tabContext;- }-async noteTypeMimeChangedEvent({noteId}) {if (this.isNote(noteId)) {await this.refresh();diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.jsindex 465cc629d9..bfda627a2f 100644--- a/src/public/javascripts/widgets/tab_caching_widget.js+++ b/src/public/javascripts/widgets/tab_caching_widget.js@@ -9,10 +9,6 @@ export default class TabCachingWidget extends TabAwareWidget {this.widgets = {};}- isEnabled() {- return !!this.tabContext;- }-doRender() {return this.$widget = $(`<div class="marker" style="display: none;">`);}@@ -31,8 +27,6 @@ export default class TabCachingWidget extends TabAwareWidget {}async newTabOpenedEvent({tabContext}) {- super.newTabOpenedEvent({tabContext});-const {tabId} = tabContext;if (this.widgets[tabId]) {@@ -48,29 +42,16 @@ export default class TabCachingWidget extends TabAwareWidget {keyboardActionsService.updateDisplayedShortcuts($renderedWidget);- await this.widgets[tabId].handleEvent('newTabOpened', {tabContext});+ await this.widgets[tabId].handleEvent('setTabContext', {tabContext});this.child(this.widgets[tabId]); // add as child only once it is ready (rendered with tabContext)}- async refreshWithNote() {- for (const widget of Object.values(this.widgets)) {- widget.toggleExt(false);- }-- if (!this.tabContext) {- console.log(`No tabContext in widget ${this.componentId}.`);-- return;- }-- const widget = this.widgets[this.tabContext.tabId];+ async refresh() {+ const activeTabId = this.tabContext && this.tabContext.tabId;- if (widget) {- widget.toggleExt(true);- }- else {- console.error(`Widget for tab ${this.tabContext.tabId} not found.`);+ for (const tabId in this.widgets) {+ this.widgets[tabId].toggleExt(tabId === activeTabId);}}diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.jsindex 863982888a..24bcd66d79 100644--- a/src/public/javascripts/widgets/tab_row.js+++ b/src/public/javascripts/widgets/tab_row.js@@ -411,7 +411,7 @@ export default class TabRowWidget extends BasicWidget {}activeTabChangedEvent() {- const newActiveTabId = appContext.tabManager.activeTabId;+ const newActiveTabId = appContext.tabManager.getActiveTabContext().tabId;const tabEl = this.getTabById(newActiveTabId)[0];const activeTabEl = this.activeTabEl;@@ -575,14 +575,14 @@ export default class TabRowWidget extends BasicWidget {return closestIndex;};- tabNoteSwitchedAndActivatedEvent({tabId}) {+ tabNoteSwitchedAndActivatedEvent({tabContext}) {this.activeTabChangedEvent();- this.updateTabById(tabId);+ this.updateTabById(tabContext.tabId);}- tabNoteSwitchedEvent({tabId}) {- this.updateTabById(tabId);+ tabNoteSwitchedEvent({tabContext}) {+ this.updateTabById(tabContext.tabId);}updateTabById(tabId) {