Skip to content
Closed
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
15 changes: 15 additions & 0 deletions scripts/previewWidth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
adjustPreviewMaxWidth,
DEFAULT_PREVIEW_MAX_WIDTH,
getPreviewContentWidth,
getStoredPreviewFullWidth,
MAX_PREVIEW_MAX_WIDTH,
MIN_PREVIEW_MAX_WIDTH,
normalizePreviewMaxWidth,
Expand Down Expand Up @@ -41,6 +42,13 @@ test('preview width shortcut adjustments retain the configured bounds', () => {
assert.equal(adjustPreviewMaxWidth(MAX_PREVIEW_MAX_WIDTH, 40), MAX_PREVIEW_MAX_WIDTH);
});

test('the dedicated full-width preference takes priority over its legacy key', () => {
assert.equal(getStoredPreviewFullWidth('true', 'false'), true);
assert.equal(getStoredPreviewFullWidth('false', 'true'), false);
assert.equal(getStoredPreviewFullWidth(null, 'true'), true);
assert.equal(getStoredPreviewFullWidth(null, null), false);
});

test('settings load, persist, and reset the preview width through one normalizer', () => {
assert.match(settingsSource, /previewMaxWidth = \$state\(DEFAULT_PREVIEW_MAX_WIDTH\)/);
assert.match(settingsSource, /localStorage\.getItem\('preview\.maxWidth'\)/);
Expand Down Expand Up @@ -72,3 +80,10 @@ test('preview width keyboard shortcuts avoid editable controls and app modals',
assert.match(viewerSource, /isFullWidth = false/);
assert.match(viewerSource, /settings\.previewMaxWidth = adjustPreviewMaxWidth\(settings\.previewMaxWidth, code === 'BracketLeft' \? -40 : 40\)/);
});

test('preview full-width state migrates from the legacy localStorage key', () => {
assert.match(viewerSource, /localStorage\.getItem\('preview\.fullWidth'\)/);
assert.match(viewerSource, /localStorage\.getItem\('isFullWidth'\)/);
assert.match(viewerSource, /localStorage\.setItem\('preview\.fullWidth', String\(isFullWidth\)\)/);
assert.match(viewerSource, /localStorage\.removeItem\('isFullWidth'\)/);
});
10 changes: 7 additions & 3 deletions src/lib/MarkdownViewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
import HomePage from './components/HomePage.svelte';
import { tabManager } from './stores/tabs.svelte.js';
import { snapshotTab } from './utils/tabTransfer.js';
import { adjustPreviewMaxWidth, getPreviewContentWidth } from './utils/previewWidth.js';
import { adjustPreviewMaxWidth, getPreviewContentWidth, getStoredPreviewFullWidth } from './utils/previewWidth.js';
import { settings } from './stores/settings.svelte.js';
import { t } from './utils/i18n.js';
import { createWindowSession } from './sessions/windowSession.svelte.js';
Expand Down Expand Up @@ -217,7 +217,10 @@ import { createDocumentSession, type LoadMarkdownOptions } from './sessions/docu
let isAtBottom = $state(false);

let showHome = $state(false);
let isFullWidth = $state(localStorage.getItem('isFullWidth') === 'true');
let isFullWidth = $state(getStoredPreviewFullWidth(
localStorage.getItem('preview.fullWidth'),
localStorage.getItem('isFullWidth'),
));
let viewerWidth = $state(0);
const TOC_MIN_WIDTH = 180;
const TOC_MAX_WIDTH = 420;
Expand All @@ -229,7 +232,8 @@ import { createDocumentSession, type LoadMarkdownOptions } from './sessions/docu
);

$effect(() => {
localStorage.setItem('isFullWidth', String(isFullWidth));
localStorage.setItem('preview.fullWidth', String(isFullWidth));
localStorage.removeItem('isFullWidth');
});

import { parseAndApplyVscodeTheme, clearVscodeTheme } from './utils/theme';
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/previewWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export function getPreviewContentWidth(value: unknown, isFullWidth: boolean): nu
export function adjustPreviewMaxWidth(value: unknown, delta: number): number {
return normalizePreviewMaxWidth(normalizePreviewMaxWidth(value) + delta);
}

export function getStoredPreviewFullWidth(value: string | null, legacyValue: string | null): boolean {
return (value ?? legacyValue) === 'true';
}
Loading