Skip to content

Commit 2d9b0b2

Browse files
committed
remove yy copy mode implementation
1 parent ad9b21a commit 2d9b0b2

3 files changed

Lines changed: 7 additions & 57 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/vim/vim-handler.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export function createVimHandler(input: {
7373
copyExitVisual?: () => void
7474
copyExit?: (scrollToBottom?: boolean) => void
7575
copyYank?: () => void
76-
copyYankLine?: () => void
7776
copyCopy?: () => void
7877
copyIsVisual?: () => boolean
7978
copyJump?: (action: VimJump) => void
@@ -836,23 +835,12 @@ export function createVimHandler(input: {
836835
return true
837836
}
838837

839-
if (key === "y" && input.state.pending() === "y") {
840-
// yy — yank current line with flash highlight
841-
input.state.clearPending()
842-
input.copyYankLine?.()
843-
event.preventDefault()
844-
return true
845-
}
846-
847838
if (key === "y") {
848-
if (!input.copyIsVisual?.()) {
849-
// first y — set pending for yy
850-
input.state.setPending("y")
851-
} else {
852-
// y in visual — yank selection, flash highlight then clear
839+
if (input.copyIsVisual?.()) {
853840
input.copyYank?.()
854-
setTimeout(() => input.copyExitVisual?.(), 150)
841+
input.copyExitVisual?.()
855842
}
843+
input.copyExit?.(true)
856844
event.preventDefault()
857845
return true
858846
}

packages/opencode/src/cli/cmd/tui/routes/session/copy-mode.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -490,19 +490,6 @@ export function createCopyMode(input: {
490490
setState((s) => ({ ...s, visual: undefined, anchor: undefined }))
491491
}
492492

493-
let yankFlashTimer: ReturnType<typeof setTimeout> | undefined
494-
function yankLine() {
495-
visual("line")
496-
const reg = yank()
497-
// Keep the highlight visible briefly, then clear
498-
if (yankFlashTimer) clearTimeout(yankFlashTimer)
499-
yankFlashTimer = setTimeout(() => {
500-
yankFlashTimer = undefined
501-
exitVisual()
502-
}, 150)
503-
return reg
504-
}
505-
506493
function selectionText(): string {
507494
const s = state()
508495
if (!s.visual || !s.anchor) return ""
@@ -701,7 +688,6 @@ export function createCopyMode(input: {
701688
exit: (scrollToBottom?: boolean) => exit(scrollToBottom),
702689
visual,
703690
yank,
704-
yankLine,
705691
copy,
706692
isVisual: () => !!state().visual,
707693
exitVisual,

packages/opencode/test/cli/tui/vim-motions.test.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,6 @@ function createHandler(
301301
copyYanks++
302302
state.setRegister({ text: options?.copy?.text ?? "picked", linewise: false })
303303
},
304-
copyYankLine() {
305-
copyYanks++
306-
state.setRegister({ text: options?.copy?.text ?? "picked line", linewise: true })
307-
},
308304
copyExit(scrollToBottom) {
309305
copyExits.push(scrollToBottom)
310306
},
@@ -2647,7 +2643,7 @@ describe("copy mode", () => {
26472643
expect(ctx.copyVisualCalls).not.toContain("char")
26482644
})
26492645

2650-
test("y yanks copy selection and stays in copy mode", () => {
2646+
test("y yanks copy selection in copy mode", () => {
26512647
const ctx = createHandler("abc", { mode: "copy", copy: { text: "picked text", isVisual: true } })
26522648

26532649
const evt = createEvent("y")
@@ -2656,7 +2652,7 @@ describe("copy mode", () => {
26562652
expect(ctx.copyYanks()).toBe(1)
26572653
expect(ctx.copyCopies()).toBe(0)
26582654
expect(ctx.state.register()).toEqual({ text: "picked text", linewise: false })
2659-
expect(ctx.state.mode()).toBe("copy")
2655+
expect(ctx.copyExits).toEqual([true])
26602656
})
26612657

26622658
test("return copies selection to clipboard path and exits copy mode", () => {
@@ -2880,33 +2876,13 @@ describe("copy mode", () => {
28802876
expect(ctx.copyExits).toEqual([false])
28812877
})
28822878

2883-
test("y in visual mode yanks and exits visual but stays in copy mode", () => {
2879+
test("y in visual mode in copy mode yanks and exits copy mode", () => {
28842880
const ctx = createHandler("abc", { mode: "copy", copy: { text: "selected", isVisual: true } })
28852881
const evt = createEvent("y")
28862882
expect(ctx.handler.handleKey(evt.event)).toBe(true)
28872883
expect(ctx.copyYanks()).toBe(1)
28882884
expect(ctx.state.register()).toEqual({ text: "selected", linewise: false })
2889-
expect(ctx.state.mode()).toBe("copy")
2890-
})
2891-
2892-
test("y without visual sets pending y for yy", () => {
2893-
const ctx = createHandler("abc", { mode: "copy" })
2894-
const evt = createEvent("y")
2895-
expect(ctx.handler.handleKey(evt.event)).toBe(true)
2896-
expect(ctx.state.pending()).toBe("y")
2897-
expect(ctx.copyYanks()).toBe(0)
2898-
expect(ctx.state.mode()).toBe("copy")
2899-
})
2900-
2901-
test("yy yanks current line and stays in copy mode", () => {
2902-
const ctx = createHandler("abc", { mode: "copy", copy: { text: "whole line" } })
2903-
ctx.handler.handleKey(createEvent("y").event)
2904-
expect(ctx.state.pending()).toBe("y")
2905-
ctx.handler.handleKey(createEvent("y").event)
2906-
expect(ctx.state.pending()).toBe("")
2907-
expect(ctx.copyYanks()).toBe(1)
2908-
expect(ctx.state.register()).toEqual({ text: "whole line", linewise: true })
2909-
expect(ctx.state.mode()).toBe("copy")
2885+
expect(ctx.copyExits).toEqual([true])
29102886
})
29112887

29122888
test("Ctrl+W j from visual in copy mode exits visual not copy", () => {

0 commit comments

Comments
 (0)