mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-24 08:22:37 +00:00
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.
53 lines
1.3 KiB
TypeScript
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"])
|
|
})
|