Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Fix Settings X not closing after a native-menu open (PRD-9101) (#5932)

Andrew Mikofalvy85688b8cc7f8
diff --git a/.changeset/prd-9101-settings-close-once.md b/.changeset/prd-9101-settings-close-once.md
new file mode 100644
index 000000000..3f816e588
--- /dev/null
+++ b/.changeset/prd-9101-settings-close-once.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge-desktop": patch
+---
+
+The Settings close button now closes Settings on the first click after File → Settings or its shortcut was used while Settings was already open.
diff --git a/packages/app/package.json b/packages/app/package.json
index 1a8d59cc5..6500f8fa5 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -39,7 +39,7 @@
"measure:stress": "bash scripts/measure-stress.sh",
"measure:sweep": "bash scripts/measure-sweep.sh",
"perf:compare": "bash scripts/perf-compare.sh",
- "test:e2e": "playwright test tests/stress/empty-bullet-before-link.e2e.ts tests/stress/list-item-drag.e2e.ts tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/file-tree-collapse-persistence.e2e.ts tests/stress/file-tree-fractional-zoom.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/external-link-cue.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/new-item-shortcut-fast-path.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/qa019-suffix-precedence.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/okf-generated-index-settings.e2e.ts tests/stress/okf-recommended-skill-install.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/selection-surface-pane-clip.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/source-undo-mode-flip.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/agent-follow-scroll.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/comment-opens-in-panel.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts tests/stress/cv-paint-lock-click.e2e.ts tests/stress/cv-auto-paint-lock-click.e2e.ts tests/stress/harness-port-ownership.e2e.ts tests/stress/history-traversal-preview-tab.e2e.ts tests/stress/tab-close-scroll-restore.e2e.ts tests/stress/skills-sidebar-open.e2e.ts tests/stress/trailing-affordance.e2e.ts tests/stress/text-doc-composer-inset.e2e.ts tests/stress/composer-control-alignment.e2e.ts tests/stress/agents-settings-accessible-names.e2e.ts tests/stress/composer-growth-eof-reveal.e2e.ts tests/stress/theme-fade.e2e.ts tests/stress/theme-color-conversion.e2e.ts tests/stress/composer-open-caret-reveal.e2e.ts tests/stress/spellcheck-browser-absence.e2e.ts tests/stress/agents-panel-reload-visibility.e2e.ts tests/stress/rail-flex-distribution-law.e2e.ts tests/stress/audit-409-console-record.e2e.ts tests/stress/pagelist-refresh-lifetime.e2e.ts tests/stress/list-keymap.e2e.ts tests/stress/okignore-settings.e2e.ts",
+ "test:e2e": "playwright test tests/stress/empty-bullet-before-link.e2e.ts tests/stress/list-item-drag.e2e.ts tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/file-tree-collapse-persistence.e2e.ts tests/stress/file-tree-fractional-zoom.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/external-link-cue.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/new-item-shortcut-fast-path.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/qa019-suffix-precedence.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/settings-close-button.e2e.ts tests/stress/okf-generated-index-settings.e2e.ts tests/stress/okf-recommended-skill-install.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/selection-surface-pane-clip.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/source-undo-mode-flip.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/agent-follow-scroll.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/comment-opens-in-panel.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts tests/stress/cv-paint-lock-click.e2e.ts tests/stress/cv-auto-paint-lock-click.e2e.ts tests/stress/harness-port-ownership.e2e.ts tests/stress/history-traversal-preview-tab.e2e.ts tests/stress/tab-close-scroll-restore.e2e.ts tests/stress/skills-sidebar-open.e2e.ts tests/stress/trailing-affordance.e2e.ts tests/stress/text-doc-composer-inset.e2e.ts tests/stress/composer-control-alignment.e2e.ts tests/stress/agents-settings-accessible-names.e2e.ts tests/stress/composer-growth-eof-reveal.e2e.ts tests/stress/theme-fade.e2e.ts tests/stress/theme-color-conversion.e2e.ts tests/stress/composer-open-caret-reveal.e2e.ts tests/stress/spellcheck-browser-absence.e2e.ts tests/stress/agents-panel-reload-visibility.e2e.ts tests/stress/rail-flex-distribution-law.e2e.ts tests/stress/audit-409-console-record.e2e.ts tests/stress/pagelist-refresh-lifetime.e2e.ts tests/stress/list-keymap.e2e.ts tests/stress/okignore-settings.e2e.ts",
"test:e2e:install-browsers": "playwright install chromium webkit firefox",
"test:visual": "playwright test --config playwright.visual.config.ts",
"test:visual:update": "playwright test --config playwright.visual.config.ts --update-snapshots",
diff --git a/packages/app/tests/stress/settings-close-button.e2e.ts b/packages/app/tests/stress/settings-close-button.e2e.ts
new file mode 100644
index 000000000..a98656512
--- /dev/null
+++ b/packages/app/tests/stress/settings-close-button.e2e.ts
@@ -0,0 +1,125 @@
+import type { Page } from '@playwright/test';
+import { settingsHashScript } from '../../../desktop/src/main/settings-surface.ts';
+import { expect, test } from './_helpers';
+
+const APP_READY_TIMEOUT_MS = 30_000;
+const DIALOG_TIMEOUT_MS = 15_000;
+
+async function openApp(page: Page): Promise<void> {
+ await page.goto('/');
+ await expect(page.getByTestId('header-settings-button')).toBeVisible({
+ timeout: APP_READY_TIMEOUT_MS,
+ });
+}
+
+async function expectSettingsOpen(page: Page): Promise<void> {
+ await expect(page.getByTestId('settings-dialog')).toBeVisible({ timeout: DIALOG_TIMEOUT_MS });
+}
+
+async function closeWithX(page: Page): Promise<void> {
+ await page.getByTestId('settings-dialog').getByRole('button', { name: 'Close' }).click();
+ await expect(page.getByTestId('settings-dialog')).toBeHidden();
+ expect(await page.evaluate(() => window.location.hash.startsWith('#settings'))).toBe(false);
+}
+
+test.describe('Settings close button', () => {
+ test('Settings opened from the header gear closes on one X click', async ({ page }) => {
+ await openApp(page);
+ await page.getByTestId('header-settings-button').click();
+ await expectSettingsOpen(page);
+ await closeWithX(page);
+ });
+
+ test('Settings opened from the keyboard shortcut closes on one X click', async ({ page }) => {
+ await openApp(page);
+ await page.locator('body').press('ControlOrMeta+,');
+ await expectSettingsOpen(page);
+ await closeWithX(page);
+ });
+
+ test('nothing in the scrolling content covers any part of the X', async ({ page }) => {
+ await page.setViewportSize({ width: 1280, height: 800 });
+ await openApp(page);
+ await page.getByTestId('header-settings-button').click();
+ await expectSettingsOpen(page);
+ await expect(page.getByTestId('settings-content-skeleton')).toBeHidden({
+ timeout: DIALOG_TIMEOUT_MS,
+ });
+
+ const probe = await page.getByTestId('settings-dialog').evaluate(async (dialog) => {
+ const close = dialog.querySelector(':scope > [data-slot="dialog-close"]');
+ const content = dialog.querySelector('section[aria-label]');
+ if (!(close instanceof HTMLElement) || !(content instanceof HTMLElement)) {
+ return { maxScroll: 0, misses: ['close button or content section missing'] };
+ }
+ const found: string[] = [];
+ const maxScroll = content.scrollHeight - content.clientHeight;
+ for (const fraction of [0, 0.5, 1]) {
+ content.scrollTop = Math.round(maxScroll * fraction);
+ await new Promise((resolve) => requestAnimationFrame(resolve));
+ const box = close.getBoundingClientRect();
+ const midX = box.left + box.width / 2;
+ const midY = box.top + box.height / 2;
+ const points = [
+ [midX, midY],
+ [box.left + 1, midY],
+ [box.right - 1, midY],
+ [midX, box.top + 1],
+ [midX, box.bottom - 1],
+ ];
+ for (const [x, y] of points) {
+ const hit = document.elementFromPoint(x, y);
+ if (!hit || !close.contains(hit)) {
+ found.push(`scroll ${fraction} at (${x}, ${y}) hit <${hit?.tagName.toLowerCase()}>`);
+ }
+ }
+ }
+ return { maxScroll, misses: found };
+ });
+ expect(probe.maxScroll).toBeGreaterThan(0);
+ expect(probe.misses).toEqual([]);
+
+ await closeWithX(page);
+ });
+
+ test('a native-menu Settings request over an open section still closes on one X click', async ({
+ page,
+ }) => {
+ await openApp(page);
+ await page.evaluate(() => {
+ window.location.hash = '#settings/hotkeys';
+ });
+ await expect(page.getByTestId('settings-hotkeys')).toBeVisible({ timeout: DIALOG_TIMEOUT_MS });
+
+ await page.evaluate(settingsHashScript());
+ await expectSettingsOpen(page);
+ await expect(page.getByTestId('settings-hotkeys')).toBeVisible();
+
+ await closeWithX(page);
+ });
+
+ test('a native-menu section request over open Settings switches page without stacking history', async ({
+ page,
+ }) => {
+ await openApp(page);
+ await page.getByTestId('header-settings-button').click();
+ await expectSettingsOpen(page);
+
+ await page.evaluate(settingsHashScript('account'));
+ await expect(page).toHaveURL(/#settings\/account$/);
+ await expect(page.getByTestId('settings-sidebar-item-account')).toHaveAttribute(
+ 'aria-current',
+ 'page',
+ );
+
+ await page.getByTestId('settings-sidebar-item-hotkeys').click();
+ await expect(page.getByTestId('settings-hotkeys')).toBeVisible({ timeout: DIALOG_TIMEOUT_MS });
+ await page.evaluate(settingsHashScript('account'));
+ await expect(page.getByTestId('settings-sidebar-item-account')).toHaveAttribute(
+ 'aria-current',
+ 'page',
+ );
+
+ await closeWithX(page);
+ });
+});
diff --git a/packages/desktop/src/main/settings-surface.test.ts b/packages/desktop/src/main/settings-surface.test.ts
index 536a530fd..72d6718d7 100644
--- a/packages/desktop/src/main/settings-surface.test.ts
+++ b/packages/desktop/src/main/settings-surface.test.ts
@@ -356,13 +356,77 @@ describe('deliverNavigatorSettings', () => {
describe('settingsHash', () => {
test('defaults to the bare settings hash', () => {
expect(settingsHash()).toBe('#settings');
- expect(settingsHashScript()).toBe('window.location.hash = "#settings"; undefined');
});
test('appends a section id', () => {
expect(settingsHash('account')).toBe('#settings/account');
- expect(settingsHashScript('account')).toBe(
- 'window.location.hash = "#settings/account"; undefined',
- );
+ });
+});
+
+describe('settingsHashScript', () => {
+ function runInRenderer(script: string, startHash: string) {
+ const entries = [startHash];
+ const hashChanges: string[] = [];
+ const sectionIntents: unknown[] = [];
+ const location = {
+ get hash() {
+ return entries[entries.length - 1] ?? '';
+ },
+ set hash(next: string) {
+ if (next === location.hash) return;
+ entries.push(next);
+ hashChanges.push(next);
+ },
+ };
+ const renderer = {
+ location,
+ history: {
+ replaceState: (_state: unknown, _unused: string, url: string) => {
+ entries[entries.length - 1] = url;
+ },
+ },
+ dispatchEvent: (event: Event) => {
+ if (event.type === 'open-knowledge:settings-section-intent') {
+ sectionIntents.push((event as CustomEvent).detail);
+ }
+ return true;
+ },
+ };
+ new Function('window', script)(renderer);
+ return { entries, hashChanges, sectionIntents };
+ }
+
+ test('opens Settings as a new history entry when it is closed', () => {
+ expect(runInRenderer(settingsHashScript(), '#/note')).toEqual({
+ entries: ['#/note', '#settings'],
+ hashChanges: ['#settings'],
+ sectionIntents: [],
+ });
+ expect(runInRenderer(settingsHashScript('account'), '#/note')).toEqual({
+ entries: ['#/note', '#settings/account'],
+ hashChanges: ['#settings/account'],
+ sectionIntents: [],
+ });
+ });
+
+ test('leaves an open Settings page alone instead of stacking a second entry', () => {
+ expect(runInRenderer(settingsHashScript(), '#settings/about')).toEqual({
+ entries: ['#settings/about'],
+ hashChanges: [],
+ sectionIntents: [],
+ });
+ });
+
+ test('brings an open Settings to the requested section in place', () => {
+ expect(runInRenderer(settingsHashScript('account'), '#settings/about')).toEqual({
+ entries: ['#settings/account'],
+ hashChanges: [],
+ sectionIntents: ['account'],
+ });
+ expect(runInRenderer(settingsHashScript('account'), '#settings/account')).toEqual({
+ entries: ['#settings/account'],
+ hashChanges: [],
+ sectionIntents: ['account'],
+ });
});
});
diff --git a/packages/desktop/src/main/settings-surface.ts b/packages/desktop/src/main/settings-surface.ts
index f3f29a840..4677cd89d 100644
--- a/packages/desktop/src/main/settings-surface.ts
+++ b/packages/desktop/src/main/settings-surface.ts
@@ -121,5 +121,8 @@ export function settingsHash(section?: SettingsSection): string {
}
export function settingsHashScript(section?: SettingsSection): string {
- return `window.location.hash = ${JSON.stringify(settingsHash(section))}; undefined`;
+ const target = JSON.stringify(settingsHash(section));
+ const openSettings = `if (!/^#settings(\\/.+)?$/.test(window.location.hash)) { window.location.hash = ${target}; }`;
+ if (section === undefined) return `${openSettings} undefined`;
+ return `${openSettings} else { window.history.replaceState(null, '', ${target}); window.dispatchEvent(new CustomEvent('open-knowledge:settings-section-intent', { detail: ${JSON.stringify(section)} })); } undefined`;
}