Skip to content

Build your personal knowledge base with Trilium Notes

feat(text): let a narrow view ask for the floating toolbar

Elian Doran8cc0b907d9a0
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index 0cc966afc8..0fd38c7b38 100644
--- a/apps/client/src/services/link.ts
+++ b/apps/client/src/services/link.ts
@@ -49,6 +49,14 @@ export interface ViewScope {
* to immediately enter read-only mode.
*/
isReadOnly?: boolean;
+ /**
+ * If true, a text note is edited with the floating toolbar whatever the user's editor-type
+ * option says — the toolbar following the selection rather than standing in a bar of its own.
+ *
+ * For views too narrow to carry a full toolbar, such as the geo map's marker pane: a classic bar
+ * built for the width of a note either spills out of them or eats the room the note is left.
+ */
+ floatingToolbar?: boolean;
highlightsListPreviousVisible?: boolean;
highlightsListTemporarilyHidden?: boolean;
tocTemporarilyHidden?: boolean;
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.css
index ecb0c82063..848b190812 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.css
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css
@@ -65,17 +65,6 @@
min-height: 0;
}
-/*
- * The editor's own toolbar, lifted out of it by the ribbon component. It is built for the width of a
- * note and this pane has a third of that, so it is left to scroll sideways rather than to push the
- * pane wider or spill over its edge.
- */
-.geo-map-container .geo-detail-pane .classic-toolbar-outer-container {
- flex-shrink: 0;
- overflow-x: auto;
- background-color: transparent;
-}
-
/*
* The ways of opening the note, at the head of the pane. Named by tooltips rather than labels, as
* every other row of actions in a panel is: labels would wrap four buttons onto two lines here.
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index eeb155eac3..2faaae3d12 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -30,15 +30,19 @@ vi.mock("../../../components/note_context", async (importOriginal) => ({
const editorAskedToSave = vi.fn();
vi.mock("../../NoteDetail", () => ({
default: () => {
- const { note } = useNoteContext();
+ const { note, viewScope } = useNoteContext();
useTriliumEvent("beforeNoteContextRemove", editorAskedToSave);
- return <div className="note-detail-stub">{note?.title}</div>;
+ return (
+ <div
+ className="note-detail-stub"
+ data-floating-toolbar={String(!!viewScope?.floatingToolbar)}
+ >
+ {note?.title}
+ </div>
+ );
}
}));
-// The formatting toolbar reaches for the editor it belongs to, which the stand-in above is not.
-vi.mock("../../ribbon/components/StandaloneRibbonAdapter", () => ({ default: () => null }));
-
/** What a marker click hands the handler, and what the pane reads the note out of. */
type Listener = (e?: unknown) => void;
@@ -364,6 +368,14 @@ describe("DetailPane", () => {
expect(pane()?.querySelector(".note-detail-stub")?.textContent).toBe("Somewhere");
});
+ /** A toolbar built for the width of a note does not fit a pane a third that wide. */
+ it("is asked for the floating toolbar rather than a bar of its own", async () => {
+ const map = fakeMap();
+ await openPane(map);
+
+ expect(pane()?.querySelector(".note-detail-stub")?.getAttribute("data-floating-toolbar")).toBe("true");
+ });
+
/**
* Switching markers announces a note switch the editor saves on, but closing the pane
* announces nothing — the widgets are only unmounted — so the pane says it itself.
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index 5d9bf277c3..e420f9892d 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -15,8 +15,6 @@ import ActionButton from "../../react/ActionButton";
import { useNoteLabel } from "../../react/hooks";
import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";
import { NoteContextContext, ParentComponent } from "../../react/react_utils";
-import StandaloneRibbonAdapter from "../../ribbon/components/StandaloneRibbonAdapter";
-import FormattingToolbar, { showFormattingToolbar } from "../../ribbon/FormattingToolbar";
import { moveMarker } from "./api";
import { ParentMap } from "./map";
import { LOCATION_ATTRIBUTE, MARKER_LAYER, parseLocation } from "./Markers";
@@ -160,9 +158,8 @@ function MarkerDetails({ note, isReadOnly, onClose }: { note: FNote; isReadOnly:
{/* The note itself, drawn by whichever widget its type calls for — the same one the
quick editor mounts, so a marker is written in exactly as it is anywhere else.
- The toolbar is the editor's own, lifted out of it by the ribbon component the
- quick editor borrows for the same reason. */}
- <StandaloneRibbonAdapter component={FormattingToolbar} show={showFormattingToolbar} />
+ No toolbar stands beside it: the pane asks for the floating one, which the editor
+ carries with it (see the view scope below). */}
<NoteDetail />
</OverlayPanelBody>
</OverlayPanel>
@@ -215,9 +212,14 @@ function usePaneNoteContext(note: FNote | undefined) {
void noteContext.setNote(notePath, {
// Selecting a marker is not the kind of navigation that should dismiss an open dialog.
keepActiveDialog: true,
- // A note held read-only only because of its size is editable here, as it is in the quick
- // editor; one the reader has marked read-only stays that way.
- viewScope: { readOnlyTemporarilyDisabled: !note.hasLabel("readOnly") }
+ viewScope: {
+ // A note held read-only only because of its size is editable here, as it is in the
+ // quick editor; one the reader has marked read-only stays that way.
+ readOnlyTemporarilyDisabled: !note.hasLabel("readOnly"),
+ // The pane has a third of a note's width, which is not a toolbar's worth: the
+ // editor's own follows the selection instead of standing in a bar (see link.ts).
+ floatingToolbar: true
+ }
});
}, [ noteContext, note?.noteId ]);
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index 6c799437f2..1604862c3f 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -18,6 +18,7 @@ import { TypeWidgetProps } from "../type_widget";
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
import getTemplates, { updateTemplateCache } from "./snippets.js";
import linkEmbedService from "../../../services/link_embed";
+import { usesClassicToolbar } from "./toolbar";
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
/**
@@ -35,7 +36,11 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
const [ textNoteEditorType ] = useTriliumOption("textNoteEditorType");
const [ codeBlockWordWrap ] = useTriliumOptionBool("codeBlockWordWrap");
const [ codeBlockTabWidth ] = useTriliumOption("codeBlockTabWidth");
- const isClassicEditor = isMobile() || textNoteEditorType === "ckeditor-classic";
+ const isClassicEditor = usesClassicToolbar({
+ floatingToolbarRequested: noteContext?.viewScope?.floatingToolbar,
+ isMobile: isMobile(),
+ textNoteEditorType
+ });
const initialized = useRef(deferred<void>());
const spacedUpdate = useEditorSpacedUpdate({
note,
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
index 35fa0996c7..d047f7e97c 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import { buildClassicToolbar, buildFloatingToolbar, buildMobileToolbar, buildToolbarConfig } from "./toolbar.js";
+import { buildClassicToolbar, buildFloatingToolbar, buildMobileToolbar, buildToolbarConfig, usesClassicToolbar } from "./toolbar.js";
type ToolbarConfig = string | "|" | { items: ToolbarConfig[] };
@@ -130,3 +130,34 @@ describe("buildToolbarConfig dispatch", () => {
expect("blockToolbar" in config).toBe(true);
});
});
+
+/**
+ * Which of the two toolbars a text note is edited with. Three things have a say and they do not
+ * carry equal weight, which is the whole of what this settles.
+ */
+describe("usesClassicToolbar", () => {
+ it("follows the reader's option on a desktop that has asked for nothing else", () => {
+ expect(usesClassicToolbar({ isMobile: false, textNoteEditorType: "ckeditor-classic" })).toBe(true);
+ expect(usesClassicToolbar({ isMobile: false, textNoteEditorType: "ckeditor-balloon" })).toBe(false);
+ });
+
+ // A balloon is hard to reach around a virtual keyboard, so the option does not apply there.
+ it("keeps the classic bar on a phone whatever the option says", () => {
+ expect(usesClassicToolbar({ isMobile: true, textNoteEditorType: "ckeditor-balloon" })).toBe(true);
+ });
+
+ // A bar built for the width of a note fits no narrow view, on any device.
+ it("gives way to a view that has asked for the floating toolbar, option and device alike", () => {
+ expect(usesClassicToolbar({
+ floatingToolbarRequested: true,
+ isMobile: false,
+ textNoteEditorType: "ckeditor-classic"
+ })).toBe(false);
+
+ expect(usesClassicToolbar({
+ floatingToolbarRequested: true,
+ isMobile: true,
+ textNoteEditorType: "ckeditor-classic"
+ })).toBe(false);
+ });
+});
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.ts b/apps/client/src/widgets/type_widgets/text/toolbar.ts
index 5212d24327..b2e0524549 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.ts
@@ -3,6 +3,28 @@ import options from "../../../services/options.js";
import { t } from "../../../services/i18n.js";
import { IconAlignCenter } from "@ckeditor/ckeditor5-icons";
+/**
+ * Whether a text note is edited with the classic toolbar — a bar standing above the note — rather
+ * than the floating one, which follows the selection.
+ *
+ * Three things have a say, in this order. A view narrow enough to have asked for the floating
+ * toolbar gets it whatever else is true (the geo map's marker pane; see `floatingToolbar` in
+ * link.ts): a bar built for the width of a note fits none of them, on any device. Failing that a
+ * phone always gets the classic bar, a balloon being hard to reach around a virtual keyboard. And
+ * failing that it is the reader's own option.
+ */
+export function usesClassicToolbar({ floatingToolbarRequested, isMobile, textNoteEditorType }: {
+ floatingToolbarRequested?: boolean;
+ isMobile: boolean;
+ textNoteEditorType: string;
+}) {
+ if (floatingToolbarRequested) {
+ return false;
+ }
+
+ return isMobile || textNoteEditorType === "ckeditor-classic";
+}
+
export function buildToolbarConfig(isClassicToolbar: boolean) {
if (utils.isMobile()) {
return buildMobileToolbar();