mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixed double refresh of note detail
This commit is contained in:
parent
d71763aedb
commit
b2a3e1cc04
@ -17,7 +17,7 @@ class TabContext extends Component {
|
|||||||
this.tabId = tabId || utils.randomString(4);
|
this.tabId = tabId || utils.randomString(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setNote(inputNotePath) {
|
async setNote(inputNotePath, triggerSwitchEvent = true) {
|
||||||
const notePath = await treeService.resolveNotePath(inputNotePath);
|
const notePath = await treeService.resolveNotePath(inputNotePath);
|
||||||
|
|
||||||
if (!notePath) {
|
if (!notePath) {
|
||||||
@ -59,11 +59,13 @@ class TabContext extends Component {
|
|||||||
protectedSessionHolder.touchProtectedSession();
|
protectedSessionHolder.touchProtectedSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (triggerSwitchEvent) {
|
||||||
this.triggerEvent('tabNoteSwitched', {
|
this.triggerEvent('tabNoteSwitched', {
|
||||||
tabId: this.tabId,
|
tabId: this.tabId,
|
||||||
notePath: this.notePath
|
notePath: this.notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @property {NoteShort} */
|
/** @property {NoteShort} */
|
||||||
get note() {
|
get note() {
|
||||||
|
@ -88,13 +88,7 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
|
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
|
||||||
for (const tab of filteredTabs) {
|
for (const tab of filteredTabs) {
|
||||||
const tabContext = this.openEmptyTab(tab.tabId);
|
await this.openTabWithNote(tab.notePath, tab.active, tab.tabId);
|
||||||
|
|
||||||
if (tab.active) {
|
|
||||||
this.activateTab(tabContext.tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
await tabContext.setNote(tab.notePath);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -185,11 +179,23 @@ export default class TabManager extends Component {
|
|||||||
const tabContext = new TabContext(tabId);
|
const tabContext = new TabContext(tabId);
|
||||||
this.child(tabContext);
|
this.child(tabContext);
|
||||||
|
|
||||||
this.triggerEvent('newTabOpened', {tabId: this.tabId})
|
this.triggerEvent('newTabOpened', {tabId: this.tabId});
|
||||||
|
|
||||||
return tabContext;
|
return tabContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async openTabWithNote(notePath, activate, tabId = null) {
|
||||||
|
const tabContext = this.openEmptyTab(tabId);
|
||||||
|
|
||||||
|
await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
|
||||||
|
|
||||||
|
if (activate) {
|
||||||
|
this.activateTab(tabContext.tabId, false);
|
||||||
|
|
||||||
|
this.triggerEvent('tabNoteSwitchedAndActivated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async activateOrOpenNote(noteId) {
|
async activateOrOpenNote(noteId) {
|
||||||
for (const tabContext of this.getTabContexts()) {
|
for (const tabContext of this.getTabContexts()) {
|
||||||
if (tabContext.note && tabContext.note.noteId === noteId) {
|
if (tabContext.note && tabContext.note.noteId === noteId) {
|
||||||
@ -204,14 +210,16 @@ export default class TabManager extends Component {
|
|||||||
await tabContext.setNote(noteId);
|
await tabContext.setNote(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
activateTab(tabId) {
|
activateTab(tabId, triggerEvent = true) {
|
||||||
if (tabId === this.activeTabId) {
|
if (tabId === this.activeTabId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activeTabId = tabId;
|
this.activeTabId = tabId;
|
||||||
|
|
||||||
|
if (triggerEvent) {
|
||||||
this.triggerEvent('activeTabChanged');
|
this.triggerEvent('activeTabChanged');
|
||||||
|
}
|
||||||
|
|
||||||
this.tabsUpdate.scheduleUpdate();
|
this.tabsUpdate.scheduleUpdate();
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ import SidePaneToggles from "./side_pane_toggles.js";
|
|||||||
|
|
||||||
export default class Layout {
|
export default class Layout {
|
||||||
getRootWidget(appContext) {
|
getRootWidget(appContext) {
|
||||||
const root = new FlexContainer('column').id('root-widget')
|
return new FlexContainer('column')
|
||||||
|
.setParent(appContext)
|
||||||
|
.id('root-widget')
|
||||||
.child(new FlexContainer('row')
|
.child(new FlexContainer('row')
|
||||||
.child(new GlobalMenuWidget())
|
.child(new GlobalMenuWidget())
|
||||||
.child(new TabRowWidget())
|
.child(new TabRowWidget())
|
||||||
@ -65,9 +67,5 @@ export default class Layout {
|
|||||||
)
|
)
|
||||||
.child(new SidePaneToggles())
|
.child(new SidePaneToggles())
|
||||||
);
|
);
|
||||||
|
|
||||||
root.setParent(appContext);
|
|
||||||
|
|
||||||
return root;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -236,13 +236,6 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleEventInChildren(name, data) {
|
|
||||||
// done manually in refresh()
|
|
||||||
if (name !== 'setTabContext') {
|
|
||||||
await super.handleEventInChildren(name, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async cutIntoNoteCommand() {
|
async cutIntoNoteCommand() {
|
||||||
const note = appContext.tabManager.getActiveTabNote();
|
const note = appContext.tabManager.getActiveTabNote();
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ export default class TabAwareWidget extends BasicWidget {
|
|||||||
setTabContextEvent({tabContext}) {
|
setTabContextEvent({tabContext}) {
|
||||||
/** @var {TabContext} */
|
/** @var {TabContext} */
|
||||||
this.tabContext = tabContext;
|
this.tabContext = tabContext;
|
||||||
|
|
||||||
this.noteSwitched();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isTab(tabId) {
|
isTab(tabId) {
|
||||||
@ -80,6 +78,13 @@ export default class TabAwareWidget extends BasicWidget {
|
|||||||
this.activeTabChanged();
|
this.activeTabChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when note is both switched and activated, this should not produce double refresh
|
||||||
|
tabNoteSwitchedAndActivatedEvent() {
|
||||||
|
this.tabContext = appContext.tabManager.getActiveTabContext();
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
treeCacheReloadedEvent() {
|
treeCacheReloadedEvent() {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ export default class TabCachingWidget extends TabAwareWidget {
|
|||||||
let widget = this.widgets[this.tabContext.tabId];
|
let widget = this.widgets[this.tabContext.tabId];
|
||||||
|
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
widget = this.widgets[this.tabContext.tabId] = this.widgetFactory(this);
|
widget = this.widgets[this.tabContext.tabId] = this.widgetFactory();
|
||||||
this.children.push(widget);
|
this.child(widget);
|
||||||
|
|
||||||
const $renderedWidget = widget.render();
|
const $renderedWidget = widget.render();
|
||||||
keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
|
keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user