DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(reading): let the outline follow the page the reader is actually on
Bingxi Zhao (Frank)00979bd74bed
diff --git a/web/components/reading/ReaderPane.tsx b/web/components/reading/ReaderPane.tsxindex 0644e4cd6..30d4db694 100644--- a/web/components/reading/ReaderPane.tsx+++ b/web/components/reading/ReaderPane.tsx@@ -105,6 +105,16 @@ export interface ReaderPaneProps {*/bookmarks?: ReadingBookmark[];onToggleBookmark?: (locator: number, label?: string) => void;+ /**+ * Where in the material the reader now is.+ *+ * Only the rendered document knows this, and the workspace is where it is+ * needed: the outline panel highlights the row the reader is inside. The+ * media stage has always reported it; the document surface did not, so on+ * an EPUB, PDF or Markdown the outline stayed on whichever row was last+ * clicked while the header counted up (#1447).+ */+ onLocatorChange?: (locator: number) => void;}/**@@ -135,6 +145,7 @@ export function ReaderPane({headingJump = null,bookmarks = [],onToggleBookmark,+ onLocatorChange,}: ReaderPaneProps) {const { t } = useTranslation();// Document + annotations live in the provider (workspace layout), so they@@ -245,6 +256,7 @@ export function ReaderPane({const handleVisibleLocator = useCallback((locator: number) => {setCurrentLocator(locator);+ onLocatorChange?.(locator);reportViewport({ locator });// Remember where the reader got to, so opening this material again// starts here instead of at page 1. EPUB writes its own position — a@@ -284,7 +296,7 @@ export function ReaderPane({});}},- [historyReady, material, reportViewport],+ [historyReady, material, onLocatorChange, reportViewport],);useEffect(() => {diff --git a/web/components/reading/workspace/ReadingWorkspace.tsx b/web/components/reading/workspace/ReadingWorkspace.tsxindex b8060c331..807a5e62e 100644--- a/web/components/reading/workspace/ReadingWorkspace.tsx+++ b/web/components/reading/workspace/ReadingWorkspace.tsx@@ -611,6 +611,11 @@ export function ReadingWorkspacePage() {externalJump={documentJump}onHeadingsChange={setPageHeadings}onActiveHeadingChange={setActiveHeadingId}+ // The outline highlights the row the reader is inside, so it+ // has to hear about pages turned in the document and not only+ // about rows clicked in the panel. ReaderPane reports its own+ // viewport, unlike the media stage above.+ onLocatorChange={setActiveLocator}headingJump={headingJump}bookmarks={bookmarks}onToggleBookmark={(locator, label) =>diff --git a/web/tests/reading-outline-tracking.spec.tsx b/web/tests/reading-outline-tracking.spec.tsxnew file mode 100644index 000000000..06f9d14c4--- /dev/null+++ b/web/tests/reading-outline-tracking.spec.tsx@@ -0,0 +1,65 @@+import { fireEvent, render, screen } from "@testing-library/react";+import { describe, expect, it, vi } from "vitest";++import { ReaderPane } from "@/components/reading/ReaderPane";+import { initI18n } from "@/i18n/init";++initI18n("en");++const material = {+ material_id: "m-1",+ title: "A Book",+ render_mode: "text",+ unit: "section",+ unit_count: 100,+ unit_refs: [],+ has_raw_view: false,+ status: "ready",+ source_kind: "upload",+ extractor: "",+};++vi.mock("@/context/ReadingContext", () => ({+ useReading: () => ({+ material,+ annotations: [],+ loading: false,+ error: "",+ openMaterial: vi.fn(),+ closeMaterial: vi.fn(),+ saveMark: vi.fn(),+ removeMark: vi.fn(),+ mergeMark: vi.fn(),+ dismissError: vi.fn(),+ setError: vi.fn(),+ reportViewport: vi.fn(),+ }),+}));++// The text view is the piece that knows which unit is on screen; stand in for+// it with a button that reports one, the way a page turn does.+vi.mock("@/components/reading/TextUnitView", () => ({+ unitLabel: () => "section",+ TextUnitView: ({+ onVisibleLocatorChange,+ }: {+ onVisibleLocatorChange?: (locator: number) => void;+ }) => (+ <button type="button" onClick={() => onVisibleLocatorChange?.(5)}>+ turn to section 5+ </button>+ ),+}));++describe("the reading outline", () => {+ it("hears about a page turned in the document, not only a row clicked", async () => {+ const onLocatorChange = vi.fn();+ render(<ReaderPane onClose={vi.fn()} onLocatorChange={onLocatorChange} />);++ fireEvent.click(await screen.findByText("turn to section 5"));++ // Without this the workspace's activeLocator stayed wherever the panel+ // last put it, so the outline never left chapter one (#1447).+ expect(onLocatorChange).toHaveBeenCalledWith(5);+ });+});