Commit efd2f14
authored
🤖 Preserve hunk expand/collapse state and centralize keybinds (#332)
Remembers users' manual expand/collapse choices in Review tab,
centralizes keybinds, and fixes Space key to operate on selected hunk.
## Problems
1. When users manually expand or collapse hunks, their choices are lost
on remount (e.g., switching workspaces and back)
2. Keybind strings hardcoded in components instead of centralized
3. Space key operated on focused (blue border) hunk instead of selected
(yellow border) hunk during j/k navigation
## Solutions
### Persistent Expand/Collapse State
- Store per-workspace hunk expand state in localStorage via
`usePersistedState`
- Key: `reviewExpandState:{workspaceId}` → maps hunkId to isExpanded
boolean
- Manual choices override automatic collapse logic (read status, size
threshold)
- Storage copies on workspace fork, clears on workspace deletion
- Refactored with `PERSISTENT_WORKSPACE_KEY_FUNCTIONS` array for DRY
### Centralized Keybinds
- Added `TOGGLE_HUNK_COLLAPSE` to `KEYBINDS` registry in
`src/utils/ui/keybinds.ts`
- All keybind displays use `formatKeybind()` for dynamic OS-appropriate
formatting
- Added special handling for space key to display as "Space" (not
invisible whitespace)
### Fixed Space Key Behavior
- Removed confusing blue focus ring from HunkContainer
- Moved Space key handler from HunkViewer to ReviewPanel level
- Space now operates on selected (yellow border) hunk, not focused
element
- All keyboard shortcuts (j/k/m/Space) consistently operate on same
selection state
## Behavior
**Priority order for expand state:**
1. **Manual state** (user clicked expand/collapse or pressed Space) →
persisted
2. **Read status** (marked as read) → collapsed
3. **Size threshold** (>200 lines) → collapsed
4. **Default** → expanded
**Keybind Display:**
- Expand indicator: "Click to expand (N lines) or press Space"
- Collapse indicator: "Click here or press Space to collapse"
- Mark as read: "Mark as read (m)"
- All keybinds show OS-appropriate format (e.g., ⌘ on Mac, Ctrl+ on
Windows/Linux)
**Keyboard Navigation:**
- `j/k` - Navigate between hunks (updates yellow border selection)
- `m` - Toggle read state on selected hunk
- `Space` - Toggle expand/collapse on selected hunk
- All operations work on the yellow-bordered (selected) hunk
_Generated with `cmux`_1 parent 0a7e200 commit efd2f14
File tree
5 files changed
+165
-37
lines changed- src
- components/RightSidebar/CodeReview
- constants
- hooks
- utils/ui
5 files changed
+165
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
| |||
165 | 176 | | |
166 | 177 | | |
167 | 178 | | |
168 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
169 | 190 | | |
170 | 191 | | |
171 | 192 | | |
| |||
179 | 200 | | |
180 | 201 | | |
181 | 202 | | |
182 | | - | |
183 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
184 | 211 | | |
185 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
186 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
187 | 231 | | |
188 | 232 | | |
189 | 233 | | |
190 | 234 | | |
191 | 235 | | |
192 | 236 | | |
193 | | - | |
| 237 | + | |
194 | 238 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
199 | 266 | | |
200 | 267 | | |
201 | 268 | | |
| |||
214 | 281 | | |
215 | 282 | | |
216 | 283 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 284 | | |
225 | 285 | | |
226 | 286 | | |
| |||
247 | 307 | | |
248 | 308 | | |
249 | 309 | | |
250 | | - | |
| 310 | + | |
251 | 311 | | |
252 | 312 | | |
253 | 313 | | |
254 | 314 | | |
255 | | - | |
| 315 | + | |
256 | 316 | | |
257 | 317 | | |
258 | 318 | | |
| |||
283 | 343 | | |
284 | 344 | | |
285 | 345 | | |
286 | | - | |
| 346 | + | |
| 347 | + | |
287 | 348 | | |
288 | 349 | | |
289 | 350 | | |
290 | | - | |
291 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
292 | 355 | | |
293 | 356 | | |
294 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
539 | 541 | | |
540 | 542 | | |
541 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
542 | 548 | | |
543 | 549 | | |
544 | 550 | | |
| |||
598 | 604 | | |
599 | 605 | | |
600 | 606 | | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
601 | 614 | | |
602 | 615 | | |
603 | 616 | | |
| |||
698 | 711 | | |
699 | 712 | | |
700 | 713 | | |
| 714 | + | |
701 | 715 | | |
702 | 716 | | |
703 | 717 | | |
704 | 718 | | |
| 719 | + | |
705 | 720 | | |
706 | 721 | | |
707 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
87 | 118 | | |
88 | 119 | | |
89 | | - | |
| 120 | + | |
90 | 121 | | |
91 | 122 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 123 | + | |
104 | 124 | | |
105 | 125 | | |
106 | 126 | | |
| |||
109 | 129 | | |
110 | 130 | | |
111 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
168 | 175 | | |
169 | 176 | | |
170 | 177 | | |
| |||
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
260 | 270 | | |
0 commit comments