Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): wrong context activation logic when creating new split

Elian Doran8c848a4cb589
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 90adc404f6..e94249741b 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -2639,10 +2639,10 @@ iframe.print-iframe {
}
}
- /* #root-widget.virtual-keyboard-opened .note-split:not(:focus-within) {
+ #root-widget.virtual-keyboard-opened .note-split:not(.active) {
max-height: 80px;
opacity: 0.4;
- } */
+ }
}
}
diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
index dc0c5e89cd..358a61ffc3 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
@@ -1,4 +1,5 @@
-import { createPortal, useState } from "preact/compat";
+import { Dropdown as BootstrapDropdown } from "bootstrap";
+import { createPortal, useRef, useState } from "preact/compat";
import FNote, { NotePathRecord } from "../../entities/fnote";
import { t } from "../../services/i18n";
@@ -13,6 +14,7 @@ import NoteActionsCustom from "../ribbon/NoteActionsCustom";
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
export default function MobileDetailMenu() {
+ const dropdownRef = useRef<BootstrapDropdown | null>(null);
const { note, noteContext, parentComponent, ntxId, viewScope, hoistedNoteId } = useNoteContext();
const subContexts = noteContext?.getMainContext().getSubContexts() ?? [];
const isMainContext = noteContext?.isMainContext();
@@ -32,6 +34,7 @@ export default function MobileDetailMenu() {
<div style={{ contain: "none" }}>
{note ? (
<NoteContextMenu
+ dropdownRef={dropdownRef}
note={note} noteContext={noteContext}
extraItems={<>
<div className="form-list-row">
@@ -60,7 +63,12 @@ export default function MobileDetailMenu() {
{subContexts.length < 2 && <>
<FormDropdownDivider />
<FormListItem
- onClick={() => parentComponent.triggerCommand("openNewNoteSplit", { ntxId })}
+ onClick={(e) => {
+ // We have to manually manage the hide because otherwise the old note context gets activated.
+ e.stopPropagation();
+ dropdownRef.current?.hide();
+ parentComponent.triggerCommand("openNewNoteSplit", { ntxId });
+ }}
icon="bx bx-dock-right"
>{t("create_pane_button.create_new_split")}</FormListItem>
</>}
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index 51788085d2..daeab278cc 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -22,7 +22,7 @@ import MovePaneButton from "../buttons/move_pane_button";
import ActionButton from "../react/ActionButton";
import Dropdown from "../react/Dropdown";
import { FormDropdownDivider, FormDropdownSubmenu, FormListHeader, FormListItem, FormListToggleableItem } from "../react/FormList";
-import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumOption } from "../react/hooks";
+import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption } from "../react/hooks";
import { ParentComponent } from "../react/react_utils";
import { NoteTypeDropdownContent, useNoteBookmarkState, useShareState } from "./BasicPropertiesTab";
import NoteActionsCustom from "./NoteActionsCustom";
@@ -63,8 +63,13 @@ function RevisionsButton({ note }: { note: FNote }) {
type ItemToFocus = "basic-properties";
-export function NoteContextMenu({ note, noteContext, extraItems }: { note: FNote, noteContext?: NoteContext, extraItems?: ComponentChildren; }) {
- const dropdownRef = useRef<BootstrapDropdown>(null);
+export function NoteContextMenu({ note, noteContext, extraItems, dropdownRef: externalDropdownRef }: {
+ note: FNote,
+ noteContext?: NoteContext,
+ extraItems?: ComponentChildren;
+ dropdownRef?: RefObject<BootstrapDropdown>;
+}) {
+ const dropdownRef = useSyncedRef<BootstrapDropdown>(externalDropdownRef, null);
const parentComponent = useContext(ParentComponent);
const noteType = useNoteProperty(note, "type") ?? "";
const [viewType] = useNoteLabel(note, "viewType");