mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	@@ -22,6 +22,7 @@ import type LoadResults from "../services/load_results.js";
 | 
				
			|||||||
import type { Attribute } from "../services/attribute_parser.js";
 | 
					import type { Attribute } from "../services/attribute_parser.js";
 | 
				
			||||||
import type NoteTreeWidget from "../widgets/note_tree.js";
 | 
					import type NoteTreeWidget from "../widgets/note_tree.js";
 | 
				
			||||||
import type { default as NoteContext, GetTextEditorCallback } from "./note_context.js";
 | 
					import type { default as NoteContext, GetTextEditorCallback } from "./note_context.js";
 | 
				
			||||||
 | 
					import type { ContextMenuEvent } from "../menus/context_menu.js";
 | 
				
			||||||
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
 | 
					import type TypeWidget from "../widgets/type_widgets/type_widget.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface Layout {
 | 
					interface Layout {
 | 
				
			||||||
@@ -55,8 +56,8 @@ export interface ContextMenuCommandData extends CommandData {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface NoteCommandData extends CommandData {
 | 
					export interface NoteCommandData extends CommandData {
 | 
				
			||||||
    notePath?: string | null;
 | 
					    notePath?: string;
 | 
				
			||||||
    hoistedNoteId?: string | null;
 | 
					    hoistedNoteId?: string;
 | 
				
			||||||
    viewScope?: ViewScope;
 | 
					    viewScope?: ViewScope;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -325,7 +326,7 @@ type EventMappings = {
 | 
				
			|||||||
        ntxId: string | null;
 | 
					        ntxId: string | null;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    contextsReopenedEvent: {
 | 
					    contextsReopenedEvent: {
 | 
				
			||||||
        mainNtxId: string | null;
 | 
					        mainNtxId: string;
 | 
				
			||||||
        tabPosition: number;
 | 
					        tabPosition: number;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    noteDetailRefreshed: {
 | 
					    noteDetailRefreshed: {
 | 
				
			||||||
@@ -339,7 +340,7 @@ type EventMappings = {
 | 
				
			|||||||
    newNoteContextCreated: {
 | 
					    newNoteContextCreated: {
 | 
				
			||||||
        noteContext: NoteContext;
 | 
					        noteContext: NoteContext;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    noteContextRemoved: {
 | 
					    noteContextRemovedEvent: {
 | 
				
			||||||
        ntxIds: string[];
 | 
					        ntxIds: string[];
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    exportSvg: {
 | 
					    exportSvg: {
 | 
				
			||||||
@@ -360,7 +361,6 @@ type EventMappings = {
 | 
				
			|||||||
    relationMapResetPanZoom: { ntxId: string | null | undefined };
 | 
					    relationMapResetPanZoom: { ntxId: string | null | undefined };
 | 
				
			||||||
    relationMapResetZoomIn: { ntxId: string | null | undefined };
 | 
					    relationMapResetZoomIn: { ntxId: string | null | undefined };
 | 
				
			||||||
    relationMapResetZoomOut: { ntxId: string | null | undefined };
 | 
					    relationMapResetZoomOut: { ntxId: string | null | undefined };
 | 
				
			||||||
    activeNoteChangedEvent: {};
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type EventListener<T extends EventNames> = {
 | 
					export type EventListener<T extends EventNames> = {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,13 +66,12 @@ export default class Entrypoints extends Component {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async toggleNoteHoistingCommand({ noteId = appContext.tabManager.getActiveContextNoteId() }) {
 | 
					    async toggleNoteHoistingCommand({ noteId = appContext.tabManager.getActiveContextNoteId() }) {
 | 
				
			||||||
        const activeNoteContext = appContext.tabManager.getActiveContext();
 | 
					        if (!noteId) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!activeNoteContext || !noteId) {
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const noteToHoist = await froca.getNote(noteId);
 | 
					        const noteToHoist = await froca.getNote(noteId);
 | 
				
			||||||
 | 
					        const activeNoteContext = appContext.tabManager.getActiveContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (noteToHoist?.noteId === activeNoteContext.hoistedNoteId) {
 | 
					        if (noteToHoist?.noteId === activeNoteContext.hoistedNoteId) {
 | 
				
			||||||
            await activeNoteContext.unhoist();
 | 
					            await activeNoteContext.unhoist();
 | 
				
			||||||
@@ -84,11 +83,6 @@ export default class Entrypoints extends Component {
 | 
				
			|||||||
    async hoistNoteCommand({ noteId }: { noteId: string }) {
 | 
					    async hoistNoteCommand({ noteId }: { noteId: string }) {
 | 
				
			||||||
        const noteContext = appContext.tabManager.getActiveContext();
 | 
					        const noteContext = appContext.tabManager.getActiveContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!noteContext) {
 | 
					 | 
				
			||||||
            logError("hoistNoteCommand: noteContext is null");
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (noteContext.hoistedNoteId !== noteId) {
 | 
					        if (noteContext.hoistedNoteId !== noteId) {
 | 
				
			||||||
            await noteContext.setHoistedNoteId(noteId);
 | 
					            await noteContext.setHoistedNoteId(noteId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -180,11 +174,7 @@ export default class Entrypoints extends Component {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async runActiveNoteCommand() {
 | 
					    async runActiveNoteCommand() {
 | 
				
			||||||
        const noteContext = appContext.tabManager.getActiveContext();
 | 
					        const { ntxId, note } = appContext.tabManager.getActiveContext();
 | 
				
			||||||
        if (!noteContext) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        const { ntxId, note } = noteContext;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // ctrl+enter is also used elsewhere, so make sure we're running only when appropriate
 | 
					        // ctrl+enter is also used elsewhere, so make sure we're running only when appropriate
 | 
				
			||||||
        if (!note || note.type !== "code") {
 | 
					        if (!note || note.type !== "code") {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,40 +4,23 @@ import server from "../services/server.js";
 | 
				
			|||||||
import options from "../services/options.js";
 | 
					import options from "../services/options.js";
 | 
				
			||||||
import froca from "../services/froca.js";
 | 
					import froca from "../services/froca.js";
 | 
				
			||||||
import treeService from "../services/tree.js";
 | 
					import treeService from "../services/tree.js";
 | 
				
			||||||
 | 
					import utils from "../services/utils.js";
 | 
				
			||||||
import NoteContext from "./note_context.js";
 | 
					import NoteContext from "./note_context.js";
 | 
				
			||||||
import appContext from "./app_context.js";
 | 
					import appContext from "./app_context.js";
 | 
				
			||||||
import Mutex from "../utils/mutex.js";
 | 
					import Mutex from "../utils/mutex.js";
 | 
				
			||||||
import linkService from "../services/link.js";
 | 
					import linkService from "../services/link.js";
 | 
				
			||||||
import type { EventData } from "./app_context.js";
 | 
					 | 
				
			||||||
import type FNote from "../entities/fnote.js";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
interface TabState {
 | 
					 | 
				
			||||||
    contexts: NoteContext[];
 | 
					 | 
				
			||||||
    position: number;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
interface NoteContextState {
 | 
					 | 
				
			||||||
    ntxId: string;
 | 
					 | 
				
			||||||
    mainNtxId: string | null;
 | 
					 | 
				
			||||||
    notePath: string | null;
 | 
					 | 
				
			||||||
    hoistedNoteId: string;
 | 
					 | 
				
			||||||
    active: boolean;
 | 
					 | 
				
			||||||
    viewScope: Record<string, any>;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class TabManager extends Component {
 | 
					export default class TabManager extends Component {
 | 
				
			||||||
    public children: NoteContext[];
 | 
					 | 
				
			||||||
    public mutex: Mutex;
 | 
					 | 
				
			||||||
    public activeNtxId: string | null;
 | 
					 | 
				
			||||||
    public recentlyClosedTabs: TabState[];
 | 
					 | 
				
			||||||
    public tabsUpdate: SpacedUpdate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @property {NoteContext[]} */
 | 
				
			||||||
        this.children = [];
 | 
					        this.children = [];
 | 
				
			||||||
        this.mutex = new Mutex();
 | 
					        this.mutex = new Mutex();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.activeNtxId = null;
 | 
					        this.activeNtxId = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // elements are arrays of {contexts, position}, storing note contexts for each tab (one main context + subcontexts [splits]), and the original position of the tab
 | 
				
			||||||
        this.recentlyClosedTabs = [];
 | 
					        this.recentlyClosedTabs = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.tabsUpdate = new SpacedUpdate(async () => {
 | 
					        this.tabsUpdate = new SpacedUpdate(async () => {
 | 
				
			||||||
@@ -45,9 +28,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const openNoteContexts = this.noteContexts
 | 
					            const openNoteContexts = this.noteContexts.map((nc) => nc.getPojoState()).filter((t) => !!t);
 | 
				
			||||||
                .map((nc) => nc.getPojoState())
 | 
					 | 
				
			||||||
                .filter((t) => !!t);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await server.put("options", {
 | 
					            await server.put("options", {
 | 
				
			||||||
                openNoteContexts: JSON.stringify(openNoteContexts)
 | 
					                openNoteContexts: JSON.stringify(openNoteContexts)
 | 
				
			||||||
@@ -57,11 +38,13 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        appContext.addBeforeUnloadListener(this);
 | 
					        appContext.addBeforeUnloadListener(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    get noteContexts(): NoteContext[] {
 | 
					    /** @returns {NoteContext[]} */
 | 
				
			||||||
 | 
					    get noteContexts() {
 | 
				
			||||||
        return this.children;
 | 
					        return this.children;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    get mainNoteContexts(): NoteContext[] {
 | 
					    /** @type {NoteContext[]} */
 | 
				
			||||||
 | 
					    get mainNoteContexts() {
 | 
				
			||||||
        return this.noteContexts.filter((nc) => !nc.mainNtxId);
 | 
					        return this.noteContexts.filter((nc) => !nc.mainNtxId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,12 +53,11 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            const noteContextsToOpen = (appContext.isMainWindow && options.getJson("openNoteContexts")) || [];
 | 
					            const noteContextsToOpen = (appContext.isMainWindow && options.getJson("openNoteContexts")) || [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // preload all notes at once
 | 
					            // preload all notes at once
 | 
				
			||||||
            await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) =>
 | 
					            await froca.getNotes([...noteContextsToOpen.flatMap((tab) => [treeService.getNoteIdFromUrl(tab.notePath), tab.hoistedNoteId])], true);
 | 
				
			||||||
                [treeService.getNoteIdFromUrl(tab.notePath), tab.hoistedNoteId])], true);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const filteredNoteContexts = noteContextsToOpen.filter((openTab: NoteContextState) => {
 | 
					            const filteredNoteContexts = noteContextsToOpen.filter((openTab) => {
 | 
				
			||||||
                const noteId = treeService.getNoteIdFromUrl(openTab.notePath);
 | 
					                const noteId = treeService.getNoteIdFromUrl(openTab.notePath);
 | 
				
			||||||
                if (noteId && !(noteId in froca.notes)) {
 | 
					                if (!(noteId in froca.notes)) {
 | 
				
			||||||
                    // note doesn't exist so don't try to open tab for it
 | 
					                    // note doesn't exist so don't try to open tab for it
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -98,10 +80,9 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                    ntxId: parsedFromUrl.ntxId,
 | 
					                    ntxId: parsedFromUrl.ntxId,
 | 
				
			||||||
                    active: true,
 | 
					                    active: true,
 | 
				
			||||||
                    hoistedNoteId: parsedFromUrl.hoistedNoteId || "root",
 | 
					                    hoistedNoteId: parsedFromUrl.hoistedNoteId || "root",
 | 
				
			||||||
                    viewScope: parsedFromUrl.viewScope || {},
 | 
					                    viewScope: parsedFromUrl.viewScope || {}
 | 
				
			||||||
                    mainNtxId: null
 | 
					 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            } else if (!filteredNoteContexts.find((tab: NoteContextState) => tab.active)) {
 | 
					            } else if (!filteredNoteContexts.find((tab) => tab.active)) {
 | 
				
			||||||
                filteredNoteContexts[0].active = true;
 | 
					                filteredNoteContexts[0].active = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -120,30 +101,21 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            // if there's a notePath in the URL, make sure it's open and active
 | 
					            // if there's a notePath in the URL, make sure it's open and active
 | 
				
			||||||
            // (useful, for e.g., opening clipped notes from clipper or opening link in an extra window)
 | 
					            // (useful, for e.g., opening clipped notes from clipper or opening link in an extra window)
 | 
				
			||||||
            if (parsedFromUrl.notePath) {
 | 
					            if (parsedFromUrl.notePath) {
 | 
				
			||||||
                await appContext.tabManager.switchToNoteContext(
 | 
					                await appContext.tabManager.switchToNoteContext(parsedFromUrl.ntxId, parsedFromUrl.notePath, parsedFromUrl.viewScope, parsedFromUrl.hoistedNoteId);
 | 
				
			||||||
                    parsedFromUrl.ntxId,
 | 
					 | 
				
			||||||
                    parsedFromUrl.notePath,
 | 
					 | 
				
			||||||
                    parsedFromUrl.viewScope,
 | 
					 | 
				
			||||||
                    parsedFromUrl.hoistedNoteId
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
            } else if (parsedFromUrl.searchString) {
 | 
					            } else if (parsedFromUrl.searchString) {
 | 
				
			||||||
                await appContext.triggerCommand("searchNotes", {
 | 
					                await appContext.triggerCommand("searchNotes", {
 | 
				
			||||||
                    searchString: parsedFromUrl.searchString
 | 
					                    searchString: parsedFromUrl.searchString
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } catch (e: unknown) {
 | 
					        } catch (e) {
 | 
				
			||||||
            if (e instanceof Error) {
 | 
					 | 
				
			||||||
            logError(`Loading note contexts '${options.get("openNoteContexts")}' failed: ${e.message} ${e.stack}`);
 | 
					            logError(`Loading note contexts '${options.get("openNoteContexts")}' failed: ${e.message} ${e.stack}`);
 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                logError(`Loading note contexts '${options.get("openNoteContexts")}' failed: ${String(e)}`);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // try to recover
 | 
					            // try to recover
 | 
				
			||||||
            await this.openEmptyTab();
 | 
					            await this.openEmptyTab();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    noteSwitchedEvent({ noteContext }: EventData<"noteSwitched">) {
 | 
					    noteSwitchedEvent({ noteContext }) {
 | 
				
			||||||
        if (noteContext.isActive()) {
 | 
					        if (noteContext.isActive()) {
 | 
				
			||||||
            this.setCurrentNavigationStateToHash();
 | 
					            this.setCurrentNavigationStateToHash();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -163,10 +135,10 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        const activeNoteContext = this.getActiveContext();
 | 
					        const activeNoteContext = this.getActiveContext();
 | 
				
			||||||
        this.updateDocumentTitle(activeNoteContext);
 | 
					        this.updateDocumentTitle(activeNoteContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.triggerEvent("activeNoteChangedEvent", {}); // trigger this even in on popstate event
 | 
					        this.triggerEvent("activeNoteChanged"); // trigger this even in on popstate event
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    calculateHash(): string {
 | 
					    calculateHash() {
 | 
				
			||||||
        const activeNoteContext = this.getActiveContext();
 | 
					        const activeNoteContext = this.getActiveContext();
 | 
				
			||||||
        if (!activeNoteContext) {
 | 
					        if (!activeNoteContext) {
 | 
				
			||||||
            return "";
 | 
					            return "";
 | 
				
			||||||
@@ -180,15 +152,21 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getNoteContexts(): NoteContext[] {
 | 
					    /** @returns {NoteContext[]} */
 | 
				
			||||||
 | 
					    getNoteContexts() {
 | 
				
			||||||
        return this.noteContexts;
 | 
					        return this.noteContexts;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getMainNoteContexts(): NoteContext[] {
 | 
					    /**
 | 
				
			||||||
 | 
					     * Main context is essentially a tab (children are splits), so this returns tabs.
 | 
				
			||||||
 | 
					     * @returns {NoteContext[]}
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getMainNoteContexts() {
 | 
				
			||||||
        return this.noteContexts.filter((nc) => nc.isMainContext());
 | 
					        return this.noteContexts.filter((nc) => nc.isMainContext());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getNoteContextById(ntxId: string | null): NoteContext {
 | 
					    /** @returns {NoteContext} */
 | 
				
			||||||
 | 
					    getNoteContextById(ntxId) {
 | 
				
			||||||
        const noteContext = this.noteContexts.find((nc) => nc.ntxId === ntxId);
 | 
					        const noteContext = this.noteContexts.find((nc) => nc.ntxId === ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!noteContext) {
 | 
					        if (!noteContext) {
 | 
				
			||||||
@@ -198,47 +176,58 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        return noteContext;
 | 
					        return noteContext;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveContext(): NoteContext | null {
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get active context which represents the visible split with focus. Active context can, but doesn't have to be "main".
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @returns {NoteContext}
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getActiveContext() {
 | 
				
			||||||
        return this.activeNtxId ? this.getNoteContextById(this.activeNtxId) : null;
 | 
					        return this.activeNtxId ? this.getNoteContextById(this.activeNtxId) : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveMainContext(): NoteContext | null {
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get active main context which corresponds to the active tab.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @returns {NoteContext}
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getActiveMainContext() {
 | 
				
			||||||
        return this.activeNtxId ? this.getNoteContextById(this.activeNtxId).getMainContext() : null;
 | 
					        return this.activeNtxId ? this.getNoteContextById(this.activeNtxId).getMainContext() : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveContextNotePath(): string | null {
 | 
					    /** @returns {string|null} */
 | 
				
			||||||
 | 
					    getActiveContextNotePath() {
 | 
				
			||||||
        const activeContext = this.getActiveContext();
 | 
					        const activeContext = this.getActiveContext();
 | 
				
			||||||
        return activeContext?.notePath ?? null;
 | 
					        return activeContext ? activeContext.notePath : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveContextNote(): FNote | null {
 | 
					    /** @returns {FNote} */
 | 
				
			||||||
 | 
					    getActiveContextNote() {
 | 
				
			||||||
        const activeContext = this.getActiveContext();
 | 
					        const activeContext = this.getActiveContext();
 | 
				
			||||||
        return activeContext ? activeContext.note : null;
 | 
					        return activeContext ? activeContext.note : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveContextNoteId(): string | null {
 | 
					    /** @returns {string|null} */
 | 
				
			||||||
 | 
					    getActiveContextNoteId() {
 | 
				
			||||||
        const activeNote = this.getActiveContextNote();
 | 
					        const activeNote = this.getActiveContextNote();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return activeNote ? activeNote.noteId : null;
 | 
					        return activeNote ? activeNote.noteId : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getActiveContextNoteType(): string | null {
 | 
					    /** @returns {string|null} */
 | 
				
			||||||
 | 
					    getActiveContextNoteType() {
 | 
				
			||||||
        const activeNote = this.getActiveContextNote();
 | 
					        const activeNote = this.getActiveContextNote();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return activeNote ? activeNote.type : null;
 | 
					        return activeNote ? activeNote.type : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    /** @returns {string|null} */
 | 
				
			||||||
    getActiveContextNoteMime(): string | null {
 | 
					    getActiveContextNoteMime() {
 | 
				
			||||||
        const activeNote = this.getActiveContextNote();
 | 
					        const activeNote = this.getActiveContextNote();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return activeNote ? activeNote.mime : null;
 | 
					        return activeNote ? activeNote.mime : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async switchToNoteContext(
 | 
					    async switchToNoteContext(ntxId, notePath, viewScope = {}, hoistedNoteId = null) {
 | 
				
			||||||
        ntxId: string | null,
 | 
					        const noteContext = this.noteContexts.find((nc) => nc.ntxId === ntxId) || (await this.openEmptyTab());
 | 
				
			||||||
        notePath: string,
 | 
					 | 
				
			||||||
        viewScope: Record<string, any> = {},
 | 
					 | 
				
			||||||
        hoistedNoteId: string | null = null
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
        const noteContext = this.noteContexts.find((nc) => nc.ntxId === ntxId) ||
 | 
					 | 
				
			||||||
            await this.openEmptyTab();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await this.activateNoteContext(noteContext.ntxId);
 | 
					        await this.activateNoteContext(noteContext.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -253,21 +242,20 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async openAndActivateEmptyTab() {
 | 
					    async openAndActivateEmptyTab() {
 | 
				
			||||||
        const noteContext = await this.openEmptyTab();
 | 
					        const noteContext = await this.openEmptyTab();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await this.activateNoteContext(noteContext.ntxId);
 | 
					        await this.activateNoteContext(noteContext.ntxId);
 | 
				
			||||||
        noteContext.setEmpty();
 | 
					
 | 
				
			||||||
 | 
					        await noteContext.setEmpty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openEmptyTab(
 | 
					    async openEmptyTab(ntxId = null, hoistedNoteId = "root", mainNtxId = null) {
 | 
				
			||||||
        ntxId: string | null = null,
 | 
					 | 
				
			||||||
        hoistedNoteId: string = "root",
 | 
					 | 
				
			||||||
        mainNtxId: string | null = null
 | 
					 | 
				
			||||||
    ): Promise<NoteContext> {
 | 
					 | 
				
			||||||
        const noteContext = new NoteContext(ntxId, hoistedNoteId, mainNtxId);
 | 
					        const noteContext = new NoteContext(ntxId, hoistedNoteId, mainNtxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const existingNoteContext = this.children.find((nc) => nc.ntxId === noteContext.ntxId);
 | 
					        const existingNoteContext = this.children.find((nc) => nc.ntxId === noteContext.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (existingNoteContext) {
 | 
					        if (existingNoteContext) {
 | 
				
			||||||
            await existingNoteContext.setHoistedNoteId(hoistedNoteId);
 | 
					            await existingNoteContext.setHoistedNoteId(hoistedNoteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return existingNoteContext;
 | 
					            return existingNoteContext;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -278,40 +266,29 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        return noteContext;
 | 
					        return noteContext;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openInNewTab(targetNoteId: string, hoistedNoteId: string | null = null) {
 | 
					    async openInNewTab(targetNoteId, hoistedNoteId = null) {
 | 
				
			||||||
        const noteContext = await this.openEmptyTab(
 | 
					        const noteContext = await this.openEmptyTab(null, hoistedNoteId || this.getActiveContext().hoistedNoteId);
 | 
				
			||||||
            null,
 | 
					 | 
				
			||||||
            hoistedNoteId || this.getActiveContext()?.hoistedNoteId
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await noteContext.setNote(targetNoteId);
 | 
					        await noteContext.setNote(targetNoteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openInSameTab(targetNoteId: string, hoistedNoteId: string | null = null) {
 | 
					    async openInSameTab(targetNoteId, hoistedNoteId = null) {
 | 
				
			||||||
        const activeContext = this.getActiveContext();
 | 
					        const activeContext = this.getActiveContext();
 | 
				
			||||||
        if (!activeContext) return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        await activeContext.setHoistedNoteId(hoistedNoteId || activeContext.hoistedNoteId);
 | 
					        await activeContext.setHoistedNoteId(hoistedNoteId || activeContext.hoistedNoteId);
 | 
				
			||||||
        await activeContext.setNote(targetNoteId);
 | 
					        await activeContext.setNote(targetNoteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openTabWithNoteWithHoisting(
 | 
					    /**
 | 
				
			||||||
        notePath: string,
 | 
					     * If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab.
 | 
				
			||||||
        opts: {
 | 
					     */
 | 
				
			||||||
            activate?: boolean | null;
 | 
					    async openTabWithNoteWithHoisting(notePath, opts = {}) {
 | 
				
			||||||
            ntxId?: string | null;
 | 
					 | 
				
			||||||
            mainNtxId?: string | null;
 | 
					 | 
				
			||||||
            hoistedNoteId?: string | null;
 | 
					 | 
				
			||||||
            viewScope?: Record<string, any> | null;
 | 
					 | 
				
			||||||
        } = {}
 | 
					 | 
				
			||||||
    ): Promise<NoteContext> {
 | 
					 | 
				
			||||||
        const noteContext = this.getActiveContext();
 | 
					        const noteContext = this.getActiveContext();
 | 
				
			||||||
        let hoistedNoteId = "root";
 | 
					        let hoistedNoteId = "root";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (noteContext) {
 | 
					        if (noteContext) {
 | 
				
			||||||
            const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId);
 | 
					            const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (resolvedNotePath?.includes(noteContext.hoistedNoteId) || resolvedNotePath?.includes("_hidden")) {
 | 
					            if (resolvedNotePath.includes(noteContext.hoistedNoteId) || resolvedNotePath.includes("_hidden")) {
 | 
				
			||||||
                hoistedNoteId = noteContext.hoistedNoteId;
 | 
					                hoistedNoteId = noteContext.hoistedNoteId;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -321,16 +298,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        return this.openContextWithNote(notePath, opts);
 | 
					        return this.openContextWithNote(notePath, opts);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openContextWithNote(
 | 
					    async openContextWithNote(notePath, opts = {}) {
 | 
				
			||||||
        notePath: string | null,
 | 
					 | 
				
			||||||
        opts: {
 | 
					 | 
				
			||||||
            activate?: boolean | null;
 | 
					 | 
				
			||||||
            ntxId?: string | null;
 | 
					 | 
				
			||||||
            mainNtxId?: string | null;
 | 
					 | 
				
			||||||
            hoistedNoteId?: string | null;
 | 
					 | 
				
			||||||
            viewScope?: Record<string, any> | null;
 | 
					 | 
				
			||||||
        } = {}
 | 
					 | 
				
			||||||
    ): Promise<NoteContext> {
 | 
					 | 
				
			||||||
        const activate = !!opts.activate;
 | 
					        const activate = !!opts.activate;
 | 
				
			||||||
        const ntxId = opts.ntxId || null;
 | 
					        const ntxId = opts.ntxId || null;
 | 
				
			||||||
        const mainNtxId = opts.mainNtxId || null;
 | 
					        const mainNtxId = opts.mainNtxId || null;
 | 
				
			||||||
@@ -347,10 +315,10 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (activate && noteContext.notePath) {
 | 
					        if (activate) {
 | 
				
			||||||
            this.activateNoteContext(noteContext.ntxId, false);
 | 
					            this.activateNoteContext(noteContext.ntxId, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await this.triggerEvent("noteSwitchedAndActivatedEvent", {
 | 
					            await this.triggerEvent("noteSwitchedAndActivated", {
 | 
				
			||||||
                noteContext,
 | 
					                noteContext,
 | 
				
			||||||
                notePath: noteContext.notePath // resolved note path
 | 
					                notePath: noteContext.notePath // resolved note path
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
@@ -359,24 +327,21 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        return noteContext;
 | 
					        return noteContext;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async activateOrOpenNote(noteId: string) {
 | 
					    async activateOrOpenNote(noteId) {
 | 
				
			||||||
        for (const noteContext of this.getNoteContexts()) {
 | 
					        for (const noteContext of this.getNoteContexts()) {
 | 
				
			||||||
            if (noteContext.note && noteContext.note.noteId === noteId) {
 | 
					            if (noteContext.note && noteContext.note.noteId === noteId) {
 | 
				
			||||||
                this.activateNoteContext(noteContext.ntxId);
 | 
					                this.activateNoteContext(noteContext.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if no tab with this note has been found we'll create new tab
 | 
					        // if no tab with this note has been found we'll create new tab
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await this.openContextWithNote(noteId, { activate: true });
 | 
					        await this.openContextWithNote(noteId, { activate: true });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async activateNoteContext(ntxId: string | null, triggerEvent: boolean = true) {
 | 
					    async activateNoteContext(ntxId, triggerEvent = true) {
 | 
				
			||||||
        if (!ntxId) {
 | 
					 | 
				
			||||||
            logError("activateNoteContext: ntxId is null");
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (ntxId === this.activeNtxId) {
 | 
					        if (ntxId === this.activeNtxId) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -394,7 +359,11 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        this.setCurrentNavigationStateToHash();
 | 
					        this.setCurrentNavigationStateToHash();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async removeNoteContext(ntxId: string | null) {
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param ntxId
 | 
				
			||||||
 | 
					     * @returns {Promise<boolean>} true if note context has been removed, false otherwise
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    async removeNoteContext(ntxId) {
 | 
				
			||||||
        // removing note context is an async process which can take some time, if users presses CTRL-W quickly, two
 | 
					        // removing note context is an async process which can take some time, if users presses CTRL-W quickly, two
 | 
				
			||||||
        // close events could interleave which would then lead to attempting to activate already removed context.
 | 
					        // close events could interleave which would then lead to attempting to activate already removed context.
 | 
				
			||||||
        return await this.mutex.runExclusively(async () => {
 | 
					        return await this.mutex.runExclusively(async () => {
 | 
				
			||||||
@@ -404,7 +373,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                noteContextToRemove = this.getNoteContextById(ntxId);
 | 
					                noteContextToRemove = this.getNoteContextById(ntxId);
 | 
				
			||||||
            } catch {
 | 
					            } catch {
 | 
				
			||||||
                // note context not found
 | 
					                // note context not found
 | 
				
			||||||
                return;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (noteContextToRemove.isMainContext()) {
 | 
					            if (noteContextToRemove.isMainContext()) {
 | 
				
			||||||
@@ -414,7 +383,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                    if (noteContextToRemove.isEmpty()) {
 | 
					                    if (noteContextToRemove.isEmpty()) {
 | 
				
			||||||
                        // this is already the empty note context, no point in closing it and replacing with another
 | 
					                        // this is already the empty note context, no point in closing it and replacing with another
 | 
				
			||||||
                        // empty tab
 | 
					                        // empty tab
 | 
				
			||||||
                        return;
 | 
					                        return false;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    await this.openEmptyTab();
 | 
					                    await this.openEmptyTab();
 | 
				
			||||||
@@ -430,7 +399,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            const noteContextsToRemove = noteContextToRemove.getSubContexts();
 | 
					            const noteContextsToRemove = noteContextToRemove.getSubContexts();
 | 
				
			||||||
            const ntxIdsToRemove = noteContextsToRemove.map((nc) => nc.ntxId);
 | 
					            const ntxIdsToRemove = noteContextsToRemove.map((nc) => nc.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await this.triggerEvent("beforeNoteContextRemove", { ntxIds: ntxIdsToRemove.filter((id) => id !== null) });
 | 
					            await this.triggerEvent("beforeNoteContextRemove", { ntxIds: ntxIdsToRemove });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!noteContextToRemove.isMainContext()) {
 | 
					            if (!noteContextToRemove.isMainContext()) {
 | 
				
			||||||
                const siblings = noteContextToRemove.getMainContext().getSubContexts();
 | 
					                const siblings = noteContextToRemove.getMainContext().getSubContexts();
 | 
				
			||||||
@@ -452,10 +421,12 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.removeNoteContexts(noteContextsToRemove);
 | 
					            this.removeNoteContexts(noteContextsToRemove);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    removeNoteContexts(noteContextsToRemove: NoteContext[]) {
 | 
					    removeNoteContexts(noteContextsToRemove) {
 | 
				
			||||||
        const ntxIdsToRemove = noteContextsToRemove.map((nc) => nc.ntxId);
 | 
					        const ntxIdsToRemove = noteContextsToRemove.map((nc) => nc.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const position = this.noteContexts.findIndex((nc) => ntxIdsToRemove.includes(nc.ntxId));
 | 
					        const position = this.noteContexts.findIndex((nc) => ntxIdsToRemove.includes(nc.ntxId));
 | 
				
			||||||
@@ -464,12 +435,12 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.addToRecentlyClosedTabs(noteContextsToRemove, position);
 | 
					        this.addToRecentlyClosedTabs(noteContextsToRemove, position);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.triggerEvent("noteContextRemoved", { ntxIds: ntxIdsToRemove.filter((id) => id !== null) });
 | 
					        this.triggerEvent("noteContextRemoved", { ntxIds: ntxIdsToRemove });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.tabsUpdate.scheduleUpdate();
 | 
					        this.tabsUpdate.scheduleUpdate();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addToRecentlyClosedTabs(noteContexts: NoteContext[], position: number) {
 | 
					    addToRecentlyClosedTabs(noteContexts, position) {
 | 
				
			||||||
        if (noteContexts.length === 1 && noteContexts[0].isEmpty()) {
 | 
					        if (noteContexts.length === 1 && noteContexts[0].isEmpty()) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -477,42 +448,26 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        this.recentlyClosedTabs.push({ contexts: noteContexts, position: position });
 | 
					        this.recentlyClosedTabs.push({ contexts: noteContexts, position: position });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tabReorderEvent({ ntxIdsInOrder }: { ntxIdsInOrder: string[] }) {
 | 
					    tabReorderEvent({ ntxIdsInOrder }) {
 | 
				
			||||||
        const order: Record<string, number> = {};
 | 
					        const order = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let i = 0;
 | 
					        let i = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const ntxId of ntxIdsInOrder) {
 | 
					        for (const ntxId of ntxIdsInOrder) {
 | 
				
			||||||
            for (const noteContext of this.getNoteContextById(ntxId).getSubContexts()) {
 | 
					            for (const noteContext of this.getNoteContextById(ntxId).getSubContexts()) {
 | 
				
			||||||
                if (noteContext.ntxId) {
 | 
					 | 
				
			||||||
                order[noteContext.ntxId] = i++;
 | 
					                order[noteContext.ntxId] = i++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.children.sort((a, b) => {
 | 
					        this.children.sort((a, b) => (order[a.ntxId] < order[b.ntxId] ? -1 : 1));
 | 
				
			||||||
            if (!a.ntxId || !b.ntxId) return 0;
 | 
					 | 
				
			||||||
            return (order[a.ntxId] ?? 0) < (order[b.ntxId] ?? 0) ? -1 : 1;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.tabsUpdate.scheduleUpdate();
 | 
					        this.tabsUpdate.scheduleUpdate();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    noteContextReorderEvent({
 | 
					    noteContextReorderEvent({ ntxIdsInOrder, oldMainNtxId, newMainNtxId }) {
 | 
				
			||||||
        ntxIdsInOrder,
 | 
					 | 
				
			||||||
        oldMainNtxId,
 | 
					 | 
				
			||||||
        newMainNtxId
 | 
					 | 
				
			||||||
    }: {
 | 
					 | 
				
			||||||
        ntxIdsInOrder: string[];
 | 
					 | 
				
			||||||
        oldMainNtxId?: string;
 | 
					 | 
				
			||||||
        newMainNtxId?: string;
 | 
					 | 
				
			||||||
    }) {
 | 
					 | 
				
			||||||
        const order = Object.fromEntries(ntxIdsInOrder.map((v, i) => [v, i]));
 | 
					        const order = Object.fromEntries(ntxIdsInOrder.map((v, i) => [v, i]));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.children.sort((a, b) => {
 | 
					        this.children.sort((a, b) => (order[a.ntxId] < order[b.ntxId] ? -1 : 1));
 | 
				
			||||||
            if (!a.ntxId || !b.ntxId) return 0;
 | 
					 | 
				
			||||||
            return (order[a.ntxId] ?? 0) < (order[b.ntxId] ?? 0) ? -1 : 1;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (oldMainNtxId && newMainNtxId) {
 | 
					        if (oldMainNtxId && newMainNtxId) {
 | 
				
			||||||
            this.children.forEach((c) => {
 | 
					            this.children.forEach((c) => {
 | 
				
			||||||
@@ -530,8 +485,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async activateNextTabCommand() {
 | 
					    async activateNextTabCommand() {
 | 
				
			||||||
        const activeMainNtxId = this.getActiveMainContext()?.ntxId;
 | 
					        const activeMainNtxId = this.getActiveMainContext().ntxId;
 | 
				
			||||||
        if (!activeMainNtxId) return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const oldIdx = this.mainNoteContexts.findIndex((nc) => nc.ntxId === activeMainNtxId);
 | 
					        const oldIdx = this.mainNoteContexts.findIndex((nc) => nc.ntxId === activeMainNtxId);
 | 
				
			||||||
        const newActiveNtxId = this.mainNoteContexts[oldIdx === this.mainNoteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;
 | 
					        const newActiveNtxId = this.mainNoteContexts[oldIdx === this.mainNoteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;
 | 
				
			||||||
@@ -540,8 +494,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async activatePreviousTabCommand() {
 | 
					    async activatePreviousTabCommand() {
 | 
				
			||||||
        const activeMainNtxId = this.getActiveMainContext()?.ntxId;
 | 
					        const activeMainNtxId = this.getActiveMainContext().ntxId;
 | 
				
			||||||
        if (!activeMainNtxId) return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const oldIdx = this.mainNoteContexts.findIndex((nc) => nc.ntxId === activeMainNtxId);
 | 
					        const oldIdx = this.mainNoteContexts.findIndex((nc) => nc.ntxId === activeMainNtxId);
 | 
				
			||||||
        const newActiveNtxId = this.mainNoteContexts[oldIdx === 0 ? this.mainNoteContexts.length - 1 : oldIdx - 1].ntxId;
 | 
					        const newActiveNtxId = this.mainNoteContexts[oldIdx === 0 ? this.mainNoteContexts.length - 1 : oldIdx - 1].ntxId;
 | 
				
			||||||
@@ -550,13 +503,12 @@ export default class TabManager extends Component {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async closeActiveTabCommand() {
 | 
					    async closeActiveTabCommand() {
 | 
				
			||||||
        if (this.activeNtxId) {
 | 
					 | 
				
			||||||
        await this.removeNoteContext(this.activeNtxId);
 | 
					        await this.removeNoteContext(this.activeNtxId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    beforeUnloadEvent(): boolean {
 | 
					    beforeUnloadEvent() {
 | 
				
			||||||
        this.tabsUpdate.updateNowIfNecessary();
 | 
					        this.tabsUpdate.updateNowIfNecessary();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true; // don't block closing the tab, this metadata is not that important
 | 
					        return true; // don't block closing the tab, this metadata is not that important
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -566,39 +518,35 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async closeAllTabsCommand() {
 | 
					    async closeAllTabsCommand() {
 | 
				
			||||||
        for (const ntxIdToRemove of this.mainNoteContexts.map((nc) => nc.ntxId)) {
 | 
					        for (const ntxIdToRemove of this.mainNoteContexts.map((nc) => nc.ntxId)) {
 | 
				
			||||||
            if (ntxIdToRemove) {
 | 
					 | 
				
			||||||
            await this.removeNoteContext(ntxIdToRemove);
 | 
					            await this.removeNoteContext(ntxIdToRemove);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async closeOtherTabsCommand({ ntxId }: { ntxId: string }) {
 | 
					    async closeOtherTabsCommand({ ntxId }) {
 | 
				
			||||||
        for (const ntxIdToRemove of this.mainNoteContexts.map((nc) => nc.ntxId)) {
 | 
					        for (const ntxIdToRemove of this.mainNoteContexts.map((nc) => nc.ntxId)) {
 | 
				
			||||||
            if (ntxIdToRemove && ntxIdToRemove !== ntxId) {
 | 
					            if (ntxIdToRemove !== ntxId) {
 | 
				
			||||||
                await this.removeNoteContext(ntxIdToRemove);
 | 
					                await this.removeNoteContext(ntxIdToRemove);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async closeRightTabsCommand({ ntxId }: { ntxId: string }) {
 | 
					    async closeRightTabsCommand({ ntxId }) {
 | 
				
			||||||
        const ntxIds = this.mainNoteContexts.map((nc) => nc.ntxId);
 | 
					        const ntxIds = this.mainNoteContexts.map((nc) => nc.ntxId);
 | 
				
			||||||
        const index = ntxIds.indexOf(ntxId);
 | 
					        const index = ntxIds.indexOf(ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (index !== -1) {
 | 
					        if (index !== -1) {
 | 
				
			||||||
            const idsToRemove = ntxIds.slice(index + 1);
 | 
					            const idsToRemove = ntxIds.slice(index + 1);
 | 
				
			||||||
            for (const ntxIdToRemove of idsToRemove) {
 | 
					            for (const ntxIdToRemove of idsToRemove) {
 | 
				
			||||||
                if (ntxIdToRemove) {
 | 
					 | 
				
			||||||
                await this.removeNoteContext(ntxIdToRemove);
 | 
					                await this.removeNoteContext(ntxIdToRemove);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async closeTabCommand({ ntxId }: { ntxId: string }) {
 | 
					    async closeTabCommand({ ntxId }) {
 | 
				
			||||||
        await this.removeNoteContext(ntxId);
 | 
					        await this.removeNoteContext(ntxId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async moveTabToNewWindowCommand({ ntxId }: { ntxId: string }) {
 | 
					    async moveTabToNewWindowCommand({ ntxId }) {
 | 
				
			||||||
        const { notePath, hoistedNoteId } = this.getNoteContextById(ntxId);
 | 
					        const { notePath, hoistedNoteId } = this.getNoteContextById(ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const removed = await this.removeNoteContext(ntxId);
 | 
					        const removed = await this.removeNoteContext(ntxId);
 | 
				
			||||||
@@ -608,16 +556,17 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async copyTabToNewWindowCommand({ ntxId }: { ntxId: string }) {
 | 
					    async copyTabToNewWindowCommand({ ntxId }) {
 | 
				
			||||||
        const { notePath, hoistedNoteId } = this.getNoteContextById(ntxId);
 | 
					        const { notePath, hoistedNoteId } = this.getNoteContextById(ntxId);
 | 
				
			||||||
        this.triggerCommand("openInWindow", { notePath, hoistedNoteId });
 | 
					        this.triggerCommand("openInWindow", { notePath, hoistedNoteId });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async reopenLastTabCommand() {
 | 
					    async reopenLastTabCommand() {
 | 
				
			||||||
        const closeLastEmptyTab: NoteContext | undefined = await this.mutex.runExclusively(async () => {
 | 
					        let closeLastEmptyTab = null;
 | 
				
			||||||
            let closeLastEmptyTab
 | 
					
 | 
				
			||||||
 | 
					        await this.mutex.runExclusively(async () => {
 | 
				
			||||||
            if (this.recentlyClosedTabs.length === 0) {
 | 
					            if (this.recentlyClosedTabs.length === 0) {
 | 
				
			||||||
                return closeLastEmptyTab;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (this.noteContexts.length === 1 && this.noteContexts[0].isEmpty()) {
 | 
					            if (this.noteContexts.length === 1 && this.noteContexts[0].isEmpty()) {
 | 
				
			||||||
@@ -626,8 +575,6 @@ export default class TabManager extends Component {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const lastClosedTab = this.recentlyClosedTabs.pop();
 | 
					            const lastClosedTab = this.recentlyClosedTabs.pop();
 | 
				
			||||||
            if (!lastClosedTab) return closeLastEmptyTab;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            const noteContexts = lastClosedTab.contexts;
 | 
					            const noteContexts = lastClosedTab.contexts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (const noteContext of noteContexts) {
 | 
					            for (const noteContext of noteContexts) {
 | 
				
			||||||
@@ -642,26 +589,25 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                ...this.noteContexts.slice(-noteContexts.length),
 | 
					                ...this.noteContexts.slice(-noteContexts.length),
 | 
				
			||||||
                ...this.noteContexts.slice(lastClosedTab.position, -noteContexts.length)
 | 
					                ...this.noteContexts.slice(lastClosedTab.position, -noteContexts.length)
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
            this.noteContextReorderEvent({ ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId).filter((id) => id !== null) });
 | 
					            await this.noteContextReorderEvent({ ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId) });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let mainNtx = noteContexts.find((nc) => nc.isMainContext());
 | 
					            let mainNtx = noteContexts.find((nc) => nc.isMainContext());
 | 
				
			||||||
            if (mainNtx) {
 | 
					            if (mainNtx) {
 | 
				
			||||||
                // reopened a tab, need to reorder new tab widget in tab row
 | 
					                // reopened a tab, need to reorder new tab widget in tab row
 | 
				
			||||||
                await this.triggerEvent("contextsReopenedEvent", {
 | 
					                await this.triggerEvent("contextsReopened", {
 | 
				
			||||||
                    mainNtxId: mainNtx.ntxId,
 | 
					                    mainNtxId: mainNtx.ntxId,
 | 
				
			||||||
                    tabPosition: ntxsInOrder.filter((nc) => nc.isMainContext()).findIndex((nc) => nc.ntxId === mainNtx.ntxId)
 | 
					                    tabPosition: ntxsInOrder.filter((nc) => nc.isMainContext()).findIndex((nc) => nc.ntxId === mainNtx.ntxId)
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                // reopened a single split, need to reorder the pane widget in split note container
 | 
					                // reopened a single split, need to reorder the pane widget in split note container
 | 
				
			||||||
                await this.triggerEvent("contextsReopenedEvent", {
 | 
					                await this.triggerEvent("contextsReopened", {
 | 
				
			||||||
                    mainNtxId: ntxsInOrder[lastClosedTab.position].ntxId,
 | 
					                    ntxId: ntxsInOrder[lastClosedTab.position].ntxId,
 | 
				
			||||||
                    // this is safe since lastClosedTab.position can never be 0 in this case
 | 
					                    // this is safe since lastClosedTab.position can never be 0 in this case
 | 
				
			||||||
                    tabPosition: lastClosedTab.position - 1
 | 
					                    afterNtxId: ntxsInOrder[lastClosedTab.position - 1].ntxId
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const noteContextToActivate = noteContexts.length === 1 ? noteContexts[0] : noteContexts.find((nc) => nc.isMainContext());
 | 
					            const noteContextToActivate = noteContexts.length === 1 ? noteContexts[0] : noteContexts.find((nc) => nc.isMainContext());
 | 
				
			||||||
            if (!noteContextToActivate) return closeLastEmptyTab;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await this.activateNoteContext(noteContextToActivate.ntxId);
 | 
					            await this.activateNoteContext(noteContextToActivate.ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -669,7 +615,6 @@ export default class TabManager extends Component {
 | 
				
			|||||||
                noteContext: noteContextToActivate,
 | 
					                noteContext: noteContextToActivate,
 | 
				
			||||||
                notePath: noteContextToActivate.notePath
 | 
					                notePath: noteContextToActivate.notePath
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            return closeLastEmptyTab;
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (closeLastEmptyTab) {
 | 
					        if (closeLastEmptyTab) {
 | 
				
			||||||
@@ -681,9 +626,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        this.tabsUpdate.scheduleUpdate();
 | 
					        this.tabsUpdate.scheduleUpdate();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async updateDocumentTitle(activeNoteContext: NoteContext | null) {
 | 
					    async updateDocumentTitle(activeNoteContext) {
 | 
				
			||||||
        if (!activeNoteContext) return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const titleFragments = [
 | 
					        const titleFragments = [
 | 
				
			||||||
            // it helps to navigate in history if note title is included in the title
 | 
					            // it helps to navigate in history if note title is included in the title
 | 
				
			||||||
            await activeNoteContext.getNavigationTitle(),
 | 
					            await activeNoteContext.getNavigationTitle(),
 | 
				
			||||||
@@ -693,7 +636,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
        document.title = titleFragments.join(" - ");
 | 
					        document.title = titleFragments.join(" - ");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
 | 
					    async entitiesReloadedEvent({ loadResults }) {
 | 
				
			||||||
        const activeContext = this.getActiveContext();
 | 
					        const activeContext = this.getActiveContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (activeContext && loadResults.isNoteReloaded(activeContext.noteId)) {
 | 
					        if (activeContext && loadResults.isNoteReloaded(activeContext.noteId)) {
 | 
				
			||||||
@@ -703,6 +646,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async frocaReloadedEvent() {
 | 
					    async frocaReloadedEvent() {
 | 
				
			||||||
        const activeContext = this.getActiveContext();
 | 
					        const activeContext = this.getActiveContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (activeContext) {
 | 
					        if (activeContext) {
 | 
				
			||||||
            await this.updateDocumentTitle(activeContext);
 | 
					            await this.updateDocumentTitle(activeContext);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -22,19 +22,13 @@ function getItems(): MenuItem<CommandNames>[] {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function handleLinkContextMenuItem(command: string | undefined, notePath: string, viewScope = {}, hoistedNoteId: string | null = null) {
 | 
					function handleLinkContextMenuItem(command: string | undefined, notePath: string, viewScope = {}, hoistedNoteId: string | null = null) {
 | 
				
			||||||
    if (!hoistedNoteId) {
 | 
					    if (!hoistedNoteId) {
 | 
				
			||||||
        hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId ?? null;
 | 
					        hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (command === "openNoteInNewTab") {
 | 
					    if (command === "openNoteInNewTab") {
 | 
				
			||||||
        appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });
 | 
					        appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });
 | 
				
			||||||
    } else if (command === "openNoteInNewSplit") {
 | 
					    } else if (command === "openNoteInNewSplit") {
 | 
				
			||||||
        const subContexts = appContext.tabManager.getActiveContext()?.getSubContexts();
 | 
					        const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!subContexts) {
 | 
					 | 
				
			||||||
            logError("subContexts is null");
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const { ntxId } = subContexts[subContexts.length - 1];
 | 
					        const { ntxId } = subContexts[subContexts.length - 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });
 | 
					        appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -288,15 +288,11 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            const noteContext = ntxId ? appContext.tabManager.getNoteContextById(ntxId) : appContext.tabManager.getActiveContext();
 | 
					            const noteContext = ntxId ? appContext.tabManager.getNoteContextById(ntxId) : appContext.tabManager.getActiveContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (noteContext) {
 | 
					 | 
				
			||||||
            noteContext.setNote(notePath, { viewScope }).then(() => {
 | 
					            noteContext.setNote(notePath, { viewScope }).then(() => {
 | 
				
			||||||
                if (noteContext !== appContext.tabManager.getActiveContext()) {
 | 
					                if (noteContext !== appContext.tabManager.getActiveContext()) {
 | 
				
			||||||
                    appContext.tabManager.activateNoteContext(noteContext.ntxId);
 | 
					                    appContext.tabManager.activateNoteContext(noteContext.ntxId);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                appContext.tabManager.openContextWithNote(notePath, { viewScope, activate: true });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else if (hrefLink) {
 | 
					    } else if (hrefLink) {
 | 
				
			||||||
        const withinEditLink = $link?.hasClass("ck-link-actions__preview");
 | 
					        const withinEditLink = $link?.hasClass("ck-link-actions__preview");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -138,7 +138,7 @@ function getParentProtectedStatus(node: Fancytree.FancytreeNode) {
 | 
				
			|||||||
    return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;
 | 
					    return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getNoteIdFromUrl(urlOrNotePath: string | null | undefined) {
 | 
					function getNoteIdFromUrl(urlOrNotePath: string | undefined) {
 | 
				
			||||||
    if (!urlOrNotePath) {
 | 
					    if (!urlOrNotePath) {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@ export default class Mutex {
 | 
				
			|||||||
        return newPromise;
 | 
					        return newPromise;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async runExclusively(cb: () => Promise<any>) {
 | 
					    async runExclusively(cb: () => Promise<void>) {
 | 
				
			||||||
        const unlock = await this.lock();
 | 
					        const unlock = await this.lock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,7 +63,7 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
 | 
				
			|||||||
        hoistedNoteId?: string;
 | 
					        hoistedNoteId?: string;
 | 
				
			||||||
        viewScope?: any;
 | 
					        viewScope?: any;
 | 
				
			||||||
    }) {
 | 
					    }) {
 | 
				
			||||||
        const mainNtxId = appContext.tabManager.getActiveMainContext()?.ntxId;
 | 
					        const mainNtxId = appContext.tabManager.getActiveMainContext().ntxId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!mainNtxId) {
 | 
					        if (!mainNtxId) {
 | 
				
			||||||
            logError("empty mainNtxId!");
 | 
					            logError("empty mainNtxId!");
 | 
				
			||||||
@@ -76,7 +76,7 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
 | 
				
			|||||||
            ntxId = mainNtxId;
 | 
					            ntxId = mainNtxId;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        hoistedNoteId = hoistedNoteId || appContext.tabManager.getActiveContext()?.hoistedNoteId;
 | 
					        hoistedNoteId = hoistedNoteId || appContext.tabManager.getActiveContext().hoistedNoteId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const noteContext = await appContext.tabManager.openEmptyTab(null, hoistedNoteId, mainNtxId);
 | 
					        const noteContext = await appContext.tabManager.openEmptyTab(null, hoistedNoteId, mainNtxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
import Draggabilly, { type MoveVector } from "draggabilly";
 | 
					import Draggabilly, { type DraggabillyCallback, type MoveVector } from "draggabilly";
 | 
				
			||||||
import { t } from "../services/i18n.js";
 | 
					import { t } from "../services/i18n.js";
 | 
				
			||||||
import BasicWidget from "./basic_widget.js";
 | 
					import BasicWidget from "./basic_widget.js";
 | 
				
			||||||
import contextMenu from "../menus/context_menu.js";
 | 
					import contextMenu from "../menus/context_menu.js";
 | 
				
			||||||
import utils from "../services/utils.js";
 | 
					import utils from "../services/utils.js";
 | 
				
			||||||
import keyboardActionService from "../services/keyboard_actions.js";
 | 
					import keyboardActionService from "../services/keyboard_actions.js";
 | 
				
			||||||
import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js";
 | 
					import appContext, { type CommandData, type CommandListenerData, type EventData } from "../components/app_context.js";
 | 
				
			||||||
import froca from "../services/froca.js";
 | 
					import froca from "../services/froca.js";
 | 
				
			||||||
import attributeService from "../services/attributes.js";
 | 
					import attributeService from "../services/attributes.js";
 | 
				
			||||||
import type NoteContext from "../components/note_context.js";
 | 
					import type NoteContext from "../components/note_context.js";
 | 
				
			||||||
@@ -419,13 +419,13 @@ export default class TabRowWidget extends BasicWidget {
 | 
				
			|||||||
    closeActiveTabCommand({ $el }: CommandListenerData<"closeActiveTab">) {
 | 
					    closeActiveTabCommand({ $el }: CommandListenerData<"closeActiveTab">) {
 | 
				
			||||||
        const ntxId = $el.closest(".note-tab").attr("data-ntx-id");
 | 
					        const ntxId = $el.closest(".note-tab").attr("data-ntx-id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        appContext.tabManager.removeNoteContext(ntxId ?? null);
 | 
					        appContext.tabManager.removeNoteContext(ntxId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setTabCloseEvent($tab: JQuery<HTMLElement>) {
 | 
					    setTabCloseEvent($tab: JQuery<HTMLElement>) {
 | 
				
			||||||
        $tab.on("mousedown", (e) => {
 | 
					        $tab.on("mousedown", (e) => {
 | 
				
			||||||
            if (e.which === 2) {
 | 
					            if (e.which === 2) {
 | 
				
			||||||
                appContext.tabManager.removeNoteContext($tab.attr("data-ntx-id") ?? null);
 | 
					                appContext.tabManager.removeNoteContext($tab.attr("data-ntx-id"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return true; // event has been handled
 | 
					                return true; // event has been handled
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -494,7 +494,7 @@ export default class TabRowWidget extends BasicWidget {
 | 
				
			|||||||
        return $tab.attr("data-ntx-id");
 | 
					        return $tab.attr("data-ntx-id");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    noteContextRemovedEvent({ ntxIds }: EventData<"noteContextRemoved">) {
 | 
					    noteContextRemovedEvent({ ntxIds }: EventData<"noteContextRemovedEvent">) {
 | 
				
			||||||
        for (const ntxId of ntxIds) {
 | 
					        for (const ntxId of ntxIds) {
 | 
				
			||||||
            this.removeTab(ntxId);
 | 
					            this.removeTab(ntxId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -650,7 +650,7 @@ export default class TabRowWidget extends BasicWidget {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    contextsReopenedEvent({ mainNtxId, tabPosition }: EventData<"contextsReopenedEvent">) {
 | 
					    contextsReopenedEvent({ mainNtxId, tabPosition }: EventData<"contextsReopenedEvent">) {
 | 
				
			||||||
        if (!mainNtxId || !tabPosition) {
 | 
					        if (mainNtxId === undefined || tabPosition === undefined) {
 | 
				
			||||||
            // no tab reopened
 | 
					            // no tab reopened
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -748,7 +748,7 @@ export default class TabRowWidget extends BasicWidget {
 | 
				
			|||||||
    hoistedNoteChangedEvent({ ntxId }: EventData<"hoistedNoteChanged">) {
 | 
					    hoistedNoteChangedEvent({ ntxId }: EventData<"hoistedNoteChanged">) {
 | 
				
			||||||
        const $tab = this.getTabById(ntxId);
 | 
					        const $tab = this.getTabById(ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($tab && ntxId) {
 | 
					        if ($tab) {
 | 
				
			||||||
            const noteContext = appContext.tabManager.getNoteContextById(ntxId);
 | 
					            const noteContext = appContext.tabManager.getNoteContextById(ntxId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.updateTab($tab, noteContext);
 | 
					            this.updateTab($tab, noteContext);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user