Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/core/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export class ScanController {
}

setOptions(options: Partial<ScanOptions>): 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<ScanOptions>;
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;
Expand Down
10 changes: 10 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Loading