|
59 | 59 |
|
60 | 60 | let lanesSrollableEl = $state<HTMLDivElement>();
|
61 | 61 |
|
| 62 | + let isDetailsViewForcesClosed = $state(false); |
| 63 | +
|
62 | 64 | const stackService = inject(STACK_SERVICE);
|
63 | 65 | const diffService = inject(DIFF_SERVICE);
|
64 | 66 | const uncommittedService = inject(UNCOMMITTED_SERVICE);
|
|
229 | 231 | selection.set(undefined);
|
230 | 232 | }
|
231 | 233 |
|
| 234 | + function onclosePreviewOnly() { |
| 235 | + // Close the details view but keep the selection intact |
| 236 | + isDetailsViewForcesClosed = true; |
| 237 | + } |
| 238 | +
|
232 | 239 | const startCommitVisible = $derived(uncommittedService.startCommitVisible(stackId));
|
233 | 240 |
|
234 | 241 | function onerror(err: unknown) {
|
|
250 | 257 | return undefined;
|
251 | 258 | }
|
252 | 259 |
|
253 |
| - let isDetailsViewOpen = $derived(!!(branchName || commitId || assignedKey || selectedFile)); |
| 260 | + let isDetailsViewOpen = $derived( |
| 261 | + !!(branchName || commitId || assignedKey || selectedFile) && !isDetailsViewForcesClosed |
| 262 | + ); |
| 263 | +
|
| 264 | + // Track the current selection to detect when it changes |
| 265 | + let previousSelection = $state<{ branchName?: string; commitId?: string }>({}); |
| 266 | +
|
| 267 | + // Reset the forced closed state when selection changes to a different branch/commit |
| 268 | + $effect(() => { |
| 269 | + const currentSelection = { branchName, commitId }; |
| 270 | +
|
| 271 | + // Check if selection actually changed |
| 272 | + if ( |
| 273 | + currentSelection.branchName !== previousSelection.branchName || |
| 274 | + currentSelection.commitId !== previousSelection.commitId |
| 275 | + ) { |
| 276 | + // Selection changed, allow details view to open again |
| 277 | + isDetailsViewForcesClosed = false; |
| 278 | + previousSelection = { ...currentSelection }; |
| 279 | +
|
| 280 | + // Clear file selections from the previous context to allow auto-selection |
| 281 | + // to work properly for the new context |
| 282 | + if (activeSelectionId) { |
| 283 | + idSelection.clear(activeSelectionId); |
| 284 | + } |
| 285 | + } |
| 286 | + }); |
254 | 287 | const DETAILS_RIGHT_PADDING_REM = 1.125;
|
255 | 288 |
|
256 | 289 | // Function to update CSS custom property for details view width
|
|
299 | 332 | scrollContainer={selectionPreviewScrollContainer}
|
300 | 333 | selectionId={createWorktreeSelection({ stackId })}
|
301 | 334 | onclose={() => {
|
302 |
| - idSelection.clear(createWorktreeSelection({ stackId: stackId })); |
| 335 | + idSelection.clearPreview(createWorktreeSelection({ stackId: stackId })); |
303 | 336 | }}
|
304 | 337 | draggableFiles
|
305 | 338 | />
|
|
317 | 350 | {/snippet}
|
318 | 351 |
|
319 | 352 | {#snippet branchView(branchName: string)}
|
320 |
| - <BranchView {stackId} {laneId} {projectId} {branchName} {onerror} {onclose} /> |
| 353 | + <BranchView {stackId} {laneId} {projectId} {branchName} {onerror} onclose={onclosePreviewOnly} /> |
321 | 354 | {/snippet}
|
322 | 355 |
|
323 | 356 | {#snippet commitView(branchName: string, commitId: string)}
|
|
333 | 366 | }}
|
334 | 367 | draggableFiles
|
335 | 368 | {onerror}
|
336 |
| - {onclose} |
| 369 | + onclose={onclosePreviewOnly} |
337 | 370 | />
|
338 | 371 | {/snippet}
|
339 | 372 |
|
|
375 | 408 | defaultValue: 16
|
376 | 409 | }}
|
377 | 410 | autoselect
|
| 411 | + allowUnselect={false} |
378 | 412 | />
|
379 | 413 | {/snippet}
|
380 | 414 | </ReduxResult>
|
|
408 | 442 | maxHeight: 32,
|
409 | 443 | defaultValue: 16
|
410 | 444 | }}
|
| 445 | + allowUnselect={false} |
411 | 446 | />
|
412 | 447 | {/snippet}
|
413 | 448 | </ReduxResult>
|
|
436 | 471 | use:focusable={{
|
437 | 472 | onKeydown: (event) => {
|
438 | 473 | if (event.key === 'Escape' && isDetailsViewOpen) {
|
439 |
| - selection.set(undefined); |
| 474 | + onclosePreviewOnly(); |
440 | 475 | event.preventDefault();
|
441 | 476 | event.stopPropagation();
|
442 | 477 | return true;
|
|
0 commit comments