Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactored TabContext => NoteContext
zadam98dfc77195da
diff --git a/src/public/app/services/keyboard_actions.js b/src/public/app/services/keyboard_actions.jsindex 077fbd49d6..87d2c7df68 100644--- a/src/public/app/services/keyboard_actions.js+++ b/src/public/app/services/keyboard_actions.js@@ -27,7 +27,7 @@ async function setupActionsForElement(scope, $el, component) {for (const action of actions) {for (const shortcut of action.effectiveShortcuts) {- utils.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeTabId}));+ utils.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeNtxId}));}}}@@ -35,7 +35,7 @@ async function setupActionsForElement(scope, $el, component) {getActionsForScope("window").then(actions => {for (const action of actions) {for (const shortcut of action.effectiveShortcuts) {- utils.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeTabId}));+ utils.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeNtxId}));}}});diff --git a/src/public/app/services/note_context.js b/src/public/app/services/note_context.jsindex 6c9ba346bf..6e1ae1408b 100644--- a/src/public/app/services/note_context.js+++ b/src/public/app/services/note_context.js@@ -60,11 +60,11 @@ class NoteContext extends Component {}}- getAllSubNoteContexts() {+ getSubContexts() {return appContext.tabManager.noteContexts.filter(nc => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId);}- getMainNoteContext() {+ getMainContext() {if (this.mainNtxId) {return appContext.tabManager.getNoteContextById(this.mainNtxId);}@@ -138,7 +138,7 @@ class NoteContext extends Component {}isActive() {- return appContext.tabManager.activeTabId === this.ntxId;+ return appContext.tabManager.activeNtxId === this.ntxId;}getTabState() {diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.jsindex 99b7b4461c..2868608c08 100644--- a/src/public/app/services/tab_manager.js+++ b/src/public/app/services/tab_manager.js@@ -12,7 +12,7 @@ export default class TabManager extends Component {constructor() {super();- this.activeTabId = null;+ this.activeNtxId = null;this.tabsUpdate = new SpacedUpdate(async () => {if (!appContext.isMainWindow) {@@ -156,8 +156,15 @@ export default class TabManager extends Component {/** @returns {NoteContext} */getActiveContext() {- return this.activeTabId- ? this.getNoteContextById(this.activeTabId)+ return this.activeNtxId+ ? this.getNoteContextById(this.activeNtxId)+ : null;+ }++ /** @returns {NoteContext} */+ getActiveMainContext() {+ return this.activeNtxId+ ? this.getNoteContextById(this.activeNtxId).getMainContext(): null;}@@ -271,11 +278,11 @@ export default class TabManager extends Component {}activateNoteContext(ntxId, triggerEvent = true) {- if (ntxId === this.activeTabId) {+ if (ntxId === this.activeNtxId) {return;}- this.activeTabId = ntxId;+ this.activeNtxId = ntxId;if (triggerEvent) {this.triggerEvent('activeTabChanged', {@@ -289,19 +296,19 @@ export default class TabManager extends Component {}async removeNoteContext(ntxId) {- const mainNoteContextToRemove = this.getNoteContextById(ntxId).getMainNoteContext();+ const mainNoteContextToRemove = this.getNoteContextById(ntxId).getMainContext();// close dangling autocompletes after closing the tab$(".aa-input").autocomplete("close");- const ntxIdsToRemove = mainNoteContextToRemove.getAllSubNoteContexts().map(nc => nc.ntxId);+ const ntxIdsToRemove = mainNoteContextToRemove.getSubContexts().map(nc => nc.ntxId);await this.triggerEvent('beforeTabRemove', { ntxIds: ntxIdsToRemove });if (this.mainNoteContexts.length <= 1) {await this.openAndActivateEmptyTab();}- else if (ntxIdsToRemove.includes(this.activeTabId)) {+ else if (ntxIdsToRemove.includes(this.activeNtxId)) {const idx = this.mainNoteContexts.findIndex(nc => nc.ntxId === mainNoteContextToRemove.ntxId);if (idx === this.mainNoteContexts.length - 1) {@@ -332,21 +339,21 @@ export default class TabManager extends Component {}activateNextTabCommand() {- const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);+ const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeNtxId);const newActiveTabId = this.mainNoteContexts[oldIdx === this.noteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;this.activateNoteContext(newActiveTabId);}activatePreviousTabCommand() {- const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);+ const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeNtxId);const newActiveTabId = this.mainNoteContexts[oldIdx === 0 ? this.noteContexts.length - 1 : oldIdx - 1].ntxId;this.activateNoteContext(newActiveTabId);}closeActiveTabCommand() {- this.removeNoteContext(this.activeTabId);+ this.removeNoteContext(this.activeNtxId);}beforeUnloadEvent() {diff --git a/src/public/app/widgets/containers/pane_container.js b/src/public/app/widgets/containers/pane_container.jsindex 78c944dbc1..168a0f025c 100644--- a/src/public/app/widgets/containers/pane_container.js+++ b/src/public/app/widgets/containers/pane_container.js@@ -49,13 +49,14 @@ export default class PaneContainer extends FlexContainer {toggleInt(show) {} // not neededtoggleExt(show) {- const activeTabId = appContext.tabManager.getActiveContext().getMainNoteContext().ntxId;+ const activeMainContext = appContext.tabManager.getActiveMainContext();+ const activeNtxId = activeMainContext ? activeMainContext.ntxId : null;for (const ntxId in this.widgets) {const noteContext = appContext.tabManager.getNoteContextById(ntxId);const widget = this.widgets[ntxId];- widget.toggleExt(show && activeTabId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeTabId));+ widget.toggleExt(show && activeNtxId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeNtxId));if (!widget.hasBeenAlreadyShown) {widget.handleEvent('activeTabChanged', {noteContext});@@ -79,11 +80,11 @@ export default class PaneContainer extends FlexContainer {const promises = [];- if (appContext.tabManager.getActiveContext().getMainNoteContext() === data.noteContext.getMainNoteContext()) {+ if (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) {promises.push(widget.handleEvent('activeTabChanged', data));}- for (const subNoteContext of data.noteContext.getMainNoteContext().getAllSubNoteContexts()) {+ for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {const subWidget = this.widgets[subNoteContext.ntxId];if (!subWidget) {@@ -112,7 +113,7 @@ export default class PaneContainer extends FlexContainer {if (name === 'activeTabChanged') {const promises = [];- for (const subNoteContext of data.noteContext.getMainNoteContext().getAllSubNoteContexts()) {+ for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {console.log("subNoteContext", subNoteContext);const widget = this.widgets[subNoteContext.ntxId];