AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(web): shorten reading gutters when the AI sidebar is open
tianma-if4303561527d5
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex a4d50434..cacec367 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -119,6 +119,13 @@ import { isDesktopResourceRuntime, stageDesktopResource, toDesktopResourceDownloimport { contentReferencesStagedResourceUrl, findMatchingMemoResource, repairMemoStagedResourceUrls, repairTiptapStagedResourceUrls } from "@/lib/staged-resource-repair";import { cn, parseTagsText } from "@/lib/utils";import { editorContentColumnMaxWidth, type EditorContentWidth } from "@/lib/editor-content-width";+import {+ EDITOR_ARTICLE_ROW_GAP_PX,+ EDITOR_COMPACT_READING_GUTTER,+ EDITOR_PANE_TIGHT_PX,+ shouldCompactEditorReadingGutter,+} from "@/lib/editor-reading-gutter";+import { EDITOR_OUTLINE_WIDTH } from "@/lib/workspace-ui";import {countMemoCharacters,createEdgeEverDocumentExtensions,@@ -513,21 +520,18 @@ const RichEditorPane = ({readEditorOutlineCollapsedPreference({ defaultCollapsed: !demoMode }));const editorColumnRef = useRef<HTMLDivElement>(null);- // The outline is 300px and the desktop gutter is 6rem per side. Below this- // pane width those two leave the article at 0, which happens once the AI- // sidebar is docked. Hide the outline until the pane is wide enough again.- const [editorPaneTight, setEditorPaneTight] = useState(false);+ // Projected editor-column width. While the sidebar is opening, its width is+ // still animating, so reserve it immediately or the outline and the 6rem+ // gutters keep crushing the article for the whole slide.+ const [editorColumnWidth, setEditorColumnWidth] = useState(0);useLayoutEffect(() => {const node = editorColumnRef.current;if (!node) return;const update = () => {const column = node.getBoundingClientRect().width;const parent = node.parentElement?.getBoundingClientRect().width ?? column;- // While the sidebar is opening, its width is still animating, so the column- // has not given up that space yet. Reserve it immediately or the outline- // crushes the article for the whole slide.- const projected = aiAssistantOpen ? parent - readAiSidebarWidth() : column;- setEditorPaneTight(projected < 720);+ const projected = aiAssistantOpen ? Math.max(0, parent - readAiSidebarWidth()) : column;+ setEditorColumnWidth((current) => (Math.abs(current - projected) < 0.5 ? current : projected));};update();const observer = new ResizeObserver(update);@@ -3567,6 +3571,23 @@ const RichEditorPane = ({const contentColumnMode = desktopFocusMode ? "focus" : editorOutlineCollapsed ? "collapsed" : "reading";const contentColumnMaxWidth = editorContentColumnMaxWidth(editorContentWidth, contentColumnMode);const focusTitleMaxWidth = editorContentColumnMaxWidth(editorContentWidth, "focus");+ const editorPaneTight = editorColumnWidth > 0 && editorColumnWidth < EDITOR_PANE_TIGHT_PX;+ const outlineReservesSpace = !editorPaneTight+ && !isMobileViewport+ && !useMobilePlainTextEditor+ && !useMarkdownSourceEditor+ && !phonePreviewOpen+ && !editorOutlineCollapsed;+ const compactEditorReadingGutter = shouldCompactEditorReadingGutter({+ aiAssistantOpen,+ desktopColumn: isDesktopColumn,+ columnWidth: Math.max(0, editorColumnWidth - editorScrollbarGutter * 2),+ articleMaxWidth: Number.parseInt(contentColumnMaxWidth, 10),+ reservedBesideArticle: outlineReservesSpace+ ? Number.parseInt(EDITOR_OUTLINE_WIDTH, 10) + EDITOR_ARTICLE_ROW_GAP_PX+ : 0,+ focusRow: desktopFocusMode,+ });const savedQuietly = saveState !== "saving"&& saveState !== "error"&& saveState !== "conflict"@@ -4091,8 +4112,8 @@ const RichEditorPane = ({? "w-full justify-center": "w-full")}- style={editorPaneTight && !useMarkdownSourceEditor- ? { "--editor-reading-gutter": "1.75rem" } as CSSProperties+ style={(editorPaneTight || compactEditorReadingGutter) && !useMarkdownSourceEditor+ ? { "--editor-reading-gutter": EDITOR_COMPACT_READING_GUTTER } as CSSProperties: undefined}><divdiff --git a/apps/web/src/lib/editor-reading-gutter.test.mjs b/apps/web/src/lib/editor-reading-gutter.test.mjsnew file mode 100644index 00000000..f56a1ee5--- /dev/null+++ b/apps/web/src/lib/editor-reading-gutter.test.mjs@@ -0,0 +1,96 @@+import { describe, expect, test } from "bun:test";+import {+ EDITOR_ARTICLE_ROW_GAP_PX,+ EDITOR_DESKTOP_READING_GUTTER_PX,+ EDITOR_PANE_TIGHT_PX,+ shouldCompactEditorReadingGutter,+} from "./editor-reading-gutter.ts";++const outlineBesideArticle = 300 + EDITOR_ARTICLE_ROW_GAP_PX;+const standardReading = 880;+const comfortableWithOutline =+ standardReading + outlineBesideArticle + EDITOR_DESKTOP_READING_GUTTER_PX * 2;++describe("editor reading gutter", () => {+ test("keeps the 6rem gutters when the assistant is closed", () => {+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: false,+ desktopColumn: true,+ columnWidth: 920,+ articleMaxWidth: standardReading,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(false);+ });++ test("compacts once an open assistant leaves no room for the article, outline, and 6rem gutters", () => {+ expect(comfortableWithOutline).toBe(1404);+ expect(EDITOR_PANE_TIGHT_PX).toBe(720);+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 920,+ articleMaxWidth: standardReading,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(true);+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: comfortableWithOutline,+ articleMaxWidth: standardReading,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(false);+ });++ test("keeps the wide reading measure when that column still fits", () => {+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 1600,+ articleMaxWidth: 1040,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(false);+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 1563,+ articleMaxWidth: 1040,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(true);+ });++ test("leaves the narrower breakpoints and an unmeasured column alone", () => {+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: false,+ columnWidth: 800,+ articleMaxWidth: standardReading,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(false);+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 0,+ articleMaxWidth: standardReading,+ reservedBesideArticle: outlineBesideArticle,+ })).toBe(false);+ });++ test("uses the 1400px focus row when deciding", () => {+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 1800,+ articleMaxWidth: 960,+ reservedBesideArticle: outlineBesideArticle,+ focusRow: true,+ })).toBe(true);+ expect(shouldCompactEditorReadingGutter({+ aiAssistantOpen: true,+ desktopColumn: true,+ columnWidth: 1800,+ articleMaxWidth: 960,+ reservedBesideArticle: 0,+ focusRow: true,+ })).toBe(false);+ });+});diff --git a/apps/web/src/lib/editor-reading-gutter.ts b/apps/web/src/lib/editor-reading-gutter.tsnew file mode 100644index 00000000..87ec0aaf--- /dev/null+++ b/apps/web/src/lib/editor-reading-gutter.ts@@ -0,0 +1,58 @@+/** Desktop reading gutter at the `lg` breakpoint. Matches `6rem` in the editor row. */+export const EDITOR_DESKTOP_READING_GUTTER_PX = 96;++/** Compact gutter already used below `lg` and in the tight pane. Matches `1.75rem`. */+export const EDITOR_COMPACT_READING_GUTTER = "1.75rem";++/**+ * Hide the outline below this projected editor-column width.+ * Outline (300px) plus 6rem gutters would otherwise collapse the article.+ */+export const EDITOR_PANE_TIGHT_PX = 720;++/** Tailwind `gap-8` between the article and an in-flow outline. */+export const EDITOR_ARTICLE_ROW_GAP_PX = 32;++/** Focus mode caps the article row. Matches `max-w-[1400px]` on that row. */+export const EDITOR_FOCUS_ROW_MAX_PX = 1400;++export const editorColumnFitsDesktopReadingGutters = ({+ columnWidth,+ articleMaxWidth,+ reservedBesideArticle = 0,+}: {+ columnWidth: number;+ articleMaxWidth: number;+ reservedBesideArticle?: number;+}) =>+ columnWidth >= articleMaxWidth + reservedBesideArticle + EDITOR_DESKTOP_READING_GUTTER_PX * 2;++/**+ * While the companion sidebar is open, yield the 6rem reading gutters as soon+ * as the column can no longer hold the chosen article width, the outline, and+ * those gutters. The shared `lg:` gutter stays 6rem for every other width.+ */+export const shouldCompactEditorReadingGutter = ({+ aiAssistantOpen,+ desktopColumn,+ columnWidth,+ articleMaxWidth,+ reservedBesideArticle = 0,+ focusRow = false,+}: {+ aiAssistantOpen: boolean;+ desktopColumn: boolean;+ columnWidth: number;+ articleMaxWidth: number;+ reservedBesideArticle?: number;+ focusRow?: boolean;+}) => {+ if (!aiAssistantOpen || !desktopColumn || columnWidth <= 0) return false;+ if (!Number.isFinite(articleMaxWidth) || articleMaxWidth <= 0) return false;+ const available = focusRow ? Math.min(columnWidth, EDITOR_FOCUS_ROW_MAX_PX) : columnWidth;+ return !editorColumnFitsDesktopReadingGutters({+ columnWidth: available,+ articleMaxWidth,+ reservedBesideArticle,+ });+};