Add font-size/zoom control to the markdown viewer

Merged
LA
4mo ago
+722-17

Summary

  • Adds font-size / zoom control to the cmux markdown viewer, which previously had no way to scale text. Cmd-+/-/0 only zoomed browser surfaces and there was no --font-size flag or setting.
  • Font size is one "points" value rendered via WKWebView.pageZoom (points / 15px body base), so it scales the whole rendered document (text, code, tables, diagrams, images) like browser zoom and mirrors the existing cmux diff --font-size.
  • cmux markdown open --font-size <points> sets a viewer's size (validated to 8..96), sent through markdown.open's new font_size param.
  • Cmd-+ / Cmd-- / Cmd-0 zoom the focused markdown viewer via new markdownZoomIn / markdownZoomOut / markdownZoomReset shortcuts in a dedicated .markdownPanel context (shares Cmd-=/-/0 with browser zoom but never collides; conflict detection also treats it as overlapping .nonBrowserPanel). Exposed through Settings > Keyboard Shortcuts, cmux.json, and the command palette. The View-menu Zoom items stay browser-only so a rebound markdown shortcut isn't overridden by the menu key equivalent.
  • markdown.fontSize setting (default 15) in Settings > App, cmux.json, the schema, and the settings catalog sets the size every new viewer starts at and that Cmd-0 resets to.
  • Zoom is scoped to the rendered preview; the raw text-edit mode keeps the system editor font and does not surface the zoom commands.

Testing

  • ./scripts/reload.sh --tag md-fontsize builds the Debug app cleanly.
  • Drove the real handleCustomShortcut path on the tagged build via the debug socket and screenshotted: --font-size 40 rendered huge → Cmd-0 reset to 15pt → Cmd-+×6 grew to ~21pt. Verified --font-size rejects 3 and 97, accepts 8 and 96.
  • Added behavioral unit tests in cmuxTests/MarkdownPanelTests.swift (clamp/pageZoom/resolvedDefault, zoom step/clamp/reset) and cmuxTests/KeyboardShortcutContextTests.swift (.markdownPanel scoping + overlap). tests CI green.

Dogfood

Open a markdown file in the viewer:

  • Previous: rendered too large, no way to shrink; Cmd-- did nothing in a markdown panel.
  • Expected now: with the rendered preview focused, Cmd-- shrinks, Cmd-+ grows, Cmd-0 resets. cmux markdown open --font-size 11 <file> opens at 11pt. Settings > App > "Markdown Viewer Font Size" and markdown.fontSize in cmux.json change the default.

Issues

  • Feature request (no GitHub issue): font-size / zoom control for the markdown viewer.

Summary by CodeRabbit

  • New Features

    • Added --font-size CLI option for cmux markdown open; per-panel font sizing and persisted "Markdown Viewer Font Size" preference (8–96 pt)
    • Keyboard shortcuts for markdown zoom: ⌘+=, ⌘+-, ⌘0; command palette entries and on-panel zoom controls
  • Documentation

    • Settings UI, localization, and configuration schema updated to expose markdown font-size controls and docs
  • Tests

    • Unit tests added/updated for markdown font-size behavior and shortcut scoping

[!NOTE]
Medium Risk
Touches global shortcut routing and WKWebView zoom alongside new settings/CLI params, but changes are scoped to the markdown preview path with validation and tests.

Overview
Adds font-size and zoom for the built-in markdown preview (not raw text edit mode).

cmux markdown open --font-size <points> validates 8–96 and sends font_size into the markdown-open path. markdown.fontSize (default 15) is a new markdown.* setting in App settings, cmux.json, schema, and docs.

Preview scaling uses WKWebView.pageZoom from a points value (MarkdownFontSizeSettings). MarkdownPanel supports per-panel zoom step/reset; the renderer reapplies zoom after shell reloads.

⌘= / ⌘- / ⌘0 get parallel markdownZoom* actions in a .markdownPanel shortcut context (same chords as browser zoom, routed by focus). Conflict detection treats markdown vs non-browser contexts as overlapping. Command palette, settings catalog, and localized strings are wired; View menu zoom stays browser-only.

Unit tests cover clamp/pageZoom, panel zoom behavior, and shortcut scoping.

Reviewed by Cursor Bugbot for commit 2990c1695b340297aca7e54df8ec4da667ba8114. Bugbot is set up for automated code reviews on this repo. Configure here.