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
14 changes: 13 additions & 1 deletion src/ui/options/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,29 @@ function wireImportExportHandlers(registry: SettingsRegistry): void {
});
}

// The stored prefix-only value of each control while inline mode shows it as on.
const prefixOnlyBeforeInline = new WeakMap<object, unknown>();

function applyInlineSuggestionLocks(registry: SettingsRegistry, enabled: boolean): void {
const prefixOnly = registry[KEY_PREFIX_ONLY_MODE];
if (enabled) {
const locks: Array<[string, unknown]> = [
[KEY_AUTOCOMPLETE_ON_TAB, true],
[KEY_NUM_SUGGESTIONS, 10],
[KEY_PREFIX_ONLY_MODE, true],
];
for (const [key, value] of locks) {
// A select control gives its value as a string.
if (String(registry[key].get()) !== String(value)) registry[key].set(value);
}
// ConfigAssembler forces prefix-only mode while inline mode is on. Thus show it without a write,
// so that the user's value comes back when inline mode goes off.
if (prefixOnly.get() !== true) {
prefixOnlyBeforeInline.set(prefixOnly, prefixOnly.get());
prefixOnly.set(true, true);
}
} else if (prefixOnlyBeforeInline.has(prefixOnly)) {
prefixOnly.set(prefixOnlyBeforeInline.get(prefixOnly), true);
prefixOnlyBeforeInline.delete(prefixOnly);
}
registry[KEY_AUTOCOMPLETE_ON_TAB].setDisabled(enabled);
registry[KEY_PREFIX_ONLY_MODE].setDisabled(enabled);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function cacheChromeExtensionHost(candidate: string | null | undefined): void {

function isRetriableBackgroundContextError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error);
return /Execution context was destroyed|Execution context is not available in detached frame or worker|Cannot find context with specified id|Session closed|Target closed|Connection closed|background worker is unavailable|Waiting failed|NoSuchFrameError|Browsing Context with id .* not found/i.test(
return /Execution context was destroyed|Execution context is not available in detached frame or worker|Cannot find context with specified id|Session closed|Target closed|Connection closed|background worker is unavailable|Waiting failed|Timed out after waiting \d+ms|NoSuchFrameError|Browsing Context with id .* not found/i.test(
message,
);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/options.page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ describe("options page settings handlers", () => {
expect(writes).toEqual([...expected]);
},
);

test("inline mode shows prefix-only mode as on but keeps the stored value", () => {
stubConfigChangeSender();
const registry = fakeRegistry({
[KEY_INLINE_SUGGESTION]: false,
[KEY_AUTOCOMPLETE_ON_TAB]: true,
[KEY_NUM_SUGGESTIONS]: "10",
[KEY_PREFIX_ONLY_MODE]: false,
});
wireRuntimeSettingsHandlers(registry);
const prefixOnly = registry[KEY_PREFIX_ONLY_MODE];

registry[KEY_INLINE_SUGGESTION].set(true);
expect(prefixOnly.get()).toBe(true);

registry[KEY_INLINE_SUGGESTION].set(false);
expect(prefixOnly.get()).toBe(false);
// ConfigAssembler forces prefix-only mode while inline mode is on, so no write is needed.
expect(prefixOnly.calls.every((call) => call.silent)).toBe(true);
});
});

async function flushPage(rounds = 30): Promise<void> {
Expand Down
Loading