Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): keep the collapsed outline button visible while scrolling

tianma-if39b8f149a24b
diff --git a/apps/web/src/components/EditorOutline.tsx b/apps/web/src/components/EditorOutline.tsx
index 04393d67..1d1c9b03 100644
--- a/apps/web/src/components/EditorOutline.tsx
+++ b/apps/web/src/components/EditorOutline.tsx
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { createPortal } from "react-dom";
import type { Editor } from "@tiptap/react";
import { ChevronDown, ChevronRight, ListTree } from "lucide-react";
import { useTranslation } from "react-i18next";
@@ -10,6 +11,9 @@ import { EDITOR_OUTLINE_WIDTH } from "@/lib/workspace-ui";
type EditorOutlineProps = {
editor: Editor | null;
scrollContainer: HTMLDivElement | null;
+ // Non-scrolling slot at the editor pane's top-right. The collapsed button
+ // portals here so it stays put while the note scrolls.
+ collapsedAnchor: HTMLElement | null;
collapsed: boolean;
shortcutLabel: string;
onCollapsedChange: (collapsed: boolean) => void;
@@ -49,7 +53,7 @@ const sameOutlineItems = (left: OutlineItem[], right: OutlineItem[]) =>
return other?.level === item.level && other.pos === item.pos && other.text === item.text;
});
-export const EditorOutline = ({ editor, scrollContainer, collapsed, shortcutLabel, onCollapsedChange }: EditorOutlineProps) => {
+export const EditorOutline = ({ editor, scrollContainer, collapsedAnchor, collapsed, shortcutLabel, onCollapsedChange }: EditorOutlineProps) => {
const { t } = useTranslation();
const [items, setItems] = useState<OutlineItem[]>([]);
const [activePos, setActivePos] = useState<number | null>(null);
@@ -267,17 +271,18 @@ export const EditorOutline = ({ editor, scrollContainer, collapsed, shortcutLabe
const outlineToggleLabel = `${t(collapsed ? "editor.showOutline" : "editor.hideOutline")} (${shortcutLabel})`;
- return (
+ const outline = (
<TooltipProvider delayDuration={350} skipDelayDuration={100}>
<aside
className={cn(
"select-none overflow-x-hidden",
collapsed
- ? "absolute right-0 top-6 z-10 h-8 w-8 overflow-hidden"
+ ? "pointer-events-auto absolute inset-0 overflow-hidden"
: "sticky top-6 h-fit max-h-[calc(100vh-8rem)] shrink-0 overflow-y-auto py-2"
)}
style={!collapsed ? { width: EDITOR_OUTLINE_WIDTH } : undefined}
aria-label={t("editor.outline")}
+ data-editor-outline={collapsed ? "collapsed" : "expanded"}
>
<div className={cn("flex", collapsed ? "justify-center" : "mb-3 justify-between px-1")}>
<Tooltip>
@@ -314,4 +319,12 @@ export const EditorOutline = ({ editor, scrollContainer, collapsed, shortcutLabe
</aside>
</TooltipProvider>
);
+
+ // Absolute inside the note scroller is tied to the document top, so the
+ // button scrolls away. The anchor sits on the pane and does not scroll.
+ if (collapsed) {
+ return collapsedAnchor ? createPortal(outline, collapsedAnchor) : null;
+ }
+
+ return outline;
};
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index 921f8c93..541cdc23 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -602,6 +602,7 @@ const RichEditorPane = ({
enabled: noteLinkPickerOpen,
});
const [editorScrollContainer, setEditorScrollContainer] = useState<HTMLDivElement | null>(null);
+ const [collapsedOutlineAnchor, setCollapsedOutlineAnchor] = useState<HTMLDivElement | null>(null);
const [editorScrollbarGutter, setEditorScrollbarGutter] = useState(0);
const [headerTitleSlot, setHeaderTitleSlot] = useState<HTMLDivElement | null>(null);
const [headerStatusCluster, setHeaderStatusCluster] = useState<HTMLDivElement | null>(null);
@@ -3897,12 +3898,12 @@ const RichEditorPane = ({
const editorColumnMatchesArticle = !useMarkdownSourceEditor;
const editorPaneTight = editorColumnWidth > 0 && editorColumnWidth < EDITOR_PANE_TIGHT_PX;
- const outlineReservesSpace = !editorPaneTight
+ const showDocumentOutline = !editorPaneTight
&& !isMobileViewport
&& !useMobilePlainTextEditor
&& !useMarkdownSourceEditor
- && !phonePreviewOpen
- && !editorOutlineCollapsed;
+ && !phonePreviewOpen;
+ const outlineReservesSpace = showDocumentOutline && !editorOutlineCollapsed;
const compactEditorReadingGutter = shouldCompactEditorReadingGutter({
aiAssistantOpen,
desktopColumn: isDesktopColumn,
@@ -4422,6 +4423,7 @@ const RichEditorPane = ({
/>
</header>
+ <div className="relative min-h-0 min-w-0 flex-1">
<div
ref={setEditorScrollContainerRef}
data-editor-theme="default"
@@ -4431,7 +4433,7 @@ const RichEditorPane = ({
"--memo-content-divider-spacing": `${MEMO_CONTENT_STYLE.divider.marginVertical}px`,
} as CSSProperties}
className={cn(
- "edgeever-editor relative min-h-0 flex-1 bg-transparent",
+ "edgeever-editor relative h-full min-h-0 bg-transparent",
MEMO_EDITOR_READING_GUTTER_PROPERTIES_CLASS_NAME,
useMobilePlainTextEditor
? "overflow-visible"
@@ -4601,10 +4603,11 @@ const RichEditorPane = ({
noteProse={noteProse}
/>
)}
- {!editorPaneTight && !isMobileViewport && !useMobilePlainTextEditor && !useMarkdownSourceEditor && !phonePreviewOpen && (
+ {showDocumentOutline && (
<EditorOutline
editor={editor}
scrollContainer={editorScrollContainer}
+ collapsedAnchor={collapsedOutlineAnchor}
collapsed={editorOutlineCollapsed}
shortcutLabel={formatShortcutBinding(shortcutSettings.toggleOutline)}
onCollapsedChange={handleEditorOutlineCollapsedChange}
@@ -4612,6 +4615,15 @@ const RichEditorPane = ({
)}
</div>
</div>
+ {showDocumentOutline ? (
+ <div
+ ref={setCollapsedOutlineAnchor}
+ className="pointer-events-none absolute top-6 z-10 h-8 w-8"
+ style={{ right: editorScrollbarGutter }}
+ data-editor-outline-anchor="collapsed"
+ />
+ ) : null}
+ </div>
{noteLinkHintPosition && (
<NoteLinkInteractionHint
diff --git a/apps/web/src/components/editor/editor-pane-helpers.test.mjs b/apps/web/src/components/editor/editor-pane-helpers.test.mjs
index df60a17d..329735ba 100644
--- a/apps/web/src/components/editor/editor-pane-helpers.test.mjs
+++ b/apps/web/src/components/editor/editor-pane-helpers.test.mjs
@@ -89,6 +89,18 @@ describe("editor outline demo preference wiring", () => {
});
});
+describe("collapsed outline entry", () => {
+ test("pins the collapsed button to the editor pane instead of the scrolling note", () => {
+ const editorSource = readFileSync(new URL("../EditorPane.tsx", import.meta.url), "utf8");
+ const outlineSource = readFileSync(new URL("../EditorOutline.tsx", import.meta.url), "utf8");
+
+ expect(editorSource).toContain('data-editor-outline-anchor="collapsed"');
+ expect(editorSource).toContain("collapsedAnchor={collapsedOutlineAnchor}");
+ expect(outlineSource).toContain("createPortal(outline, collapsedAnchor)");
+ expect(outlineSource).not.toContain("absolute right-0 top-6");
+ });
+});
+
test('document reset keeps reused image sources, releases removed media and clears undo history',async()=>{
const {parseHTML}=await import('linkedom'),{Schema}=await import('@tiptap/pm/model'),{EditorView}=await import('@tiptap/pm/view'),{EditorState}=await import('@tiptap/pm/state'),{history,undoDepth}=await import('@tiptap/pm/history');