mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-12 20:02:28 +08:00
feat(in_app_help): reuse contextual help if possible
This commit is contained in:
parent
c649f473b4
commit
6953928f7a
@ -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 });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user