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): cleanup comment component usage · bpd1069/opencode@ddc4e89

File tree

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

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

Copy file name to clipboardExpand all lines: packages/app/src/pages/session.tsx
+22-92Lines changed: 22 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DiffChanges } from "@opencode-ai/ui/diff-changes"
1515
import { ResizeHandle } from "@opencode-ai/ui/resize-handle"
1616
import { Tabs } from "@opencode-ai/ui/tabs"
1717
import { useCodeComponent } from "@opencode-ai/ui/context/code"
18-
import { LineCommentAnchor } from "@opencode-ai/ui/line-comment"
18+
import { LineComment as LineCommentView, LineCommentEditor } from "@opencode-ai/ui/line-comment"
1919
import { SessionTurn } from "@opencode-ai/ui/session-turn"
2020
import { createAutoScroll } from "@opencode-ai/ui/hooks"
2121
import { SessionReview } from "@opencode-ai/ui/session-review"
@@ -1885,7 +1885,6 @@ export default function Page() {
18851885
})
18861886

18871887
let wrap: HTMLDivElement | undefined
1888-
let textarea: HTMLTextAreaElement | undefined
18891888

18901889
const fileComments = createMemo(() => {
18911890
const p = path()
@@ -1898,7 +1897,6 @@ export default function Page() {
18981897
const [openedComment, setOpenedComment] = createSignal<string | null>(null)
18991898
const [commenting, setCommenting] = createSignal<SelectedLineRange | null>(null)
19001899
const [draft, setDraft] = createSignal("")
1901-
const [draftError, setDraftError] = createSignal(false)
19021900
const [positions, setPositions] = createSignal<Record<string, number>>({})
19031901
const [draftTop, setDraftTop] = createSignal<number | undefined>(undefined)
19041902

@@ -1986,7 +1984,6 @@ export default function Page() {
19861984
const range = commenting()
19871985
if (!range) return
19881986
setDraft("")
1989-
requestAnimationFrame(() => textarea?.focus())
19901987
})
19911988

19921989
createEffect(() => {
@@ -2047,7 +2044,7 @@ export default function Page() {
20472044
/>
20482045
<For each={fileComments()}>
20492046
{(comment) => (
2050-
<LineCommentAnchor
2047+
<LineCommentView
20512048
id={comment.id}
20522049
top={positions()[comment.id]}
20532050
open={openedComment() === comment.id}
@@ -2063,26 +2060,31 @@ export default function Page() {
20632060
setOpenedComment((current) => (current === comment.id ? null : comment.id))
20642061
file.setSelectedLines(p, comment.selection)
20652062
}}
2066-
>
2067-
<div class="flex flex-col gap-1.5">
2068-
<div class="text-14-regular text-text-strong whitespace-pre-wrap">
2069-
{comment.comment}
2070-
</div>
2071-
<div class="text-12-medium text-text-weak whitespace-nowrap">
2072-
Comment on {commentLabel(comment.selection)}
2073-
</div>
2074-
</div>
2075-
</LineCommentAnchor>
2063+
comment={comment.comment}
2064+
selection={commentLabel(comment.selection)}
2065+
/>
20762066
)}
20772067
</For>
20782068
<Show when={commenting()}>
20792069
{(range) => (
20802070
<Show when={draftTop() !== undefined}>
2081-
<LineCommentAnchor
2071+
<LineCommentEditor
20822072
top={draftTop()}
2083-
open={true}
2084-
variant="editor"
2085-
onClick={() => textarea?.focus()}
2073+
value={draft()}
2074+
selection={commentLabel(range())}
2075+
onInput={setDraft}
2076+
onCancel={() => setCommenting(null)}
2077+
onSubmit={(comment) => {
2078+
const p = path()
2079+
if (!p) return
2080+
addCommentToContext({
2081+
file: p,
2082+
selection: range(),
2083+
comment,
2084+
origin: "file",
2085+
})
2086+
setCommenting(null)
2087+
}}
20862088
onPopoverFocusOut={(e) => {
20872089
const target = e.relatedTarget as Node | null
20882090
if (target && e.currentTarget.contains(target)) return
@@ -2093,79 +2095,7 @@ export default function Page() {
20932095
}
20942096
}, 0)
20952097
}}
2096-
>
2097-
<div class="flex flex-col gap-2">
2098-
<textarea
2099-
ref={textarea}
2100-
classList={{
2101-
"w-full resize-vertical p-2 rounded-[6px] bg-surface-base text-text-strong text-12-regular leading-5 focus:outline-none": true,
2102-
"focus:shadow-xs-border-select": !draftError(),
2103-
"shadow-xs-border-critical-base": draftError(),
2104-
}}
2105-
rows={3}
2106-
placeholder="Add comment"
2107-
value={draft()}
2108-
onInput={(e) => {
2109-
setDraft(e.currentTarget.value)
2110-
setDraftError(false)
2111-
}}
2112-
onKeyDown={(e) => {
2113-
if (e.key === "Escape") {
2114-
setCommenting(null)
2115-
return
2116-
}
2117-
if (e.key !== "Enter") return
2118-
if (e.shiftKey) return
2119-
e.preventDefault()
2120-
const value = draft().trim()
2121-
if (!value) {
2122-
setDraftError(true)
2123-
return
2124-
}
2125-
const p = path()
2126-
if (!p) return
2127-
addCommentToContext({
2128-
file: p,
2129-
selection: range(),
2130-
comment: value,
2131-
origin: "file",
2132-
})
2133-
setCommenting(null)
2134-
}}
2135-
/>
2136-
<div class="flex items-center gap-2">
2137-
<div class="text-12-medium text-text-weak ml-1">
2138-
Commenting on {commentLabel(range())}
2139-
</div>
2140-
<div class="flex-1" />
2141-
<Button size="small" variant="ghost" onClick={() => setCommenting(null)}>
2142-
Cancel
2143-
</Button>
2144-
<Button
2145-
size="small"
2146-
variant="primary"
2147-
onClick={() => {
2148-
const value = draft().trim()
2149-
if (!value) {
2150-
setDraftError(true)
2151-
return
2152-
}
2153-
const p = path()
2154-
if (!p) return
2155-
addCommentToContext({
2156-
file: p,
2157-
selection: range(),
2158-
comment: value,
2159-
origin: "file",
2160-
})
2161-
setCommenting(null)
2162-
}}
2163-
>
2164-
Comment
2165-
</Button>
2166-
</div>
2167-
</div>
2168-
</LineCommentAnchor>
2098+
/>
21692099
</Show>
21702100
)}
21712101
</Show>
Collapse file

‎packages/ui/src/components/line-comment.css‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/line-comment.css
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,64 @@
5252
padding: 8px;
5353
border-radius: 14px;
5454
}
55+
56+
[data-component="line-comment"] [data-slot="line-comment-content"] {
57+
display: flex;
58+
flex-direction: column;
59+
gap: 6px;
60+
}
61+
62+
[data-component="line-comment"] [data-slot="line-comment-text"] {
63+
font-family: var(--font-family-sans);
64+
font-size: var(--font-size-base);
65+
font-weight: var(--font-weight-regular);
66+
line-height: var(--line-height-x-large);
67+
letter-spacing: var(--letter-spacing-normal);
68+
color: var(--text-strong);
69+
white-space: pre-wrap;
70+
}
71+
72+
[data-component="line-comment"] [data-slot="line-comment-label"],
73+
[data-component="line-comment"] [data-slot="line-comment-editor-label"] {
74+
font-family: var(--font-family-sans);
75+
font-size: var(--font-size-small);
76+
font-weight: var(--font-weight-medium);
77+
line-height: var(--line-height-large);
78+
letter-spacing: var(--letter-spacing-normal);
79+
color: var(--text-weak);
80+
white-space: nowrap;
81+
}
82+
83+
[data-component="line-comment"] [data-slot="line-comment-editor"] {
84+
display: flex;
85+
flex-direction: column;
86+
gap: 8px;
87+
}
88+
89+
[data-component="line-comment"] [data-slot="line-comment-textarea"] {
90+
width: 100%;
91+
resize: vertical;
92+
padding: 8px;
93+
border-radius: var(--radius-md);
94+
background: var(--surface-base);
95+
border: 1px solid var(--border-base);
96+
color: var(--text-strong);
97+
font-family: var(--font-family-sans);
98+
font-size: var(--font-size-small);
99+
line-height: var(--line-height-large);
100+
}
101+
102+
[data-component="line-comment"] [data-slot="line-comment-textarea"]:focus {
103+
outline: none;
104+
box-shadow: var(--shadow-xs-border-select);
105+
}
106+
107+
[data-component="line-comment"] [data-slot="line-comment-actions"] {
108+
display: flex;
109+
align-items: center;
110+
gap: 8px;
111+
}
112+
113+
[data-component="line-comment"] [data-slot="line-comment-editor-label"] {
114+
margin-right: auto;
115+
}
Collapse file

‎packages/ui/src/components/line-comment.tsx‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/line-comment.tsx
+104-1Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Show, type JSX } from "solid-js"
1+
import { onMount, Show, splitProps, type JSX } from "solid-js"
2+
import { Button } from "./button"
23
import { Icon } from "./icon"
34

45
export type LineCommentVariant = "default" | "editor"
@@ -52,3 +53,105 @@ export const LineCommentAnchor = (props: LineCommentAnchorProps) => {
5253
</div>
5354
)
5455
}
56+
57+
export type LineCommentProps = Omit<LineCommentAnchorProps, "children" | "variant"> & {
58+
comment: JSX.Element
59+
selection: JSX.Element
60+
}
61+
62+
export const LineComment = (props: LineCommentProps) => {
63+
const [split, rest] = splitProps(props, ["comment", "selection"])
64+
65+
return (
66+
<LineCommentAnchor {...rest} variant="default">
67+
<div data-slot="line-comment-content">
68+
<div data-slot="line-comment-text">{split.comment}</div>
69+
<div data-slot="line-comment-label">Comment on {split.selection}</div>
70+
</div>
71+
</LineCommentAnchor>
72+
)
73+
}
74+
75+
export type LineCommentEditorProps = Omit<LineCommentAnchorProps, "children" | "open" | "variant" | "onClick"> & {
76+
value: string
77+
selection: JSX.Element
78+
onInput: (value: string) => void
79+
onCancel: VoidFunction
80+
onSubmit: (value: string) => void
81+
placeholder?: string
82+
rows?: number
83+
autofocus?: boolean
84+
cancelLabel?: string
85+
submitLabel?: string
86+
}
87+
88+
export const LineCommentEditor = (props: LineCommentEditorProps) => {
89+
const [split, rest] = splitProps(props, [
90+
"value",
91+
"selection",
92+
"onInput",
93+
"onCancel",
94+
"onSubmit",
95+
"placeholder",
96+
"rows",
97+
"autofocus",
98+
"cancelLabel",
99+
"submitLabel",
100+
])
101+
102+
const refs = {
103+
textarea: undefined as HTMLTextAreaElement | undefined,
104+
}
105+
106+
const focus = () => refs.textarea?.focus()
107+
108+
const submit = () => {
109+
const value = split.value.trim()
110+
if (!value) return
111+
split.onSubmit(value)
112+
}
113+
114+
onMount(() => {
115+
if (split.autofocus === false) return
116+
requestAnimationFrame(focus)
117+
})
118+
119+
return (
120+
<LineCommentAnchor {...rest} open={true} variant="editor" onClick={() => focus()}>
121+
<div data-slot="line-comment-editor">
122+
<textarea
123+
ref={(el) => {
124+
refs.textarea = el
125+
}}
126+
data-slot="line-comment-textarea"
127+
rows={split.rows ?? 3}
128+
placeholder={split.placeholder ?? "Add comment"}
129+
value={split.value}
130+
onInput={(e) => split.onInput(e.currentTarget.value)}
131+
onKeyDown={(e) => {
132+
if (e.key === "Escape") {
133+
e.preventDefault()
134+
e.stopPropagation()
135+
split.onCancel()
136+
return
137+
}
138+
if (e.key !== "Enter") return
139+
if (e.shiftKey) return
140+
e.preventDefault()
141+
e.stopPropagation()
142+
submit()
143+
}}
144+
/>
145+
<div data-slot="line-comment-actions">
146+
<div data-slot="line-comment-editor-label">Commenting on {split.selection}</div>
147+
<Button size="small" variant="ghost" onClick={split.onCancel}>
148+
{split.cancelLabel ?? "Cancel"}
149+
</Button>
150+
<Button size="small" variant="primary" disabled={split.value.trim().length === 0} onClick={submit}>
151+
{split.submitLabel ?? "Comment"}
152+
</Button>
153+
</div>
154+
</div>
155+
</LineCommentAnchor>
156+
)
157+
}

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.