diff options
| author | Adam <[email protected]> | 2026-01-21 05:27:52 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2026-01-22 22:12:12 -0600 |
| commit | 0ce0cacb282c47943348a2af21ea00e721bcb9d9 (patch) | |
| tree | e1c17ec3dc03ce1fd86f348059a6401e700eb60d /packages/app/src/pages | |
| parent | 640d1f1ecc7a2b46fb2bafed760c7348c70579a8 (diff) | |
| download | opencode-0ce0cacb282c47943348a2af21ea00e721bcb9d9.tar.gz opencode-0ce0cacb282c47943348a2af21ea00e721bcb9d9.zip | |
wip(app): line selection
Diffstat (limited to 'packages/app/src/pages')
| -rw-r--r-- | packages/app/src/pages/session.tsx | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/packages/app/src/pages/session.tsx b/packages/app/src/pages/session.tsx index ad6d360dc..1e0d7a89e 100644 --- a/packages/app/src/pages/session.tsx +++ b/packages/app/src/pages/session.tsx @@ -81,6 +81,7 @@ interface SessionReviewTabProps { diffStyle: DiffStyle onDiffStyleChange?: (style: DiffStyle) => void onViewFile?: (file: string) => void + onLineComment?: (comment: { file: string; selection: SelectedLineRange; comment: string; preview?: string }) => void classes?: { root?: string header?: string @@ -166,6 +167,7 @@ function SessionReviewTab(props: SessionReviewTabProps) { onDiffStyleChange={props.onDiffStyleChange} onViewFile={props.onViewFile} readFile={readFile} + onLineComment={props.onLineComment} /> ) } @@ -488,8 +490,36 @@ export default function Page() { setStore("expanded", id, status().type !== "idle") }) + const selectionPreview = (path: string, selection: FileSelection) => { + const content = file.get(path)?.content?.content + if (!content) return undefined + const start = Math.max(1, Math.min(selection.startLine, selection.endLine)) + const end = Math.max(selection.startLine, selection.endLine) + const lines = content.split("\n").slice(start - 1, end) + if (lines.length === 0) return undefined + return lines.slice(0, 2).join("\n") + } + const addSelectionToContext = (path: string, selection: FileSelection) => { - prompt.context.add({ type: "file", path, selection }) + const preview = selectionPreview(path, selection) + prompt.context.add({ type: "file", path, selection, preview }) + } + + const addCommentToContext = (input: { + file: string + selection: SelectedLineRange + comment: string + preview?: string + }) => { + const selection = selectionFromLines(input.selection) + const preview = input.preview ?? selectionPreview(input.file, selection) + prompt.context.add({ + type: "file", + path: input.file, + selection, + comment: input.comment, + preview, + }) } command.register(() => [ @@ -1402,6 +1432,7 @@ export default function Page() { diffs={diffs} view={view} diffStyle="unified" + onLineComment={addCommentToContext} onViewFile={(path) => { const value = file.tab(path) tabs().open(value) @@ -1717,6 +1748,7 @@ export default function Page() { view={view} diffStyle={layout.review.diffStyle()} onDiffStyleChange={layout.review.setDiffStyle} + onLineComment={addCommentToContext} onViewFile={(path) => { const value = file.tab(path) tabs().open(value) |
