mirror of
https://github.com/zadam/trilium.git
synced 2025-01-16 12:08:03 +08:00
event fixes
This commit is contained in:
parent
091eb8f791
commit
8909d175d0
5 changed files with 25 additions and 47 deletions
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
async refresh() {
|
||||
const activeTabId = this.tabContext && this.tabContext.tabId;
|
||||
|
||||
if (!this.tabContext) {
|
||||
console.log(`No tabContext in widget ${this.componentId}.`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const widget = this.widgets[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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue