diff --git a/scripts/previewWidth.test.ts b/scripts/previewWidth.test.ts index 8634cee..4d56c56 100644 --- a/scripts/previewWidth.test.ts +++ b/scripts/previewWidth.test.ts @@ -12,6 +12,7 @@ import { const settingsSource = readFileSync(new URL('../src/lib/stores/settings.svelte.ts', import.meta.url), 'utf8'); const viewerSource = readFileSync(new URL('../src/lib/MarkdownViewer.svelte', import.meta.url), 'utf8'); +const settingsComponentSource = readFileSync(new URL('../src/lib/components/Settings.svelte', import.meta.url), 'utf8'); test('preview width defaults and clamps persisted numeric values', () => { assert.equal(DEFAULT_PREVIEW_MAX_WIDTH, 880); @@ -47,3 +48,11 @@ test('preview layout derives width and ToC geometry from the same preference', ( assert.match(viewerSource, /--preview-max-width:/); assert.match(viewerSource, /max-width: var\(--preview-max-width, 880px\)/); }); + +test('Settings exposes a bounded preview-width input and reset action', () => { + assert.match(settingsComponentSource, /id="preview-max-width"/); + assert.match(settingsComponentSource, /min=\{MIN_PREVIEW_MAX_WIDTH\}/); + assert.match(settingsComponentSource, /max=\{MAX_PREVIEW_MAX_WIDTH\}/); + assert.match(settingsComponentSource, /bind:value=\{settings\.previewMaxWidth\}/); + assert.match(settingsComponentSource, /settings\.resetPreviewMaxWidth\(\)/); +}); diff --git a/src/lib/components/Settings.svelte b/src/lib/components/Settings.svelte index dddfe64..27bedb9 100644 --- a/src/lib/components/Settings.svelte +++ b/src/lib/components/Settings.svelte @@ -9,6 +9,12 @@ import type { LanguageCode } from '../utils/i18n.js'; import { getEditorToolbarTools } from '../utils/editorToolbar.js'; import { getTitlebarToolbarActions, type TitlebarToolbarPlacement } from '../utils/titlebarToolbar.js'; + import { + DEFAULT_PREVIEW_MAX_WIDTH, + MAX_PREVIEW_MAX_WIDTH, + MIN_PREVIEW_MAX_WIDTH, + normalizePreviewMaxWidth, + } from '../utils/previewWidth.js'; let { show = false, @@ -19,6 +25,10 @@ let activeCategory = $state<'editor' | 'preview' | 'appearance' | 'toolbars' | 'files'>('editor'); let highlightMenuOpen = $state(false); + + function updatePreviewMaxWidth(value: unknown) { + settings.previewMaxWidth = normalizePreviewMaxWidth(value); + } const highlightColors = [ { value: 'default', color: 'var(--color-accent-fg)' }, { value: 'yellow', color: '#ffd000' }, @@ -901,12 +911,43 @@