|
19 | 19 | import { chunk } from '$lib/utils/array';
|
20 | 20 | import { inject, injectOptional } from '@gitbutler/core/context';
|
21 | 21 | import { FileListItem } from '@gitbutler/ui';
|
| 22 | + import { FOCUS_MANAGER } from '@gitbutler/ui/focus/focusManager'; |
22 | 23 | import { focusable } from '@gitbutler/ui/focus/focusable';
|
23 | 24 |
|
24 | 25 | import type { ConflictEntriesObj } from '$lib/files/conflicts';
|
|
52 | 53 | }: Props = $props();
|
53 | 54 |
|
54 | 55 | const idSelection = inject(ID_SELECTION);
|
| 56 | + const focusManager = inject(FOCUS_MANAGER); |
55 | 57 | const aiService = inject(AI_SERVICE);
|
56 | 58 | const actionService = inject(ACTION_SERVICE);
|
57 | 59 | const modeService = injectOptional(MODE_SERVICE, undefined);
|
|
91 | 93 | const aiGenEnabled = $derived(projectAiGenEnabled(projectId));
|
92 | 94 |
|
93 | 95 | const canUseGBAI = $derived(aiGenEnabled && aiConfigurationValid);
|
| 96 | + const selectedFileIds = $derived(idSelection.values(selectionId)); |
94 | 97 |
|
95 | 98 | $effect(() => {
|
96 | 99 | aiService.validateGitButlerAPIConfiguration().then((value) => {
|
|
177 | 180 | function handleKeyDown(change: TreeChange, idx: number, e: KeyboardEvent) {
|
178 | 181 | if (e.key === 'Enter' || e.key === ' ' || e.key === 'l') {
|
179 | 182 | e.stopPropagation();
|
180 |
| - selectFilesInList(e, change, changes, idSelection, true, idx, selectionId); |
| 183 | + selectFilesInList(e, change, changes, idSelection, selectedFileIds, true, idx, selectionId); |
181 | 184 | onselect?.();
|
182 | 185 | return true;
|
183 | 186 | }
|
|
194 | 197 | return;
|
195 | 198 | }
|
196 | 199 |
|
197 |
| - // If we want to keep the behavior where focus can change while |
198 |
| - // not automatically selecting the item, then we should remove |
199 |
| - // that code from `updateSelection` rather than checkinf for |
200 |
| - // modifier keys here. |
201 |
| - if (e.shiftKey || e.metaKey) { |
| 200 | + if (!e.metaKey) { |
202 | 201 | updateSelection({
|
203 | 202 | allowMultiple: true,
|
204 | 203 | metaKey: e.metaKey,
|
205 | 204 | shiftKey: e.shiftKey,
|
206 | 205 | key: e.key,
|
207 | 206 | targetElement: e.currentTarget as HTMLElement,
|
208 | 207 | files: changes,
|
209 |
| - selectedFileIds: idSelection.values(selectionId), |
| 208 | + selectedFileIds, |
210 | 209 | fileIdSelection: idSelection,
|
211 | 210 | selectionId: selectionId,
|
212 | 211 | preventDefault: () => e.preventDefault()
|
213 | 212 | });
|
| 213 | + return true; |
214 | 214 | }
|
215 | 215 | }
|
| 216 | + const lastAdded = $derived(idSelection.getById(selectionId).lastAdded); |
| 217 | + $effect(() => { |
| 218 | + if ($lastAdded) focusManager.focusNthSibling($lastAdded.index); |
| 219 | + }); |
216 | 220 | </script>
|
217 | 221 |
|
218 | 222 | {#snippet fileTemplate(change: TreeChange, idx: number, depth: number = 0)}
|
|
231 | 235 | draggable={draggableFiles}
|
232 | 236 | executable={!!isExecutable}
|
233 | 237 | showCheckbox={showCheckboxes}
|
234 |
| - focusableOpts={{ onKeydown: (e) => handleKeyDown(change, idx, e) }} |
| 238 | + focusableOpts={{ onKeydown: (e) => handleKeyDown(change, idx, e), autoAction: true }} |
235 | 239 | onclick={(e) => {
|
236 | 240 | e.stopPropagation();
|
237 |
| - selectFilesInList(e, change, changes, idSelection, true, idx, selectionId); |
| 241 | + selectFilesInList(e, change, changes, idSelection, selectedFileIds, true, idx, selectionId); |
238 | 242 | onselect?.();
|
239 | 243 | }}
|
240 | 244 | {conflictEntries}
|
|
0 commit comments