Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

baseline (#3154)

shagun-singh-inkeep7755e6ac026b
diff --git a/.changeset/comment-rail-toolbar-overlap.md b/.changeset/comment-rail-toolbar-overlap.md
new file mode 100644
index 000000000..237e04abc
--- /dev/null
+++ b/.changeset/comment-rail-toolbar-overlap.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Comment markers in the right-hand rail no longer sit on top of the toolbar buttons in the editor's top right corner. The rail ran the full height of the editor's scroll area, but that area reaches up underneath the toolbar, so any comment whose passage was scrolled above the visible text parked its icon at the very top of the rail, in the same corner as the panel and action buttons. With several such comments they stacked down over that corner. The rail now starts below the toolbar, and a comment anchored to a line hidden behind the toolbar dims like any other off-screen one instead of being drawn over it.
diff --git a/packages/app/src/comments/CommentMarginRail.tsx b/packages/app/src/comments/CommentMarginRail.tsx
index 4d5c799a0..14f002d74 100644
--- a/packages/app/src/comments/CommentMarginRail.tsx
+++ b/packages/app/src/comments/CommentMarginRail.tsx
@@ -18,6 +18,10 @@
* scrolled out of view clamps to the nearest edge and dims — it stops claiming
* to point at a line, while still saying "there is more this way".
*
+ * The rail's top edge is the scrollport's top PLUS the inset that scrollport
+ * declares, because the editor toolbar overlays that strip and its buttons are
+ * flush right, in the rail's own column.
+ *
* Recomputes on scroll, thread changes, doc edits, and container resize.
*/
@@ -35,7 +39,7 @@ import {
revealPropertyValueRange,
scrollPropertyRowIntoView,
} from './property-row-rect';
-import { findScrollContainer, scrollAnchorIntoView } from './scroll-to-anchor';
+import { findScrollContainer, scrollAnchorIntoView, scrollportInsetTop } from './scroll-to-anchor';
import {
clearActiveThread,
emitOpenThreadPopover,
@@ -61,6 +65,22 @@ interface MarkerPosition {
offscreen: boolean;
}
+/**
+ * The band of the scrollport a marker may occupy, in viewport coordinates.
+ *
+ * The scrollport reaches up UNDER the editor toolbar, and the toolbar's action
+ * buttons sit flush against the same right edge the rail runs down — so a
+ * marker clamped to the raw top of that box lands on top of them. Taking the
+ * inset off the top uses the one number the scrollport already declares as
+ * covered, instead of restating the toolbar's height here.
+ */
+export function railBand(
+ rect: { top: number; height: number },
+ insetTop: number,
+): { top: number; height: number } {
+ return { top: rect.top + insetTop, height: Math.max(0, rect.height - insetTop) };
+}
+
/**
* Place each marker beside its line, in viewport coordinates.
*
@@ -145,8 +165,9 @@ export function CommentMarginRail({ editor, docName }: { editor: Editor; docName
targets.push({ id: thread.id, y });
}
}
- setRail({ top: rect.top, height: rect.height, left: rect.right - RAIL_WIDTH });
- setPositions(layoutMarkers(targets, rect.top, rect.height));
+ const band = railBand(rect, scrollportInsetTop(container));
+ setRail({ top: band.top, height: band.height, left: rect.right - RAIL_WIDTH });
+ setPositions(layoutMarkers(targets, band.top, band.height));
};
compute();
diff --git a/packages/app/src/comments/margin-rail-layout.test.ts b/packages/app/src/comments/margin-rail-layout.test.ts
index 7efba4669..36b0ec57e 100644
--- a/packages/app/src/comments/margin-rail-layout.test.ts
+++ b/packages/app/src/comments/margin-rail-layout.test.ts
@@ -10,7 +10,7 @@
*/
import { describe, expect, test } from 'vitest';
-import { layoutMarkers } from './CommentMarginRail';
+import { layoutMarkers, railBand } from './CommentMarginRail';
const RAIL_TOP = 100;
const RAIL_HEIGHT = 600; // visible band: 100 → 700
@@ -78,3 +78,41 @@ describe('layoutMarkers', () => {
expect(layoutMarkers([], RAIL_TOP, RAIL_HEIGHT)).toEqual([]);
});
});
+
+/**
+ * The second bug: the rail ran the full height of the scrollport, but the
+ * scrollport reaches up under the editor toolbar, whose buttons are flush
+ * against the same right edge. Anything clamped to the top — every comment
+ * scrolled above the viewport — piled onto those buttons.
+ */
+describe('railBand', () => {
+ const scrollport = { top: 100, height: 600 };
+ const TOOLBAR = 56;
+
+ test('starts below the strip the scrollport declares as covered', () => {
+ expect(railBand(scrollport, TOOLBAR)).toEqual({ top: 156, height: 544 });
+ });
+
+ test('keeps a top-clamped marker clear of the toolbar', () => {
+ const band = railBand(scrollport, TOOLBAR);
+ const [marker] = layoutMarkers([{ id: 'a', y: -250 }], band.top, band.height);
+ expect(marker.top).toBeGreaterThanOrEqual(scrollport.top + TOOLBAR);
+ expect(marker.offscreen).toBe(true);
+ });
+
+ test('a line hidden behind the toolbar counts as offscreen, not as placed there', () => {
+ const band = railBand(scrollport, TOOLBAR);
+ // 130 is inside the scrollport's box but under the toolbar.
+ const [marker] = layoutMarkers([{ id: 'a', y: 130 }], band.top, band.height);
+ expect(marker.top).toBe(band.top);
+ expect(marker.offscreen).toBe(true);
+ });
+
+ test('leaves the band alone when the scrollport declares no inset', () => {
+ expect(railBand(scrollport, 0)).toEqual(scrollport);
+ });
+
+ test('never reports a negative height for a scrollport shorter than its inset', () => {
+ expect(railBand({ top: 100, height: 20 }, TOOLBAR).height).toBe(0);
+ });
+});
diff --git a/packages/app/src/comments/scroll-to-anchor.ts b/packages/app/src/comments/scroll-to-anchor.ts
index 3c4a7d641..27e26118f 100644
--- a/packages/app/src/comments/scroll-to-anchor.ts
+++ b/packages/app/src/comments/scroll-to-anchor.ts
@@ -67,8 +67,11 @@ export function findScrollContainer(el: HTMLElement | null): HTMLElement | null
/**
* Read the inset from the scrollport itself rather than restating the toolbar
* height here — one fewer constant to keep in sync with `scroll-pt-14`.
+ *
+ * Shared with the margin rail, which has to keep its markers out of the same
+ * strip the toolbar occupies.
*/
-function insetTopOf(container: HTMLElement): number {
+export function scrollportInsetTop(container: HTMLElement): number {
const value = Number.parseFloat(getComputedStyle(container).scrollPaddingTop);
return Number.isFinite(value) ? value : 0;
}
@@ -99,7 +102,7 @@ export function scrollAnchorIntoView(editor: Editor, range: { from: number; to:
anchorBottom: Math.max(start.bottom, end.bottom),
viewTop: box.top,
viewBottom: box.bottom,
- insetTop: insetTopOf(container),
+ insetTop: scrollportInsetTop(container),
});
if (delta === 0) return;
const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;