GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): scroll to comment on click · bpd1069/opencode@2b07291

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • app/src
      • components
        • prompt-input.tsx
      • pages
        • session.tsx
    • ui/src/components
      • session-review.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/components/prompt-input.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input.tsx
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,26 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
185185
const openComment = (item: { path: string; commentID?: string; commentOrigin?: "review" | "file" }) => {
186186
if (!item.commentID) return
187187

188-
comments.setFocus({ file: item.path, id: item.commentID })
189-
comments.setActive({ file: item.path, id: item.commentID })
188+
const focus = { file: item.path, id: item.commentID }
189+
comments.setActive(focus)
190190
view().reviewPanel.open()
191191

192192
if (item.commentOrigin === "review") {
193193
tabs().open("review")
194+
requestAnimationFrame(() => comments.setFocus(focus))
194195
return
195196
}
196197

197198
if (item.commentOrigin !== "file" && commentInReview(item.path)) {
198199
tabs().open("review")
200+
requestAnimationFrame(() => comments.setFocus(focus))
199201
return
200202
}
201203

202204
const tab = files.tab(item.path)
203205
tabs().open(tab)
204206
files.load(item.path)
207+
requestAnimationFrame(() => comments.setFocus(focus))
205208
}
206209

207210
const recent = createMemo(() => {
Collapse file

‎packages/app/src/pages/session.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/pages/session.tsx
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ export default function Page() {
18601860
let scrollFrame: number | undefined
18611861
let pending: { x: number; y: number } | undefined
18621862
let codeScroll: HTMLElement[] = []
1863+
let focusToken = 0
18631864

18641865
const path = createMemo(() => file.pathFromTab(tab))
18651866
const state = createMemo(() => {
@@ -2036,9 +2037,50 @@ export default function Page() {
20362037
const target = fileComments().find((comment) => comment.id === focus.id)
20372038
if (!target) return
20382039

2040+
focusToken++
2041+
const token = focusToken
2042+
20392043
setOpenedComment(target.id)
20402044
setCommenting(null)
20412045
file.setSelectedLines(p, target.selection)
2046+
2047+
const scrollTo = (attempt: number) => {
2048+
if (token !== focusToken) return
2049+
2050+
const root = scroll
2051+
if (!root) {
2052+
if (attempt >= 120) return
2053+
requestAnimationFrame(() => scrollTo(attempt + 1))
2054+
return
2055+
}
2056+
2057+
const anchor = root.querySelector(`[data-comment-id="${target.id}"]`)
2058+
const ready =
2059+
anchor instanceof HTMLElement &&
2060+
anchor.style.pointerEvents !== "none" &&
2061+
anchor.style.opacity !== "0"
2062+
2063+
const shadow = getRoot()
2064+
const marker = shadow ? findMarker(shadow, target.selection) : undefined
2065+
const node = (ready ? anchor : (marker ?? wrap)) as HTMLElement | undefined
2066+
if (!node) {
2067+
if (attempt >= 120) return
2068+
requestAnimationFrame(() => scrollTo(attempt + 1))
2069+
return
2070+
}
2071+
2072+
const rootRect = root.getBoundingClientRect()
2073+
const targetRect = node.getBoundingClientRect()
2074+
const offset = targetRect.top - rootRect.top
2075+
const next = root.scrollTop + offset - rootRect.height / 2 + targetRect.height / 2
2076+
root.scrollTop = Math.max(0, next)
2077+
2078+
if (ready || marker) return
2079+
if (attempt >= 120) return
2080+
requestAnimationFrame(() => scrollTo(attempt + 1))
2081+
}
2082+
2083+
requestAnimationFrame(() => scrollTo(0))
20422084
requestAnimationFrame(() => comments.clearFocus())
20432085
})
20442086

Collapse file

‎packages/ui/src/components/session-review.tsx‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/session-review.tsx
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export const SessionReview = (props: SessionReviewProps) => {
238238

239239
const target = ready ? anchor : anchors.get(focus.file)
240240
if (!target) {
241-
if (attempt >= 24) return
241+
if (attempt >= 120) return
242242
requestAnimationFrame(() => scrollTo(attempt + 1))
243243
return
244244
}
@@ -250,7 +250,7 @@ export const SessionReview = (props: SessionReviewProps) => {
250250
root.scrollTop = Math.max(0, next)
251251

252252
if (ready) return
253-
if (attempt >= 24) return
253+
if (attempt >= 120) return
254254
requestAnimationFrame(() => scrollTo(attempt + 1))
255255
}
256256

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.