Fix: wrong focus on the last selected item

This commit is contained in:
Pavel Laptev 2024-06-25 22:28:15 +02:00 committed by GitButler
parent e707bdd812
commit 328c3e6f16
4 changed files with 8 additions and 6 deletions

View File

@ -74,6 +74,8 @@
class:draggable={isDraggable}
id={`file-${file.id}`}
data-locked={file.locked}
role="button"
tabindex="0"
on:click
on:keydown
on:dragstart={async () => {
@ -106,8 +108,6 @@
draggableElt.classList.remove('locked-file-animation');
}
}}
role="button"
tabindex="0"
on:contextmenu|preventDefault={async (e) => {
if (fileIdSelection.has(file.id, $commit?.id)) {
popupMenu.openByMouse(e, { files: await $selectedFiles });

View File

@ -11,8 +11,9 @@ export function selectFilesInList(
allowMultiple: boolean,
commit: AnyCommit | undefined
) {
let selectedFileIds = get(fileIdSelection);
e.stopPropagation();
let selectedFileIds = get(fileIdSelection);
const isAlreadySelected = selectedFileIds && fileIdSelection.has(file.id, commit?.id);
if (e.ctrlKey || e.metaKey) {

View File

@ -46,8 +46,8 @@ export function maybeMoveSelection(
) {
if (selectedFileIds.length === 0) return;
const firstFileId = unstringifyFileKey(selectedFileIds[0]);
const lastFileId = unstringifyFileKey(selectedFileIds[selectedFileIds.length - 1]);
const firstFileId = unstringifyFileKey(selectedFileIds[selectedFileIds.length - 1]);
const lastFileId = unstringifyFileKey(selectedFileIds[0]);
let selectionDirection = getSelectionDirection(
files.findIndex((f) => f.id === lastFileId),
files.findIndex((f) => f.id === firstFileId)
@ -87,6 +87,7 @@ export function maybeMoveSelection(
} else if (selectionDirection === 'down') {
fileIdSelection.remove(lastFileId);
}
getAndAddFile(getPreviousFile, lastFileId);
} else {
// Handle reset of selection

View File

@ -56,7 +56,7 @@ export class FileIdSelection {
}
add(fileId: string, commitId?: string) {
this.value.push(stringifyFileKey(fileId, commitId));
this.value.unshift(stringifyFileKey(fileId, commitId));
this.emit();
}