Skip to content

Commit fa7ef7f

Browse files
authored
feat: copy mode cursor line (#31)
* feat: add cursor line highlight in copy mode * feat: hide cursor line highlight in visual mode --------- Co-authored-by: leohenon <77656081+lhenon999@users.noreply.github.com>
1 parent 84c91c0 commit fa7ef7f

File tree

1 file changed

+36
-6
lines changed
  • packages/opencode/src/cli/cmd/tui/routes/session

1 file changed

+36
-6
lines changed

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ export function Session() {
11741174
<UserMessage
11751175
copy={
11761176
cm.row()?.kind === "user" && cm.row()?.id === message.id
1177-
? { line: cm.row()!.line, col: cm.state().col }
1177+
? { line: cm.row()!.line, col: cm.state().col, visual: !!cm.state().visual }
11781178
: undefined
11791179
}
11801180
highlights={cm.highlights().get(message.id) ?? []}
@@ -1196,7 +1196,7 @@ export function Session() {
11961196
</Match>
11971197
<Match when={message.role === "assistant"}>
11981198
<AssistantMessage
1199-
copy={cm.row() ? { ...cm.row()!, col: cm.state().col } : undefined}
1199+
copy={cm.row() ? { ...cm.row()!, col: cm.state().col, visual: !!cm.state().visual } : undefined}
12001200
highlights={cm.highlights()}
12011201
last={lastAssistant()?.id === message.id}
12021202
message={message as AssistantMessage}
@@ -1276,7 +1276,7 @@ function UserMessage(props: {
12761276
onMouseUp: () => void
12771277
index: number
12781278
pending?: string
1279-
copy?: { line: number; col: number }
1279+
copy?: { line: number; col: number; visual?: boolean }
12801280
highlights?: CopyHighlight[]
12811281
}) {
12821282
const ctx = use()
@@ -1318,6 +1318,16 @@ function UserMessage(props: {
13181318
flexShrink={0}
13191319
>
13201320
<Show when={props.copy}>
1321+
<Show when={!props.copy?.visual}>
1322+
<box
1323+
position="absolute"
1324+
top={(props.copy?.line ?? 0) + 1}
1325+
left={0}
1326+
width="100%"
1327+
height={1}
1328+
backgroundColor={RGBA.fromInts(255, 255, 255, 15)}
1329+
/>
1330+
</Show>
13211331
<box position="absolute" top={(props.copy?.line ?? 0) + 1} left={props.copy?.col ?? 0}>
13221332
<text fg={theme.text}></text>
13231333
</box>
@@ -1387,7 +1397,7 @@ function AssistantMessage(props: {
13871397
message: AssistantMessage
13881398
parts: Part[]
13891399
last: boolean
1390-
copy?: CopyRow
1400+
copy?: CopyRow & { visual?: boolean }
13911401
highlights?: Map<string, CopyHighlight[]>
13921402
}) {
13931403
const ctx = use()
@@ -1532,7 +1542,7 @@ function TextPart(props: {
15321542
last: boolean
15331543
part: TextPart
15341544
message: AssistantMessage
1535-
copy?: CopyRow
1545+
copy?: CopyRow & { visual?: boolean }
15361546
highlights?: CopyHighlight[]
15371547
}) {
15381548
const ctx = use()
@@ -1541,6 +1551,16 @@ function TextPart(props: {
15411551
<Show when={props.part.text.trim()}>
15421552
<box id={"text-" + props.part.id} paddingLeft={3} marginTop={1} flexShrink={0}>
15431553
<Show when={props.copy?.kind === "text" && props.copy.part === props.part.id}>
1554+
<Show when={!props.copy?.visual}>
1555+
<box
1556+
position="absolute"
1557+
top={props.copy?.line ?? 0}
1558+
left={0}
1559+
width="100%"
1560+
height={1}
1561+
backgroundColor={RGBA.fromInts(255, 255, 255, 15)}
1562+
/>
1563+
</Show>
15441564
<box position="absolute" top={props.copy?.line ?? 0} left={props.copy?.col ?? 0}>
15451565
<text fg={theme.text}></text>
15461566
</box>
@@ -1588,7 +1608,7 @@ function ToolPart(props: {
15881608
last: boolean
15891609
part: ToolPart
15901610
message: AssistantMessage
1591-
copy?: CopyRow
1611+
copy?: CopyRow & { visual?: boolean }
15921612
highlights?: CopyHighlight[]
15931613
}) {
15941614
const ctx = use()
@@ -1632,6 +1652,16 @@ function ToolPart(props: {
16321652
<Show when={!shouldHide()}>
16331653
<box id={"tool-" + props.part.id}>
16341654
<Show when={props.copy?.kind === "tool" && props.copy.part === props.part.id}>
1655+
<Show when={!props.copy?.visual}>
1656+
<box
1657+
position="absolute"
1658+
top={props.copy?.line ?? 0}
1659+
left={0}
1660+
width="100%"
1661+
height={1}
1662+
backgroundColor={RGBA.fromInts(255, 255, 255, 15)}
1663+
/>
1664+
</Show>
16351665
<box position="absolute" top={props.copy?.line ?? 0} left={props.copy?.col ?? 0}>
16361666
<text fg={theme.text}></text>
16371667
</box>

0 commit comments

Comments
 (0)