mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-29 03:32:08 +08:00
fix(vscode): prevent recursive settings saves (#12561)
* fix(vscode): prevent recursive settings saves * docs: clarify settings save release note
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"kilo-code": patch
|
||||
---
|
||||
|
||||
Fix settings changes sometimes failing to save and apply in VS Code.
|
||||
@@ -0,0 +1,4 @@
|
||||
export function changed<T>(current: T | undefined, next: T | undefined, key: (item: T) => string) {
|
||||
if (current === undefined || next === undefined) return current !== next
|
||||
return key(current) !== key(next)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { changed } from "./select-change"
|
||||
|
||||
describe("changed", () => {
|
||||
const key = (item: { value: string }) => item.value
|
||||
|
||||
test("ignores recreated options with the current key", () => {
|
||||
expect(changed({ value: "ollama" }, { value: "ollama" }, key)).toBe(false)
|
||||
})
|
||||
|
||||
test("reports selected and cleared values", () => {
|
||||
expect(changed({ value: "ollama" }, { value: "kilo" }, key)).toBe(true)
|
||||
expect(changed({ value: "ollama" }, undefined, key)).toBe(true)
|
||||
expect(changed(undefined, { value: "ollama" }, key)).toBe(true)
|
||||
expect(changed(undefined, undefined, key)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -1 +1,19 @@
|
||||
import { Select as Base, type SelectProps } from "@opencode-ai/ui/select"
|
||||
import type { ButtonProps } from "@opencode-ai/ui/button"
|
||||
import { changed } from "./select-change"
|
||||
|
||||
export * from "@opencode-ai/ui/select"
|
||||
|
||||
export function Select<T>(props: SelectProps<T> & Omit<ButtonProps, "children">) {
|
||||
const key = (item: T) => (props.value ? props.value(item) : (item as string))
|
||||
|
||||
return (
|
||||
<Base
|
||||
{...props}
|
||||
onSelect={(next) => {
|
||||
if (!changed(props.current, next, key)) return
|
||||
props.onSelect?.(next)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user