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
feat(inline_title): in split, avoid layout shift by maintaining the toolbar
Elian Doran2b1bc8e2b9f8
diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx b/apps/client/src/widgets/ribbon/FormattingToolbar.tsxindex c8d32aab77..8c4ba105a2 100644--- a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx+++ b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx@@ -1,3 +1,4 @@+import clsx from "clsx";import { useEffect, useRef, useState } from "preact/hooks";import { useActiveNoteContext, useIsNoteReadOnly, useNoteProperty, useTriliumEvent, useTriliumOption } from "../react/hooks";@@ -48,7 +49,7 @@ export function FixedFormattingToolbar() {const shown = (viewScope?.viewMode === "default" &&textNoteEditorType === "ckeditor-classic" &&- noteType === "text" &&+ (noteContext?.getMainContext().getSubContexts() ?? []).some(sub => sub.note?.type === "text") &&!isReadOnly);const [ toolbarToRender, setToolbarToRender ] = useState<HTMLElement | null | undefined>();@@ -74,8 +75,11 @@ export function FixedFormattingToolbar() {// Switch between the cached toolbar when user navigates to a different note context.useEffect(() => {if (!ntxId) return;- setToolbarToRender(toolbarCache.get(ntxId));- }, [ ntxId, noteContext ]);+ const toolbar = toolbarCache.get(ntxId);+ if (toolbar) {+ setToolbarToRender(toolbar);+ }+ }, [ ntxId, noteType, noteContext ]);// Render the toolbar.useEffect(() => {@@ -89,7 +93,10 @@ export function FixedFormattingToolbar() {return (<divref={containerRef}- className={`classic-toolbar-widget ${!shown ? "hidden-ext" : ""}`}+ className={clsx("classic-toolbar-widget", {+ "hidden-ext": !shown,+ "disabled": noteType !== "text"+ })}/>);}diff --git a/apps/client/src/widgets/ribbon/style.css b/apps/client/src/widgets/ribbon/style.cssindex bb0da9c4df..8cada33193 100644--- a/apps/client/src/widgets/ribbon/style.css+++ b/apps/client/src/widgets/ribbon/style.css@@ -152,6 +152,15 @@opacity: 0.3;}+body.experimental-feature-new-layout .classic-toolbar-widget {+ transition: opacity 250ms ease-in;++ &.disabled {+ opacity: 0.3;+ pointer-events: none;+ }+}+/* #endregion *//* #region Script Tab */