Skip to content

Build your personal knowledge base with Trilium Notes

feat(dialogs): open help in quick edit

Elian Doranc56cad147922
diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.ts
index 680e982678..c897db0cee 100644
--- a/apps/client/src/components/note_context.ts
+++ b/apps/client/src/components/note_context.ts
@@ -19,6 +19,8 @@ import Component from "./component.js";
export interface SetNoteOpts {
triggerSwitchEvent?: unknown;
viewScope?: ViewScope;
+ /** If true, skip closing the currently active dialog. Used when opening a note into a stackable popup (e.g. quick-edit) that must not dismiss the dialog it was launched from. */
+ keepActiveDialog?: boolean;
}
export type GetTextEditorCallback = (editor: CKTextEditor) => void;
@@ -127,7 +129,9 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">
await this.triggerEvent("beforeNoteSwitch", { noteContext: this });
- closeActiveDialog();
+ if (!opts.keepActiveDialog) {
+ closeActiveDialog();
+ }
this.notePath = resolvedNotePath;
this.viewScope = opts.viewScope;
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.css b/apps/client/src/widgets/dialogs/PopupEditor.css
index c1f5c7b2a3..d68c3cab88 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.css
+++ b/apps/client/src/widgets/dialogs/PopupEditor.css
@@ -1,7 +1,14 @@
/** Reduce the z-index of modals so that ckeditor popups are properly shown on top of it. */
-body.popup-editor-open > .modal-backdrop { z-index: 998; }
-body.popup-editor-open .popup-editor-dialog { z-index: 999; }
-body.popup-editor-open .ck-clipboard-drop-target-line { z-index: 1000; }
+body.popup-editor-open:not(.popup-editor-stacked) > .modal-backdrop { z-index: 998; }
+body.popup-editor-open:not(.popup-editor-stacked) .popup-editor-dialog { z-index: 999; }
+body.popup-editor-open:not(.popup-editor-stacked) .ck-clipboard-drop-target-line { z-index: 1000; }
+
+/** When stacked on top of another Bootstrap modal (e.g. opened from a dialog's help button),
+ raise the popup and its own backdrop above the underlying modal (Bootstrap defaults are
+ backdrop 1050, dialog 1055 — no native stacking increment). */
+body.popup-editor-stacked .popup-editor-dialog { z-index: 1100; }
+body.popup-editor-stacked .ck-clipboard-drop-target-line { z-index: 1101; }
+.modal-backdrop.popup-editor-backdrop { z-index: 1099; }
body.desktop .modal.popup-editor-dialog .modal-dialog {
max-width: 75vw;
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index 92851ddc93..851cefcbad 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx
@@ -30,6 +30,7 @@ const isNewLayout = isExperimentalFeatureEnabled("new-layout");
export default function PopupEditor() {
const [ shown, setShown ] = useState(false);
+ const [ stacked, setStacked ] = useState(false);
const parentComponent = useContext(ParentComponent);
const [ noteContext, setNoteContext ] = useState(new NoteContext("_popup-editor"));
const isMobile = utils.isMobile();
@@ -40,6 +41,7 @@ export default function PopupEditor() {
useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => {
const noteContext = new NoteContext("_popup-editor");
+ setStacked(!!document.querySelector(".modal.show"));
const noteId = tree.getNoteIdAndParentIdFromUrl(noteIdOrPath);
if (!noteId.noteId) return;
@@ -51,7 +53,8 @@ export default function PopupEditor() {
viewScope: {
// Override auto-readonly notes to be editable, but respect user's choice to have a read-only note.
readOnlyTemporarilyDisabled: !hasUserSetNoteReadOnly
- }
+ },
+ keepActiveDialog: true
});
// Events triggered at note context level (e.g. the save indicator) would not work since the note context has no parent component. Propagate events to parent component so that they can be handled properly.
@@ -63,7 +66,20 @@ export default function PopupEditor() {
// Add a global class to be able to handle issues with z-index due to rendering in a popup.
useEffect(() => {
document.body.classList.toggle("popup-editor-open", shown);
- }, [shown]);
+ document.body.classList.toggle("popup-editor-stacked", shown && stacked);
+ }, [shown, stacked]);
+
+ // When stacked on top of another modal, raise this popup's own backdrop above
+ // the underlying modal. Bootstrap does not auto-increment z-index for stacked
+ // modals, and the appended `.modal-backdrop` is not individually addressable.
+ useEffect(() => {
+ if (!shown || !stacked) return;
+ const backdrops = document.querySelectorAll(".modal-backdrop");
+ const popupBackdrop = backdrops[backdrops.length - 1] as HTMLElement | undefined;
+ if (!popupBackdrop) return;
+ popupBackdrop.classList.add("popup-editor-backdrop");
+ return () => popupBackdrop.classList.remove("popup-editor-backdrop");
+ }, [shown, stacked]);
return (
<NoteContextContext.Provider value={noteContext}>
diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsx
index f84bac3222..e7c7bce89f 100644
--- a/apps/client/src/widgets/react/Modal.tsx
+++ b/apps/client/src/widgets/react/Modal.tsx
@@ -3,6 +3,7 @@ import clsx from "clsx";
import { ComponentChildren, CSSProperties, RefObject } from "preact";
import { useEffect, useMemo, useRef } from "preact/hooks";
+import appContext from "../../components/app_context";
import { openDialog } from "../../services/dialog";
import { t } from "../../services/i18n";
import { useSyncedRef } from "./hooks";
@@ -170,7 +171,12 @@ export default function Modal({ children, className, size, title, customTitleBar
)}
{header}
{helpPageId && (
- <button className="help-button" type="button" data-in-app-help={helpPageId} title={t("modal.help_title")}>?</button>
+ <button
+ className="help-button"
+ type="button"
+ title={t("modal.help_title")}
+ onClick={() => appContext.triggerCommand("openInPopup", { noteIdOrPath: `_help_${helpPageId}` })}
+ >?</button>
)}
{titleBarButtons?.filter((b) => b !== null).map((titleBarButton) => (