feat(in_app_help): reuse contextual help if possible

This commit is contained in:
Elian Doran 2025-02-03 22:50:00 +02:00
parent c649f473b4
commit 6953928f7a
No known key found for this signature in database

View File

@ -1,6 +1,7 @@
import appContext from "../../components/app_context.js"; import appContext from "../../components/app_context.js";
import type { NoteType } from "../../entities/fnote.js"; import type { NoteType } from "../../entities/fnote.js";
import { t } from "../../services/i18n.js"; import { t } from "../../services/i18n.js";
import type { ViewScope } from "../../services/link.js";
import NoteContextAwareWidget from "../note_context_aware_widget.js"; import NoteContextAwareWidget from "../note_context_aware_widget.js";
const TPL = ` const TPL = `
@ -51,15 +52,24 @@ export default class ContextualHelpButton extends NoteContextAwareWidget {
this.$widget = $(TPL); this.$widget = $(TPL);
this.$widget.on("click", () => { this.$widget.on("click", () => {
const subContexts = appContext.tabManager.getActiveContext().getSubContexts(); const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
const { ntxId } = subContexts[subContexts.length - 1]; const targetNote = `_help_${this.helpNoteIdToOpen}`;
this.triggerCommand("openNewNoteSplit", { const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");
ntxId, const viewScope: ViewScope = {
notePath: `_help_${this.helpNoteIdToOpen}`, viewMode: "contextual-help",
hoistedNoteId: "_help", };
viewScope: { if (!helpSubcontext) {
viewMode: "contextual-help" // The help is not already open, open a new split with it.
} const { ntxId } = subContexts[subContexts.length - 1];
}) this.triggerCommand("openNewNoteSplit", {
ntxId,
notePath: targetNote,
hoistedNoteId: "_help",
viewScope
})
} else {
// There is already a help window open, make sure it opens on the right note.
helpSubcontext.setNote(targetNote, { viewScope });
}
}); });
} }