Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export function createCopyMode(input: {
setState((prev) => ({
...prev,
visual: mode,
anchor: { idx: prev.idx, col: prev.col },
anchor: prev.anchor ?? { idx: prev.idx, col: prev.col },
}))
}

Expand Down
44 changes: 42 additions & 2 deletions packages/opencode/test/cli/tui/vim-motions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, test } from "bun:test"
import type { TextareaRenderable } from "@opentui/core"
import { createSignal } from "solid-js"
import type { ScrollBoxRenderable, TextareaRenderable } from "@opentui/core"
import type { Part } from "@opencode-ai/sdk/v2"
import { createRoot, createSignal } from "solid-js"
import { createCopyMode } from "../../../src/cli/cmd/tui/routes/session/copy-mode"
import { createVimHandler } from "../../../src/cli/cmd/tui/component/vim/vim-handler"
import { createVimState } from "../../../src/cli/cmd/tui/component/vim/vim-state"
import type { VimScroll } from "../../../src/cli/cmd/tui/component/vim/vim-scroll"
Expand Down Expand Up @@ -4507,6 +4509,44 @@ describe("copy mode", () => {
expect(ctx.copyVisualCalls).not.toContain("char")
})

test("V after characterwise visual preserves copy anchor", () => {
createRoot((dispose) => {
const children = [
{ id: "text-part", y: 0, height: 1 },
{ id: "text-part", y: 1, height: 1 },
{ id: "text-part", y: 2, height: 1 },
]
const scroll = {
y: 0,
height: 3,
width: 80,
getChildren: () => children,
scrollBy(delta: number) {
scroll.y += delta
},
} as unknown as ScrollBoxRenderable
const cm = createCopyMode({
scroll: () => scroll,
messages: () => [{ id: "msg", role: "assistant" }],
parts: () => [{ type: "text", id: "part" } as Part],
thinking: () => false,
details: () => false,
session: () => "session",
toBottom() {},
})

cm.prompt.enter()
cm.prompt.visual("char")
cm.prompt.move("up")
cm.prompt.visual("line")

expect(cm.state().visual).toBe("line")
expect(cm.state().anchor).toEqual({ idx: 2, col: 3 })
expect(cm.state().idx).toBe(1)
dispose()
})
})

test("y yanks copy selection and exits copy mode", () => {
const ctx = createHandler("abc", { mode: "copy", copy: { text: "picked text", isVisual: true } })

Expand Down
Loading