mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
event fixes
This commit is contained in:
parent
091eb8f791
commit
8909d175d0
@ -19,7 +19,7 @@ class TabContext extends Component {
|
|||||||
|
|
||||||
setEmpty() {
|
setEmpty() {
|
||||||
this.triggerEvent('tabNoteSwitched', {
|
this.triggerEvent('tabNoteSwitched', {
|
||||||
tabId: this.tabId,
|
tabContext: this,
|
||||||
notePath: this.notePath
|
notePath: this.notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class TabContext extends Component {
|
|||||||
|
|
||||||
if (triggerSwitchEvent) {
|
if (triggerSwitchEvent) {
|
||||||
this.triggerEvent('tabNoteSwitched', {
|
this.triggerEvent('tabNoteSwitched', {
|
||||||
tabId: this.tabId,
|
tabContext: this,
|
||||||
notePath: this.notePath
|
notePath: this.notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ class TabContext extends Component {
|
|||||||
this.notePath = null;
|
this.notePath = null;
|
||||||
|
|
||||||
this.triggerEvent('tabNoteSwitched', {
|
this.triggerEvent('tabNoteSwitched', {
|
||||||
tabId: this.tabId,
|
tabContext: this,
|
||||||
notePath: this.notePath
|
notePath: this.notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -93,8 +93,8 @@ export default class TabManager extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
tabNoteSwitchedEvent({tabId}) {
|
tabNoteSwitchedEvent({tabContext}) {
|
||||||
if (tabId === this.activeTabId) {
|
if (tabContext.isActive()) {
|
||||||
this.setCurrentNotePathToHash();
|
this.setCurrentNotePathToHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ export default class TabManager extends Component {
|
|||||||
this.activateTab(tabContext.tabId, false);
|
this.activateTab(tabContext.tabId, false);
|
||||||
|
|
||||||
this.triggerEvent('tabNoteSwitchedAndActivated', {
|
this.triggerEvent('tabNoteSwitchedAndActivated', {
|
||||||
tabId: tabContext.tabId,
|
tabContext,
|
||||||
notePath
|
notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -222,7 +222,9 @@ export default class TabManager extends Component {
|
|||||||
this.activeTabId = tabId;
|
this.activeTabId = tabId;
|
||||||
|
|
||||||
if (triggerEvent) {
|
if (triggerEvent) {
|
||||||
this.triggerEvent('activeTabChanged', {tabId});
|
this.triggerEvent('activeTabChanged', {
|
||||||
|
tabContext: this.getTabContextById(tabId)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tabsUpdate.scheduleUpdate();
|
this.tabsUpdate.scheduleUpdate();
|
||||||
|
@ -46,9 +46,9 @@ export default class TabAwareWidget extends BasicWidget {
|
|||||||
|
|
||||||
async refreshWithNote(note, notePath) {}
|
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 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();
|
await this.noteSwitched();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,8 +57,8 @@ export default class TabAwareWidget extends BasicWidget {
|
|||||||
await this.refresh();
|
await this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
async activeTabChangedEvent({tabId}) {
|
async activeTabChangedEvent({tabContext}) {
|
||||||
this.tabContext = appContext.tabManager.getTabContextById(tabId);
|
this.tabContext = tabContext;
|
||||||
|
|
||||||
await this.activeTabChanged();
|
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
|
// when note is both switched and activated, this should not produce double refresh
|
||||||
async tabNoteSwitchedAndActivatedEvent({tabId, notePath}) {
|
async tabNoteSwitchedAndActivatedEvent({tabContext, notePath}) {
|
||||||
this.tabContext = appContext.tabManager.getTabContextById(tabId);
|
this.tabContext = tabContext;
|
||||||
|
|
||||||
// if notePath does not match then the tabContext has been switched to another note in the mean time
|
// if notePath does not match then the tabContext has been switched to another note in the mean time
|
||||||
if (this.notePath === notePath) {
|
if (this.notePath === notePath) {
|
||||||
@ -84,11 +84,6 @@ export default class TabAwareWidget extends BasicWidget {
|
|||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
async newTabOpenedEvent({tabContext}) {
|
|
||||||
/** @var {TabContext} */
|
|
||||||
this.tabContext = tabContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
async noteTypeMimeChangedEvent({noteId}) {
|
async noteTypeMimeChangedEvent({noteId}) {
|
||||||
if (this.isNote(noteId)) {
|
if (this.isNote(noteId)) {
|
||||||
await this.refresh();
|
await this.refresh();
|
||||||
|
@ -9,10 +9,6 @@ export default class TabCachingWidget extends TabAwareWidget {
|
|||||||
this.widgets = {};
|
this.widgets = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
isEnabled() {
|
|
||||||
return !!this.tabContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
return this.$widget = $(`<div class="marker" style="display: none;">`);
|
return this.$widget = $(`<div class="marker" style="display: none;">`);
|
||||||
}
|
}
|
||||||
@ -31,8 +27,6 @@ export default class TabCachingWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async newTabOpenedEvent({tabContext}) {
|
async newTabOpenedEvent({tabContext}) {
|
||||||
super.newTabOpenedEvent({tabContext});
|
|
||||||
|
|
||||||
const {tabId} = tabContext;
|
const {tabId} = tabContext;
|
||||||
|
|
||||||
if (this.widgets[tabId]) {
|
if (this.widgets[tabId]) {
|
||||||
@ -48,29 +42,16 @@ export default class TabCachingWidget extends TabAwareWidget {
|
|||||||
|
|
||||||
keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
|
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)
|
this.child(this.widgets[tabId]); // add as child only once it is ready (rendered with tabContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote() {
|
async refresh() {
|
||||||
for (const widget of Object.values(this.widgets)) {
|
const activeTabId = this.tabContext && this.tabContext.tabId;
|
||||||
widget.toggleExt(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.tabContext) {
|
for (const tabId in this.widgets) {
|
||||||
console.log(`No tabContext in widget ${this.componentId}.`);
|
this.widgets[tabId].toggleExt(tabId === activeTabId);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const widget = this.widgets[this.tabContext.tabId];
|
|
||||||
|
|
||||||
if (widget) {
|
|
||||||
widget.toggleExt(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(`Widget for tab ${this.tabContext.tabId} not found.`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activeTabChangedEvent() {
|
activeTabChangedEvent() {
|
||||||
const newActiveTabId = appContext.tabManager.activeTabId;
|
const newActiveTabId = appContext.tabManager.getActiveTabContext().tabId;
|
||||||
|
|
||||||
const tabEl = this.getTabById(newActiveTabId)[0];
|
const tabEl = this.getTabById(newActiveTabId)[0];
|
||||||
const activeTabEl = this.activeTabEl;
|
const activeTabEl = this.activeTabEl;
|
||||||
@ -575,14 +575,14 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
return closestIndex;
|
return closestIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
tabNoteSwitchedAndActivatedEvent({tabId}) {
|
tabNoteSwitchedAndActivatedEvent({tabContext}) {
|
||||||
this.activeTabChangedEvent();
|
this.activeTabChangedEvent();
|
||||||
|
|
||||||
this.updateTabById(tabId);
|
this.updateTabById(tabContext.tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
tabNoteSwitchedEvent({tabId}) {
|
tabNoteSwitchedEvent({tabContext}) {
|
||||||
this.updateTabById(tabId);
|
this.updateTabById(tabContext.tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTabById(tabId) {
|
updateTabById(tabId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user