GeezerVison is showing github.com — feat(ui): make the line comment card a text field by opencode-agent[bot] · Pull Request #58970 · anomalyco/opencode
feat(ui): make the line comment card a text field
#58970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.css
(3)
.ts
(3)
.tsx
(4)
All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -50,6 +50,12 @@ test("mobile files browse, comment, search, and close tabs", async ({ page }) =>
const comment = files.locator('[data-component="line-comment-v2"][data-variant="display"]')
await expect(comment).toContainText("Full-width file comment")
await expect.poll(() => fullWidth(comment)).toBe(true)
// A click on the card itself opens its editor.
await comment.getByText("Full-width file comment", { exact: true }).click()
await expect(editor.getByRole("textbox", { name: "Comment", exact: true })).toHaveValue("Full-width file comment")
await editor.getByRole("button", { name: "Cancel", exact: true }).click()
await expect(editor).toHaveCount(0)
await expect(comment).toContainText("Full-width file comment")
await page.setViewportSize({ width: 390, height: 844 })
// Its composer chip reveals the comment without leaving the conversation.
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -12,6 +12,7 @@
[data-component="file-tree-v2"] [data-slot="file-tree-v2-row"],
.toast-v2 [data-close-button],
[data-slot="segmented-control-v2-item"],
[data-component="line-comment-v2"][data-variant="display"][data-clickable],
[data-slot="line-comment-v2-overflow"],
[data-slot="line-comment-v2-mention-item"],
[data-slot="text-input-v2-icon-button"],
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -4,3 +4,12 @@ story("renders the line comment cancel action as a ghost button", async ({ mount
const root = await mount("ui-line-comment--editor-filled")
await expect(root.getByRole("button", { name: "Cancel" })).toHaveAttribute("data-variant", "ghost")
})
story("keeps the line breaks of a submitted comment", async ({ mount }) => {
const root = await mount("ui-line-comment--display-multiline")
// toHaveText collapses whitespace, so compare the rendered text exactly.
await expect(root.locator('[data-slot="line-comment-v2-text"]')).toHaveJSProperty(
"innerText",
"Consider guarding against empty arrays.\n\nAn early return keeps the happy path flat.",
)
})
Original file line number
Diff line number
Diff line change
Expand Up
@@ -45,13 +45,13 @@ export type LineCommentStateProps<T> = {
hoverSelected?: (range: SelectedLineRange) => void
}
export type LineCommentShape = {
export type SavedLineComment = {
id: string
selection: SelectedLineRange
comment: string
}
type LineCommentControllerProps<T extends LineCommentShape > = {
type LineCommentControllerProps<T extends SavedLineComment > = {
comments: Accessor<T[]>
draftKey: Accessor<string>
label: string
Expand All
@@ -68,7 +68,7 @@ type LineCommentControllerProps<T extends LineCommentShape> = {
clearSelectionOnSelectionEndNull?: boolean
}
type LineCommentControllerWithSideProps<T extends LineCommentShape > = LineCommentControllerProps<T> & {
type LineCommentControllerWithSideProps<T extends SavedLineComment > = LineCommentControllerProps<T> & {
getSide: (range: SelectedLineRange) => "additions" | "deletions"
}
Expand Down
Expand Up
@@ -230,15 +230,16 @@ function lineCommentDraftElement(view: Accessor<DraftProps>) {
}
export function createLineCommentState<T>(props: LineCommentStateProps<T>) {
const [state, setState] = createStore({
const [state, setState] = createStore<{ draft: string; editing: T | null }> ({
draft: "",
editing: null as T | null ,
editing: null,
})
const draft = () => state.draft
const setDraft = (value: string) => setState("draft", value)
const editing = () => state.editing
const setEditing = (value: T | null) => setState("editing", typeof value === "function" ? () => value : value)
// The updater form stores `value` as is, even when it is itself a function.
const setEditing = (value: T | null) => setState("editing", () => value)
const toRange = (range: SelectedLineRange | null) => (range ? cloneSelectedLineRange(range) : null)
Expand Down
Expand Up
@@ -340,7 +341,7 @@ export function createLineCommentState<T>(props: LineCommentStateProps<T>) {
}
}
export function createLineCommentController<T extends LineCommentShape >(
export function createLineCommentController<T extends SavedLineComment >(
props: LineCommentControllerWithSideProps<T>,
): {
note: ReturnType<typeof createLineCommentState<string>>
Expand All
@@ -352,7 +353,7 @@ export function createLineCommentController<T extends LineCommentShape>(
onLineSelected: (range: SelectedLineRange | null) => void
onLineSelectionEnd: (range: SelectedLineRange | null) => void
}
export function createLineCommentController<T extends LineCommentShape >(
export function createLineCommentController<T extends SavedLineComment >(
props: LineCommentControllerProps<T>,
): {
note: ReturnType<typeof createLineCommentState<string>>
Expand All
@@ -364,7 +365,7 @@ export function createLineCommentController<T extends LineCommentShape>(
onLineSelected: (range: SelectedLineRange | null) => void
onLineSelectionEnd: (range: SelectedLineRange | null) => void
}
export function createLineCommentController<T extends LineCommentShape >(
export function createLineCommentController<T extends SavedLineComment >(
props: LineCommentControllerProps<T> | LineCommentControllerWithSideProps<T>,
) {
const i18n = useI18n()
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -36,7 +36,8 @@
font-family: var(--v2-font-family-sans, "Inter", sans-serif);
font-style: normal;
font-size: 11px;
line-height: 12px;
/* Inter's descenders need 14px at 11px; a tighter line box clips them where the text truncates. */
line-height: 14px;
letter-spacing: 0.05px;
font-variation-settings: "slnt" 0;
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -13,7 +13,19 @@ export function createHoverCommentUtility(props: {
const button = document.createElement("button")
button.type = "button"
button.ariaLabel = props.label
button.textContent = "+"
// A drawn plus, unlike a "+" glyph, is centered regardless of the font's metrics.
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
icon.setAttribute("width", "12")
icon.setAttribute("height", "12")
icon.setAttribute("viewBox", "0 0 12 12")
icon.setAttribute("fill", "none")
icon.setAttribute("aria-hidden", "true")
const plus = document.createElementNS("http://www.w3.org/2000/svg", "path")
plus.setAttribute("d", "M6 2V10M2 6H10")
plus.setAttribute("stroke", "currentColor")
plus.setAttribute("stroke-width", "1.5")
icon.append(plus)
button.append(icon)
button.style.width = "20px"
button.style.height = "20px"
button.style.display = "flex"
Expand All
@@ -24,8 +36,7 @@ export function createHoverCommentUtility(props: {
button.style.background = "var(--icon-interactive-base)"
button.style.color = "var(--white)"
button.style.boxShadow = "var(--shadow-xs)"
button.style.fontSize = "14px"
button.style.lineHeight = "1"
button.style.padding = "0"
button.style.cursor = "pointer"
button.style.position = "relative"
button.style.left = "30px"
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -5,14 +5,14 @@ import {
createLineCommentGutterRenderer,
createLineCommentState,
createManagedLineCommentAnnotationRenderer,
type LineCommentShape ,
type SavedLineComment ,
type LineCommentStateProps,
} from "../../components/line-comment-annotations"
import { useI18n } from "@opencode/ui/context/i18n"
import { cloneSelectedLineRange, formatSelectedLineLabel } from "../../pierre/selection-bridge"
import { cloneSelectedLineRange } from "../../pierre/selection-bridge"
import { LineCommentEditor, LineComment, type LineCommentEditorMention } from "@opencode/ui/line-comment"
type LineCommentControllerV2Props<T extends LineCommentShape > = {
type LineCommentControllerV2Props<T extends SavedLineComment > = {
comments: Accessor<T[]>
draftKey: Accessor<string>
label: string
Expand All
@@ -29,16 +29,15 @@ type LineCommentControllerV2Props<T extends LineCommentShape> = {
type CommentProps = {
id?: string
comment: JSX.Element
selection: JSX.Element
actions?: JSX.Element
editor?: DraftProps
onOpen?: VoidFunction
onClick?: JSX.EventHandlerUnion<HTMLDivElement, MouseEvent>
onMouseEnter?: JSX.EventHandlerUnion<HTMLDivElement, MouseEvent>
}
type DraftProps = {
value: string
selection: JSX.Element
onInput: (value: string) => void
onCancel: VoidFunction
onSubmit: (value: string) => void
Expand All
@@ -59,14 +58,13 @@ function lineCommentElementV2(view: Accessor<CommentProps>) {
onClick={view().onClick}
onMouseEnter={view().onMouseEnter}
>
<LineComment comment={view().comment} selection ={view().selection} actions ={view().actions } />
<LineComment comment={view().comment} actions ={view().actions} onOpen ={view().onOpen } />
</div>
}
>
<div data-prevent-autofocus="" data-comment-id={view().id} onMouseDown={(event) => event.stopPropagation()}>
<LineCommentEditor
value={view().editor!.value}
selection={view().editor!.selection}
onInput={view().editor!.onInput}
onCancel={view().editor!.onCancel}
onSubmit={view().editor!.onSubmit}
Expand All
@@ -84,7 +82,6 @@ function lineCommentDraftElementV2(view: Accessor<DraftProps>) {
<div data-prevent-autofocus="" onMouseDown={(event) => event.stopPropagation()}>
<LineCommentEditor
value={view().value}
selection={view().selection}
onInput={view().onInput}
onCancel={view().onCancel}
onSubmit={view().onSubmit}
Expand All
@@ -96,7 +93,7 @@ function lineCommentDraftElementV2(view: Accessor<DraftProps>) {
)
}
export function createLineCommentControllerV2<T extends LineCommentShape >(props: LineCommentControllerV2Props<T>) {
export function createLineCommentControllerV2<T extends SavedLineComment >(props: LineCommentControllerV2Props<T>) {
const i18n = useI18n()
const note = createLineCommentState<string>(props.state)
Expand Down
Expand Up
@@ -124,7 +121,8 @@ export function createLineCommentControllerV2<T extends LineCommentShape>(props:
return {
id: comment.id,
comment: comment.comment,
selection: formatSelectedLineLabel(comment.selection, i18n.t),
// A comment with actions (its menu offers Edit) also opens its editor from a click on the card.
onOpen: props.renderCommentActions ? edit : undefined,
get actions() {
return props.renderCommentActions?.(comment, { edit, remove })
},
Expand All
@@ -134,7 +132,6 @@ export function createLineCommentControllerV2<T extends LineCommentShape>(props:
get value() {
return note.draft()
},
selection: formatSelectedLineLabel(comment.selection, i18n.t),
onInput: note.setDraft,
onCancel: note.cancelDraft,
onSubmit: (value: string) => {
Expand All
@@ -156,7 +153,7 @@ export function createLineCommentControllerV2<T extends LineCommentShape>(props:
note.hoverComment(comment.selection)
},
onClick: () => {
if (note.isEditing(comment.id)) return
if (props.renderCommentActions || note.isEditing(comment.id)) return
note.toggleComment(comment.id, comment.selection)
},
}
Expand All
@@ -165,7 +162,6 @@ export function createLineCommentControllerV2<T extends LineCommentShape>(props:
get value() {
return note.draft()
},
selection: formatSelectedLineLabel(range, i18n.t),
onInput: note.setDraft,
onCancel: () => {
note.cancelDraft()
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -43,6 +43,16 @@
min-width: 0;
}
[data-component="line-comment-v2"][data-variant="display"][data-clickable] {
cursor: pointer;
}
[data-component="line-comment-v2"][data-variant="display"][data-clickable]:hover [data-slot="line-comment-v2-shell"] {
background:
linear-gradient(var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)),
var(--v2-background-bg-layer-01);
}
[data-component="line-comment-v2"][data-variant="display"] [data-slot="line-comment-v2-text"] {
margin: 0;
width: 100%;
Expand All
@@ -53,6 +63,8 @@
letter-spacing: -0.04px;
color: var(--v2-text-text-base);
font-variation-settings: "slnt" 0;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
[data-component="line-comment-v2"][data-variant="display"] [data-slot="line-comment-v2-meta"] {
Expand Down
Expand Up
@@ -130,36 +142,19 @@
min-width: 0;
}
[data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-label"] {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
font-size: 13px;
font-style: normal;
font-weight: 530;
line-height: var(--line-height-compact);
letter-spacing: -0.04px;
color: var(--v2-text-text-base);
user-select: none;
}
[data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-textarea"] {
display: block;
width: 100%;
min-width: 0;
min-height: 80px;
padding: 8px;
padding: 0;
margin: 0;
resize: vertical;
border: 1px solid var(--v2-border-border-base);
border-radius: 6px;
background:
linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
resize: none;
border: none;
background: transparent;
font-size: 13px;
font-style: normal;
font-weight: 440;
line-height: 1.35 ;
line-height: var(--line-height-compact) ;
letter-spacing: -0.04px;
color: var(--v2-text-text-base);
font-variation-settings: "slnt" 0;
Expand All
@@ -171,10 +166,6 @@
user-select: none;
}
[data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-textarea"]:focus {
border-color: var(--v2-border-border-focus);
}
[data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-footer"] {
display: flex;
flex-direction: row;
Expand Down
Expand Up
@@ -202,6 +193,7 @@
align-items: center;
gap: 8px;
flex-shrink: 0;
margin-inline-start: auto;
}
[data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-mention-list"] {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -4,14 +4,14 @@ import { LineCommentEditor, LineComment, LineCommentOverflowIcon } from "./line-
import { Menu } from "../../navigation/menu/menu"
const docs = `### Overview
Line comment **display** and **editor** cards aligned with OpenCode line-comment specs (raised \`#FAFAFA\` surface, footer line context, \`Button\` ghost + contrast actions).
Line comment **display** and **editor** cards aligned with OpenCode line-comment specs (raised \`#FAFAFA\` surface, small \`Button\` ghost + contrast actions).
### Display
- \`LineComment\`: column stack (body + meta) beside optional \`actions\` (overflow).
- \`LineComment\`: column stack (body + optional meta) beside optional \`actions\` (overflow). The body keeps its line breaks. \`onOpen\` makes a click anywhere on the card open it .
- Use \`LineCommentOverflowIcon\` inside a \`data-slot="line-comment-v2-overflow"\` button for the Figma dots control.
### Editor
- \`LineCommentEditor\`: optional \`heading \` above the textarea ( default “Comment”), footer (selection meta + Cancel / Comment).
- \`LineCommentEditor\`: the card is the text field (\`label \` names it, default “Comment”), footer (optional selection meta + Cancel / Comment).
- \`Enter\` submits (Shift+Enter newline); \`Escape\` cancels. Controlled via \`value\` / \`onInput\`.
`
Expand All
@@ -34,7 +34,6 @@ export const Display = {
<div style={{ width: "400px" }}>
<LineComment
comment="Consider guarding against empty arrays."
selection="Comment on line 40"
actions={
<Menu gutter={4}>
<Menu.Trigger as="button" type="button" data-slot="line-comment-v2-overflow" aria-label="Comment actions">
Expand All
@@ -56,7 +55,15 @@ export const Display = {
export const DisplayWithoutActions = {
render: () => (
<div style={{ width: "400px" }}>
<LineComment comment="Consider guarding against empty arrays." selection="Comment on line 40" />
<LineComment comment="Consider guarding against empty arrays." />
</div>
),
}
export const DisplayMultiline = {
render: () => (
<div style={{ width: "400px" }}>
<LineComment comment={"Consider guarding against empty arrays.\n\nAn early return keeps the happy path flat."} />
</div>
),
}
Expand All
@@ -72,7 +79,6 @@ export const Editor = {
onInput={setValue}
onCancel={() => setValue("")}
onSubmit={() => setValue("")}
selection="Comment on line 40"
/>
</div>
)
Expand All
@@ -90,7 +96,6 @@ export const EditorFilled = {
onInput={setValue}
onCancel={() => setValue("")}
onSubmit={() => {}}
selection="Comment on line 40"
autofocus={false}
/>
</div>
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.