opencode/packages/tui/test/util/selection.test.ts
Simon Klee 0d24ebdbbe
tui: preserve selection after copy (#44496)
Copy-on-select reset the click counter, so a third click could not select the full line. Keep the selection after copying to preserve multi-click input.
2026-08-23 20:40:19 +02:00

53 lines
1.3 KiB
TypeScript

import { expect, test } from "bun:test"
import { copy, copyOnSelectRelease } from "../../src/util/selection"
function renderer() {
return {
getSelection: () => ({
getSelectedText: () => "beta",
selectedRenderables: [],
}),
clearSelection: () => {},
}
}
test("copy writes selected text without clearing the highlight", () => {
let cleared = false
const copied = copy(
{
getSelection: () => ({
getSelectedText: () => "beta",
selectedRenderables: [],
}),
clearSelection: () => {
cleared = true
},
},
{ show: () => {}, error: () => {} },
{
async read() {
return undefined
},
async write() {},
},
)
expect(copied).toBe(true)
expect(cleared).toBe(false)
})
test("copy-on-select ignores a later non-drag release", () => {
const writes: string[] = []
const clipboard = {
async read() {
return undefined
},
async write(value: string) {
writes.push(value)
},
}
const toast = { show: () => {}, error: () => {} }
expect(copyOnSelectRelease({}, renderer(), toast, clipboard)).toBe(false)
expect(copyOnSelectRelease({ isDragging: false }, renderer(), toast, clipboard)).toBe(false)
expect(copyOnSelectRelease({ isDragging: true }, renderer(), toast, clipboard)).toBe(true)
expect(writes).toEqual(["beta"])
})