diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index da0e7c7d0..297459721 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.js index 1a63abeba..fac7805f5 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.js index 5586e4501..d0feaf647 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 time if (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.js index 465cc629d..bfda627a2 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 = $(`