Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): drop the inline title and type switcher on code notes
Elian Dorane96da8e85108
diff --git a/apps/client/src/widgets/layout/InlineTitle.spec.ts b/apps/client/src/widgets/layout/InlineTitle.spec.tsnew file mode 100644index 0000000000..44caf7007c--- /dev/null+++ b/apps/client/src/widgets/layout/InlineTitle.spec.ts@@ -0,0 +1,16 @@+import { describe, expect, it } from "vitest";++import { buildNote } from "../../test/easy-froca";+import { shouldShowInlineTitle } from "./InlineTitle";++describe("shouldShowInlineTitle", () => {+ const viewScope = { viewMode: "default" } as const;++ it("carries text notes only, since a code note fills the pane and scrolls its own editor", () => {+ const textNote = buildNote({ title: "Note", type: "text" });+ const codeNote = buildNote({ title: "Script", type: "code", mime: "application/javascript;env=backend" });++ expect(shouldShowInlineTitle(textNote, "text", viewScope)).toBe(true);+ expect(shouldShowInlineTitle(codeNote, "code", viewScope)).toBe(false);+ });+});diff --git a/apps/client/src/widgets/layout/InlineTitle.tsx b/apps/client/src/widgets/layout/InlineTitle.tsxindex 806b9455eb..9f211cb75c 100644--- a/apps/client/src/widgets/layout/InlineTitle.tsx+++ b/apps/client/src/widgets/layout/InlineTitle.tsx@@ -17,21 +17,17 @@ import { useNoteContext, useNoteProperty, useStaticTooltip } from "../react/hookimport { joinElements } from "../react/react_utils";import { useNoteMetadata } from "../ribbon/NoteInfoTab";-const supportedNoteTypes = new Set<NoteType>([- "text", "code"-]);-export default function InlineTitle() {const { note, parentComponent, viewScope } = useNoteContext();const type = useNoteProperty(note, "type");const mime = useNoteProperty(note, "mime");const isOptions = note?.noteId?.startsWith("_options") ?? false;- const [ shown, setShown ] = useState(shouldShow(note, type, viewScope));+ const [ shown, setShown ] = useState(shouldShowInlineTitle(note, type, viewScope));const containerRef = useRef<HTMLDivElement>(null);const [ titleHidden, setTitleHidden ] = useState(false);useLayoutEffect(() => {- setShown(shouldShow(note, type, viewScope));+ setShown(shouldShowInlineTitle(note, type, viewScope));}, [ note, type, mime, viewScope ]);// Options pages render their own title (OptionsPageHeader) inside the content, so collapse the@@ -85,17 +81,14 @@ export default function InlineTitle() {);}-function shouldShow(note: FNote | null | undefined, type: NoteType | undefined, viewScope: ViewScope | undefined) {+export function shouldShowInlineTitle(note: FNote | null | undefined, type: NoteType | undefined, viewScope: ViewScope | undefined) {if (viewScope?.viewMode !== "default") return false;// Options pages provide their own title via OptionsPageHeader, so this inline title stays hidden// for them (and the sticky title-row is hidden too — see the effect in InlineTitle).if (note?.noteId?.startsWith("_options")) return false;- if (note?.isTriliumSqlite()) return false;- if (note?.isMarkdown()) return false;- // Icon packs render their own preview (like markdown) and the `file`-type ones already have no- // inline title, so opt the `code`-type ones out too for a consistent collapsed header.- if (note?.isIconPack()) return false;- return type && supportedNoteTypes.has(type);+ // A code note fills the pane and scrolls inside its own editor, so nothing ever scrolls past+ // this title. The sticky title row in .note-split carries the title for those notes instead.+ return type === "text";}//#region Title detailsdiff --git a/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx b/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsxindex e5fb73ccc3..32e10641bb 100644--- a/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx+++ b/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx@@ -22,7 +22,7 @@ import type FNote from "../../entities/fnote.js";import server from "../../services/server.js";import { buildNote } from "../../test/easy-froca.js";import { ParentComponent } from "../react/react_utils.js";-import { TemplateNoteTypes, useBuiltinTemplates } from "./NoteTypeSwitcher.js";+import NoteTypeSwitcher, { TemplateNoteTypes, useBuiltinTemplates } from "./NoteTypeSwitcher.js";// happy-dom has no ResizeObserver; Dropdown only needs observe/disconnect to exist.class ResizeObserverStub {@@ -63,6 +63,32 @@ async function flush() {}}+describe("NoteTypeSwitcher", () => {+ it("offers a switch on a text note, and stays away from code notes", () => {+ // The switcher resolves the built-in templates through froca on mount.+ buildNote({ id: "_templates", title: "Templates" });++ expect(renderSwitcher(buildNote({ id: "textNote", title: "Note", type: "text" }))).not.toBeNull();+ expect(renderSwitcher(buildNote({ id: "codeNote", title: "Script", type: "code", mime: "application/javascript;env=backend" }))).toBeNull();+ });+});++function renderSwitcher(note: FNote) {+ if (container?.isConnected) {+ act(() => render(null, container));+ container.remove();+ }++ const host = new Component();+ container = document.createElement("div");+ document.body.appendChild(container);+ act(() => render(+ <ParentComponent.Provider value={host}><NoteTypeSwitcher note={note} /></ParentComponent.Provider>,+ container+ ));+ return container.querySelector(".note-type-switcher");+}+describe("TemplateNoteTypes", () => {it("re-resolves user templates on frocaReloaded (fresh FNote refs after unlock)", async () => {buildNote({ id: "userTemplate1", title: "[protected]" });diff --git a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsxindex 365ef9762b..775ea197a4 100644--- a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx+++ b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx@@ -16,9 +16,6 @@ import { useNoteProperty, useNoteSavedData, useTriliumEvent } from "../react/hooimport { onWheelHorizontalScroll } from "../widget_utils";const SWITCHER_PINNED_NOTE_TYPES = new Set<NoteType>([ "text", "code", "book", "canvas" ]);-const supportedNoteTypes = new Set<NoteType>([- "text", "code"-]);export default function NoteTypeSwitcher({ note }: { note?: FNote | null }) {const blob = useNoteSavedData(note?.noteId);@@ -41,7 +38,9 @@ export default function NoteTypeSwitcher({ note }: { note?: FNote | null }) {const currentNoteTypeData = useMemo(() => NOTE_TYPES.find(t => t.type === currentNoteType), [ currentNoteType ]);const { builtinTemplates, collectionTemplates } = useBuiltinTemplates();- return (currentNoteType && supportedNoteTypes.has(currentNoteType) && !note?.isTriliumSqlite() && !note?.isMarkdown() && !note?.isIconPack() &&+ // Code notes fill the pane with their editor and carry no inline title, so the switcher has+ // nowhere to sit above them.+ return (currentNoteType === "text" &&<divclassName="note-type-switcher"onWheel={onWheelHorizontalScroll}diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.htmlindex 613cfddda4..e29ad5daab 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html@@ -21,11 +21,11 @@ class="image">it displays the title in a larger font, while also displaying additionalinformation such as the creation and the modification date.</p><p>Whenever the title is scrolled past, the fixed title is shown instead.</p>-<p>This only affects <a class="reference-link" href="#root/_help_iPIMuisry3hd">Text</a> and <a- class="reference-link" href="#root/_help_6f9hih2hXXZk">Code</a> notes. Note- types that take the entirety of the screen such as <a class="reference-link"- href="#root/_help_grjYqerjn243">Canvas</a> will always have only the fixed- title bar.</p>+<p>This only affects <a class="reference-link" href="#root/_help_iPIMuisry3hd">Text</a> notes.+ Note types that take the entirety of the screen, such as <a class="reference-link"+ href="#root/_help_6f9hih2hXXZk">Code</a> and <a class="reference-link"+ href="#root/_help_grjYqerjn243">Canvas</a>, will always have only the fixed title+ bar.</p><p>Depending on the note type, the inline title will also present some moreinteractive options such as being able to switch the note type (see below).</p><figure@@ -41,9 +41,8 @@ class="image"><figcaption>The fixed title bar. The title only appears after scrolling past the <em>Inline title</em>.</figcaption></figure><h3>New note type switcher</h3>-<p>When a new <a class="reference-link" href="#root/_help_iPIMuisry3hd">Text</a> or <a- class="reference-link" href="#root/_help_6f9hih2hXXZk">Code</a> note is- created, a note type switcher will appear below the <em>Inline title</em>.+<p>When a new <a class="reference-link" href="#root/_help_iPIMuisry3hd">Text</a> note+ is created, a note type switcher will appear below the <em>Inline title</em>.Apart from changing the note type, it's also possible to apply a <a href="#root/_help_KC1HB96bqqHX">template</a>.</p><p>The switcher will disappear as soon as a text is entered.</p><img src="6_New Layout_image.png"diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.md b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.mdindex 24bac65c09..e5de7cea3c 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.md@@ -17,7 +17,7 @@ In previous versions of Trilium, the title bar was fixed at all times. In the neWhenever the title is scrolled past, the fixed title is shown instead.-This only affects <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> and <a class="reference-link" href="../../Note%20Types/Code.md">Code</a> notes. Note types that take the entirety of the screen such as <a class="reference-link" href="../../Note%20Types/Canvas.md">Canvas</a> will always have only the fixed title bar.+This only affects <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> notes. Note types that take the entirety of the screen, such as <a class="reference-link" href="../../Note%20Types/Code.md">Code</a> and <a class="reference-link" href="../../Note%20Types/Canvas.md">Canvas</a>, will always have only the fixed title bar.Depending on the note type, the inline title will also present some more interactive options such as being able to switch the note type (see below).@@ -25,7 +25,7 @@ Depending on the note type, the inline title will also present some more interac### New note type switcher-When a new <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> or <a class="reference-link" href="../../Note%20Types/Code.md">Code</a> note is created, a note type switcher will appear below the _Inline title_. Apart from changing the note type, it's also possible to apply a [template](../../Advanced%20Usage/Templates.md).+When a new <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> note is created, a note type switcher will appear below the _Inline title_. Apart from changing the note type, it's also possible to apply a [template](../../Advanced%20Usage/Templates.md).The switcher will disappear as soon as a text is entered.