Skip to content

feat(superdoc): center comment and document anchor on sidebar click#2466

Open
tupizz wants to merge 1 commit intomainfrom
feat/center-comment-on-sidebar-click
Open

feat(superdoc): center comment and document anchor on sidebar click#2466
tupizz wants to merge 1 commit intomainfrom
feat/center-comment-on-sidebar-click

Conversation

@tupizz
Copy link
Contributor

@tupizz tupizz commented Mar 19, 2026

CleanShot.2026-03-19.at.10.43.17.mp4

Summary

fixes SD-2248
https://linear.app/superdocworkspace/issue/SD-2248/bug-in-tester-tools-googleapis-and-labs-commenttc-bubbles-and-doc-do

  • When clicking a comment card in the sidebar, both the document anchor and the sidebar comment now smoothly scroll to the vertical center of the viewport instead of staying at the comment's current screen position
  • Document scroll uses behavior: 'smooth' instead of instant jump
  • Sidebar alignment uses CSS transitions (non-instant path) for smooth motion
  • Applies consistently to all sidebar-originated activations: direct click, comments list, thread expansion

How it works

The entire alignment pipeline is parameterized by a single targetClientY value. This PR changes it from commentDialog.getBoundingClientRect().top (the card's current position) to window.innerHeight * 0.38 (optical center of the viewport).

The 0.38 ratio places content slightly above true center to leave room for comment card content below. This is a tunable constant (VIEWPORT_CENTER_RATIO).

What does NOT change

  • "From document" clicks (clicking tracked change text) still align the sidebar to the anchor position without centering scroll
  • PDF comment centering (already uses scrollIntoView({ block: 'center' }))
  • All existing alignment infrastructure (FloatingComments watchers, collision avoidance, PresentationEditor scroll)

Test plan

  • Click a tracked change comment near the top/bottom of the sidebar. Both document text and comment card should smoothly scroll to viewport center at the same Y level
  • Click a regular (non-tracked-change) comment. Same centering behavior
  • Click a comment whose anchor is on the first/last page. Scroll should clamp gracefully
  • Click tracked change text in the document body. Sidebar should align to anchor Y without centering scroll (unchanged)
  • Click "N more replies" on a thread. Thread should expand and center
  • Click several different comments rapidly. No stale positioning artifacts

@tupizz tupizz self-assigned this Mar 19, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41d3e62d97

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// Skip instant alignment (which disables CSS transitions) so that the
// sidebar smoothly slides to its target. The non-instant watcher path in
// FloatingComments will align the comment after the smooth scroll settles.
clearInstantSidebarAlignment();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-align the sidebar on repeat activation of the same thread

Clearing the instant-alignment request here breaks the new centering behavior whenever the clicked thread is already active. FloatingComments.vue only updates sidebarOffsetY from its watch(activeCommentKey, ...) / watch(activeComment, ...) paths, so re-clicking the currently active card—or expanding N more replies on an already-active thread—does not move the sidebar at all, while scrollThreadAnchorToClientY(..., { behavior: 'smooth' }) below still recenters the document. In that scenario the document anchor moves to center but the selected comment card stays where it was.

Useful? React with 👍 / 👎.

} else {
clearInstantSidebarAlignment();
}
const targetClientY = Math.round(window.innerHeight * VIEWPORT_CENTER_RATIO);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute the center target from the actual scroll container

This uses the browser window height as the centering target, but PresentationEditor.scrollThreadAnchorToClientY() explicitly supports scrolling an HTMLElement container as well as Window (packages/super-editor/src/core/presentation-editor/PresentationEditor.ts, scrollThreadAnchorToClientY), and the same class's other scrolling code already switches to container bounds for nested scrollers (#scrollScreenRectIntoView). In embedded layouts like a modal or split pane, window.innerHeight * 0.38 is not the visible center of the editor viewport, so sidebar clicks will land the anchor/comment noticeably off-center.

Useful? React with 👍 / 👎.

@linear
Copy link

linear bot commented Mar 19, 2026

Target viewport center (38% from top) instead of the comment's current
screen position when clicking a sidebar comment card.
@tupizz tupizz force-pushed the feat/center-comment-on-sidebar-click branch from adfdfc4 to f86b8b9 Compare March 19, 2026 14:35
Copy link
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tupizz nice and simple change. the centering works well for the current full-screen setup. one small thing: if the editor ever lives inside a smaller container, the scroll position might land a bit off — left an inline comment about it. no tests needed for this. the codex bot flagged re-clicking the same comment as a problem, but that behavior already existed before this PR.

const setFocus = () => {
const editor = proxy.$superdoc.activeEditor;
const targetClientY = commentDialogElement.value?.getBoundingClientRect?.()?.top;
const targetClientY = Math.round(window.innerHeight * 0.38);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this uses the browser window height to figure out where to scroll, which works when the editor takes up the full screen. if the editor is inside something smaller (like a modal or a panel with a toolbar above it), the scroll target will be a bit off. not a blocker — just something to keep in mind. also, naming the 0.38 makes it easier to find and tweak later:

Suggested change
const targetClientY = Math.round(window.innerHeight * 0.38);
const COMMENT_FOCUS_VIEWPORT_RATIO = 0.38;
const targetClientY = Math.round(window.innerHeight * COMMENT_FOCUS_VIEWPORT_RATIO);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants