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 type { NoteType } from "../../entities/fnote.js";
import { t } from "../../services/i18n.js";
import type { ViewScope } from "../../services/link.js";
import NoteContextAwareWidget from "../note_context_aware_widget.js";
const TPL = `
@ -51,15 +52,24 @@ export default class ContextualHelpButton extends NoteContextAwareWidget {
this.$widget = $(TPL);
this.$widget.on("click", () => {
const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
const { ntxId } = subContexts[subContexts.length - 1];
this.triggerCommand("openNewNoteSplit", {
ntxId,
notePath: `_help_${this.helpNoteIdToOpen}`,
hoistedNoteId: "_help",
viewScope: {
viewMode: "contextual-help"
}
})
const targetNote = `_help_${this.helpNoteIdToOpen}`;
const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");
const viewScope: ViewScope = {
viewMode: "contextual-help",
};
if (!helpSubcontext) {
// 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 });
}
});
}