Commit f9bcdb6
authored
feat(preview): floating modal + async render + raw-first toggle (#40)
Three intertwined fixes to the preview experience.
## Floating modal (Space)
Was: full-screen takeover that didn't feel like a modal.
Now: centered floating box (~80% × 80%) with rounded accent border,
overlaid on the still-rendered underlying view.
Uses `charmbracelet/x/ansi.Cut` for cell-aware substring operations so
the overlay survives ANSI escape codes. `padBlock` normalises the
background to a full screenW × screenH grid first — without that,
short matrix-view rows produced a "left strip" of width 0 and the
modal drifted to column 0 on those rows.
## Async glamour render
Was: glamour was invoked inside `View()`, blocking every keystroke on
the cold-render path even with a cache. j/k felt laggy in side mode.
Now: rendering is dispatched in a `tea.Cmd` (goroutine), result comes
back as `PreviewRenderedMsg`, the model stores it. `View()` only ever
reads the cache. `ensurePreviewRendered()` is called from key handlers
that change the relevant inputs (preview toggle, j/k, resize, scan).
This is the canonical Bubble Tea pattern for expensive work and the
reason `bubbles/spinner`, `glow`, etc. stay responsive.
## Raw-first + r toggle
Was: preview opened directly in glamour-rendered markdown.
Now: opens showing the **raw file content** (instant — just split
`rec.Raw` on newlines). Pressing `r` toggles to rendered. The glamour
goroutine is dispatched the moment the preview opens, so the cache is
almost always warm by the time the user presses `r`.
Added `Raw string` to `SkillRecord` to store the original file bytes
(byte-exact, not reconstructed from frontmatter + body).
## Keymap
- Space — toggle modal preview
- Shift+P — toggle side-panel preview
- r — toggle raw ↔ rendered (preview only)
- R — re-scan
- j/k — scroll preview (when it owns input) else navigate skills
- Tab — swap focus between skill list and preview pane (side mode)
- Esc — close any preview
Toolbar's `r` label is dynamic: shows `→ rendered` when in raw and
`→ raw` when in rendered, so the user always knows the current mode
and what r will do next. Avoids fighting lipgloss layout to put a tag
in the header.
Tests cover the keymap state machine end-to-end (space, P, r, Esc,
cross-switching).1 parent 5eeab6f commit f9bcdb6
9 files changed
Lines changed: 680 additions & 85 deletions
File tree
- internal
- app
- scan
- ui
- view
- diff
- matrix
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | | - | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
87 | 95 | | |
88 | 96 | | |
89 | 97 | | |
| |||
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
113 | 129 | | |
114 | 130 | | |
115 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
0 commit comments