Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix files selection #4764

Merged
merged 9 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions apps/desktop/src/lib/commit/CommitCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@
class:integrated={type === 'integrated'}
></div>

{#if type === 'local' || type === 'localAndRemote'}
<div class="commit__drag-icon">
<Icon name="draggable-narrow" />
</div>
{#if !isUnapplied}
{#if type === 'local' || type === 'localAndRemote'}
<div class="commit__drag-icon">
<Icon name="draggable-narrow" />
</div>
{/if}
{/if}

{#if first}
Expand Down Expand Up @@ -368,7 +370,12 @@
{/if}

<div class="files-container">
<BranchFilesList {files} {isUnapplied} readonly={type === 'remote'} />
<BranchFilesList
allowMultiple={!isUnapplied && type !== 'remote'}
{files}
{isUnapplied}
readonly={type === 'remote' || isUnapplied}
/>
</div>
{/if}
</CommitDragItem>
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/lib/components/BranchPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
{#if remoteCommits}
{#each remoteCommits as commit, index (commit.id)}
<CommitCard
isUnapplied
first={index === 0}
last={index === remoteCommits.length - 1}
{commit}
Expand All @@ -135,6 +136,7 @@
{#if localCommits}
{#each localCommits as commit, index (commit.id)}
<CommitCard
isUnapplied
first={index === 0}
last={index === localCommits.length - 1}
{commit}
Expand All @@ -150,6 +152,7 @@
{#if localAndRemoteCommits}
{#each localAndRemoteCommits as commit, index (commit.id)}
<CommitCard
isUnapplied
first={index === 0}
last={index === localAndRemoteCommits.length - 1}
{commit}
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/lib/file/BranchFilesList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
file,
files: displayedFiles,
selectedFileIds: $fileIdSelection,
fileIdSelection
fileIdSelection,
commitId: $commit?.id
}
);

Expand Down
18 changes: 11 additions & 7 deletions apps/desktop/src/lib/utils/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface MoveSelectionParams {
files: AnyFile[];
selectedFileIds: string[];
fileIdSelection: FileIdSelection;
commitId?: string;
}

export function maybeMoveSelection({
Expand All @@ -35,7 +36,8 @@ export function maybeMoveSelection({
file,
files,
selectedFileIds,
fileIdSelection
fileIdSelection,
commitId
}: MoveSelectionParams) {
if (!selectedFileIds[0] || selectedFileIds.length === 0) return;

Expand All @@ -53,9 +55,10 @@ export function maybeMoveSelection({
const file = getFileFunc(files, id);
if (file) {
// if file is already selected, do nothing
if (selectedFileIds.includes(stringifyFileKey(file.id))) return;

fileIdSelection.add(file.id);
if (selectedFileIds.includes(stringifyFileKey(file.id, commitId))) return;

fileIdSelection.add(file.id, commitId);
}
}

Expand All @@ -64,9 +67,9 @@ export function maybeMoveSelection({
id: string
) {
const file = getFileFunc(files, id);

if (file) {
fileIdSelection.clear();
fileIdSelection.add(file.id);
fileIdSelection.clearExcept(file.id, commitId);
}
}

Expand All @@ -78,7 +81,7 @@ export function maybeMoveSelection({
if (selectedFileIds.length === 1) {
selectionDirection = 'up';
} else if (selectionDirection === 'down') {
fileIdSelection.remove(lastFileId);
fileIdSelection.remove(lastFileId, commitId);
}
getAndAddFile(getPreviousFile, lastFileId);
} else {
Expand All @@ -102,8 +105,9 @@ export function maybeMoveSelection({
if (selectedFileIds.length === 1) {
selectionDirection = 'down';
} else if (selectionDirection === 'up') {
fileIdSelection.remove(lastFileId);
fileIdSelection.remove(lastFileId, commitId);
}

getAndAddFile(getNextFile, lastFileId);
} else {
// focus next file
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/lib/vbranches/fileIdSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export class FileIdSelection {
this.emit();
}

clearExcept(fileId: string, commitId?: string) {
this.value = [stringifyFileKey(fileId, commitId)];
this.emit();
}

emit() {
for (const callback of this.callbacks) {
callback(this.value);
Expand Down