Skip to content

Commit b6380b9

Browse files
committed
fix: remove yy
1 parent ad9b21a commit b6380b9

5 files changed

Lines changed: 5 additions & 111 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export type PromptProps = {
9292
exit: (scrollToBottom?: boolean) => void
9393
visual: (mode: "char" | "line") => void
9494
yank: () => { text: string; linewise: boolean } | null
95-
yankLine: () => { text: string; linewise: boolean } | null
9695
copy: () => Promise<void> | void
9796
isVisual: () => boolean
9897
exitVisual: () => void
@@ -455,10 +454,6 @@ export function Prompt(props: PromptProps) {
455454
const reg = props.copy?.yank()
456455
if (reg) vimState.setRegister(reg)
457456
},
458-
copyYankLine() {
459-
const reg = props.copy?.yankLine()
460-
if (reg) vimState.setRegister(reg)
461-
},
462457
copyCopy() {
463458
return props.copy?.copy()
464459
},

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

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ import {
4242
toggleCase,
4343
toggleSelectionCase,
4444
wordEnd,
45-
yankLine,
46-
yankLineSpan,
4745
yankSelection,
48-
yankWord,
49-
yankWordSpan,
5046
} from "./vim-motions"
5147

5248
export type VimEvent = {
@@ -73,7 +69,6 @@ export function createVimHandler(input: {
7369
copyExitVisual?: () => void
7470
copyExit?: (scrollToBottom?: boolean) => void
7571
copyYank?: () => void
76-
copyYankLine?: () => void
7772
copyCopy?: () => void
7873
copyIsVisual?: () => boolean
7974
copyJump?: (action: VimJump) => void
@@ -376,35 +371,6 @@ export function createVimHandler(input: {
376371
input.state.clearPending()
377372
}
378373

379-
if (input.state.pending() === "y") {
380-
if (key === "y" && !event.shift && !hasModifier(event)) {
381-
const span = yankLineSpan(input.textarea())
382-
const reg = yankLine(input.textarea())
383-
if (reg) input.state.setRegister(reg)
384-
if (span.end > span.start) input.flash?.(span)
385-
input.state.clearPending()
386-
event.preventDefault()
387-
return true
388-
}
389-
390-
if (key === "w" && !event.shift && !hasModifier(event)) {
391-
const span = yankWordSpan(input.textarea())
392-
const reg = yankWord(input.textarea())
393-
if (reg) input.state.setRegister(reg)
394-
if (span && span.end > span.start) input.flash?.(span)
395-
input.state.clearPending()
396-
event.preventDefault()
397-
return true
398-
}
399-
400-
if (hasModifier(event)) {
401-
input.state.clearPending()
402-
return false
403-
}
404-
405-
input.state.clearPending()
406-
}
407-
408374
const find = input.state.pending()
409375
if (find === "f" || find === "F" || find === "t" || find === "T") {
410376
if (isPrintable(event) && !hasModifier(event)) {
@@ -449,12 +415,6 @@ export function createVimHandler(input: {
449415
return true
450416
}
451417

452-
if (key === "y" && !event.shift && !hasModifier(event)) {
453-
input.state.setPending("y")
454-
event.preventDefault()
455-
return true
456-
}
457-
458418
if (key === "p" && !event.shift && !hasModifier(event)) {
459419
edit(() => {
460420
pasteAfter(input.textarea(), input.state.register())
@@ -836,23 +796,9 @@ export function createVimHandler(input: {
836796
return true
837797
}
838798

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-
847799
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
853-
input.copyYank?.()
854-
setTimeout(() => input.copyExitVisual?.(), 150)
855-
}
800+
input.copyYank?.()
801+
input.state.setMode("normal")
856802
event.preventDefault()
857803
return true
858804
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createEffect, createMemo, createSignal, type Accessor } from "solid-js"
22

33
export type VimMode = "normal" | "insert" | "replace" | "visual" | "visual-line" | "copy"
4-
export type VimPending = "" | "c" | "d" | "g" | "z" | "f" | "F" | "t" | "T" | "y" | "w"
4+
export type VimPending = "" | "c" | "d" | "g" | "z" | "f" | "F" | "t" | "T" | "w"
55
export type VimFind = { char: string; forward: boolean; till: boolean } | null
66
export type VimRegister = { text: string; linewise: boolean } | null
77
export type VimSnapshot = { text: string; cursor: number; data?: unknown }

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: 2 additions & 35 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 and exits 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.state.mode()).toBe("normal")
26602656
})
26612657

26622658
test("return copies selection to clipboard path and exits copy mode", () => {
@@ -2880,35 +2876,6 @@ 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", () => {
2884-
const ctx = createHandler("abc", { mode: "copy", copy: { text: "selected", isVisual: true } })
2885-
const evt = createEvent("y")
2886-
expect(ctx.handler.handleKey(evt.event)).toBe(true)
2887-
expect(ctx.copyYanks()).toBe(1)
2888-
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")
2910-
})
2911-
29122879
test("Ctrl+W j from visual in copy mode exits visual not copy", () => {
29132880
const ctx = createHandler("abc", { mode: "copy", copy: { isVisual: true } })
29142881
ctx.handler.handleKey(createEvent("w", { ctrl: true }).event)

0 commit comments

Comments
 (0)