This commit is contained in:
zadam 2020-02-28 11:46:35 +01:00
parent cb35284d37
commit a2d6a5c3e9
5 changed files with 21 additions and 5 deletions

View File

@ -17,6 +17,13 @@ class TabContext extends Component {
this.tabId = tabId || utils.randomString(4);
}
setEmpty() {
this.triggerEvent('tabNoteSwitched', {
tabId: this.tabId,
notePath: this.notePath
});
}
async setNote(inputNotePath, triggerSwitchEvent = true) {
const notePath = await treeService.resolveNotePath(inputNotePath);

View File

@ -173,13 +173,15 @@ export default class TabManager extends Component {
const tabContext = this.openEmptyTab();
await this.activateTab(tabContext.tabId);
await tabContext.setEmpty();
}
openEmptyTab(tabId) {
const tabContext = new TabContext(tabId);
this.child(tabContext);
this.triggerEvent('newTabOpened', {tabId: this.tabId});
this.triggerEvent('newTabOpened', {tabId: tabContext.tabId});
return tabContext;
}

View File

@ -80,7 +80,9 @@ export default class TabAwareWidget extends BasicWidget {
// when note is both switched and activated, this should not produce double refresh
async tabNoteSwitchedAndActivatedEvent({tabId, notePath}) {
if (this.isTab(tabId) && this.notePath === notePath) {
this.tabContext = appContext.tabManager.getActiveTabContext();
if (this.notePath === notePath) {
this.tabContext = appContext.tabManager.getActiveTabContext();
await this.refresh();

View File

@ -20,12 +20,15 @@ export default class TabCachingWidget extends TabAwareWidget {
async handleEventInChildren(name, data) {
// stop propagation of the event to the children, individual tab widget should not know about tab switching
// since they are per-tab
if (name !== 'activeTabChanged') {
if (name === 'tabNoteSwitchedAndActivated') {
await super.handleEventInChildren('tabNoteSwitched', data);
}
else if (name !== 'activeTabChanged') {
await super.handleEventInChildren(name, data);
}
}
refreshWithNote() {
async refreshWithNote() {
for (const widget of Object.values(this.widgets)) {
widget.toggle(false);
}
@ -47,7 +50,7 @@ export default class TabCachingWidget extends TabAwareWidget {
keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
this.child(widget); // add as child only once it is ready (also rendered)
widget.handleEvent('setTabContext', {tabContext: this.tabContext});
await widget.handleEvent('setTabContext', {tabContext: this.tabContext});
}
widget.toggle(widget.isEnabled());

View File

@ -576,6 +576,8 @@ export default class TabRowWidget extends BasicWidget {
};
tabNoteSwitchedAndActivatedEvent({tabId}) {
this.activeTabChangedEvent();
this.updateTabById(tabId);
}