diff --git a/package.json b/package.json index e473128..e26e8b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@switchify/scanning", - "version": "0.3.0", + "version": "0.3.1", "description": "Switch scanning for React and React Native, ported from Switchify PC.", "license": "AGPL-3.0-only", "type": "module", diff --git a/src/core/controller.ts b/src/core/controller.ts index d33e91f..2707594 100644 --- a/src/core/controller.ts +++ b/src/core/controller.ts @@ -174,7 +174,9 @@ export class ScanController { } setOptions(options: Partial): void { - const next = resolveOptions({ ...this.scanner.options, ...options }); + // An option left undefined keeps its current value rather than resetting to the default. + const given = Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)) as Partial; + const next = resolveOptions({ ...this.scanner.options, ...given }); const current = this.scanner.options; if ((Object.keys(next) as (keyof ScanOptions)[]).every((key) => next[key] === current[key])) { return; diff --git a/test/controller.test.ts b/test/controller.test.ts index 104d907..0e8dd1b 100644 --- a/test/controller.test.ts +++ b/test/controller.test.ts @@ -289,3 +289,13 @@ test("an exclusive group confines scanning until it is removed", async () => { await Promise.resolve(); expect(highlight(controller)).toEqual({ kind: "item", id: "page-a" }); }); + +test("options left undefined keep their current values", () => { + const { controller, clock } = setup({ options: { automatic: false, intervalMs: 700 } }); + controller.setOptions({ automatic: undefined, intervalMs: undefined, pattern: "linear" }); + expect(controller.options).toMatchObject({ automatic: false, intervalMs: 700, pattern: "linear" }); + controller.registerItem("a"); + controller.flush(); + controller.start(); + expect(clock.running()).toBe(false); +});