mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 10:24:23 +01:00
chore(note_map): open in reusable split
This commit is contained in:
parent
726d6aad65
commit
24cd5006d5
@ -6,7 +6,7 @@ import openService from "../services/open.js";
|
|||||||
import protectedSessionService from "../services/protected_session.js";
|
import protectedSessionService from "../services/protected_session.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 utils from "../services/utils.js";
|
import utils, { openInReusableSplit } from "../services/utils.js";
|
||||||
import toastService from "../services/toast.js";
|
import toastService from "../services/toast.js";
|
||||||
import noteCreateService from "../services/note_create.js";
|
import noteCreateService from "../services/note_create.js";
|
||||||
|
|
||||||
@ -199,14 +199,8 @@ export default class RootCommandExecutor extends Component {
|
|||||||
if (!isNewLayout) return;
|
if (!isNewLayout) return;
|
||||||
|
|
||||||
const activeContext = appContext.tabManager.getActiveContext();
|
const activeContext = appContext.tabManager.getActiveContext();
|
||||||
if (!activeContext) return;
|
if (!activeContext?.notePath) return;
|
||||||
|
openInReusableSplit(activeContext.notePath, "note-map");
|
||||||
const subContexts = activeContext.getSubContexts();
|
|
||||||
appContext.triggerCommand("openNewNoteSplit", {
|
|
||||||
ntxId: subContexts[subContexts.length - 1].ntxId,
|
|
||||||
notePath: activeContext.notePath,
|
|
||||||
viewScope: { viewMode: "note-map" }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
firstTabCommand() {
|
firstTabCommand() {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { dayjs } from "@triliumnext/commons";
|
import { dayjs } from "@triliumnext/commons";
|
||||||
import type { ViewScope } from "./link.js";
|
import type { ViewMode, ViewScope } from "./link.js";
|
||||||
import FNote from "../entities/fnote";
|
import FNote from "../entities/fnote";
|
||||||
import { snapdom } from "@zumer/snapdom";
|
import { snapdom } from "@zumer/snapdom";
|
||||||
|
|
||||||
@ -439,7 +439,20 @@ async function openInAppHelp($button: JQuery<HTMLElement>) {
|
|||||||
* @param inAppHelpPage the ID of the help note (excluding the `_help_` prefix).
|
* @param inAppHelpPage the ID of the help note (excluding the `_help_` prefix).
|
||||||
* @returns a promise that resolves once the help has been opened.
|
* @returns a promise that resolves once the help has been opened.
|
||||||
*/
|
*/
|
||||||
export async function openInAppHelpFromUrl(inAppHelpPage: string) {
|
export function openInAppHelpFromUrl(inAppHelpPage: string) {
|
||||||
|
return openInReusableSplit(`_help_${inAppHelpPage}`, "contextual-help");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to opening a new note in a split, but re-uses an existing split if there is already one open with the same view mode.
|
||||||
|
*
|
||||||
|
* @param targetNoteId the note ID to open in the split.
|
||||||
|
* @param targetViewMode the view mode of the split to open the note in.
|
||||||
|
* @param openOpts additional options for opening the note.
|
||||||
|
*/
|
||||||
|
export async function openInReusableSplit(targetNoteId: string, targetViewMode: ViewMode, openOpts: {
|
||||||
|
hoistedNoteId?: string;
|
||||||
|
} = {}) {
|
||||||
// Dynamic import to avoid import issues in tests.
|
// Dynamic import to avoid import issues in tests.
|
||||||
const appContext = (await import("../components/app_context.js")).default;
|
const appContext = (await import("../components/app_context.js")).default;
|
||||||
const activeContext = appContext.tabManager.getActiveContext();
|
const activeContext = appContext.tabManager.getActiveContext();
|
||||||
@ -447,23 +460,20 @@ export async function openInAppHelpFromUrl(inAppHelpPage: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const subContexts = activeContext.getSubContexts();
|
const subContexts = activeContext.getSubContexts();
|
||||||
const targetNote = `_help_${inAppHelpPage}`;
|
const existingSubcontext = subContexts.find((s) => s.viewScope?.viewMode === targetViewMode);
|
||||||
const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");
|
const viewScope: ViewScope = { viewMode: targetViewMode };
|
||||||
const viewScope: ViewScope = {
|
if (!existingSubcontext) {
|
||||||
viewMode: "contextual-help",
|
// The target split is not already open, open a new split with it.
|
||||||
};
|
|
||||||
if (!helpSubcontext) {
|
|
||||||
// The help is not already open, open a new split with it.
|
|
||||||
const { ntxId } = subContexts[subContexts.length - 1];
|
const { ntxId } = subContexts[subContexts.length - 1];
|
||||||
appContext.triggerCommand("openNewNoteSplit", {
|
appContext.triggerCommand("openNewNoteSplit", {
|
||||||
ntxId,
|
ntxId,
|
||||||
notePath: targetNote,
|
notePath: targetNoteId,
|
||||||
hoistedNoteId: "_help",
|
hoistedNoteId: openOpts.hoistedNoteId,
|
||||||
viewScope
|
viewScope
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// There is already a help window open, make sure it opens on the right note.
|
// There is already a target split open, make sure it opens on the right note.
|
||||||
helpSubcontext.setNote(targetNote, { viewScope });
|
existingSubcontext.setNote(targetNoteId, { viewScope });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user