From 0a3cbbe705d8f4ce2a3bf8ed59aeb130cf5e2899 Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Mon, 26 Aug 2024 16:57:02 +0200 Subject: [PATCH 1/9] allow select multiple if the lane is applied --- apps/desktop/src/lib/commit/CommitCard.svelte | 8 +++++++- apps/desktop/src/lib/components/BranchPreview.svelte | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/lib/commit/CommitCard.svelte b/apps/desktop/src/lib/commit/CommitCard.svelte index 8266aa3648..65a29b4e73 100644 --- a/apps/desktop/src/lib/commit/CommitCard.svelte +++ b/apps/desktop/src/lib/commit/CommitCard.svelte @@ -31,6 +31,7 @@ export let branch: VirtualBranch | undefined = undefined; export let commit: DetailedCommit | Commit; export let commitUrl: string | undefined = undefined; + export let isPreview: boolean = false; export let isHeadCommit: boolean = false; export let isUnapplied = false; export let first = false; @@ -368,7 +369,12 @@ {/if}
- +
{/if} diff --git a/apps/desktop/src/lib/components/BranchPreview.svelte b/apps/desktop/src/lib/components/BranchPreview.svelte index 56e29d7c75..16441c92d4 100644 --- a/apps/desktop/src/lib/components/BranchPreview.svelte +++ b/apps/desktop/src/lib/components/BranchPreview.svelte @@ -120,6 +120,7 @@ {#if remoteCommits} {#each remoteCommits as commit, index (commit.id)} Date: Mon, 26 Aug 2024 22:04:31 +0200 Subject: [PATCH 2/9] missing commit Id added --- .../src/lib/file/BranchFilesList.svelte | 3 ++- apps/desktop/src/lib/utils/selection.ts | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/lib/file/BranchFilesList.svelte b/apps/desktop/src/lib/file/BranchFilesList.svelte index ec9fd84503..b280298ea4 100644 --- a/apps/desktop/src/lib/file/BranchFilesList.svelte +++ b/apps/desktop/src/lib/file/BranchFilesList.svelte @@ -103,7 +103,8 @@ file, files: displayedFiles, selectedFileIds: $fileIdSelection, - fileIdSelection + fileIdSelection, + commitId: $commit?.id } ); diff --git a/apps/desktop/src/lib/utils/selection.ts b/apps/desktop/src/lib/utils/selection.ts index f44636fb85..bdac205956 100644 --- a/apps/desktop/src/lib/utils/selection.ts +++ b/apps/desktop/src/lib/utils/selection.ts @@ -8,12 +8,15 @@ import type { AnyFile } from '$lib/vbranches/types'; export function getNextFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - return fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; + const nextFile = + fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; + return nextFile; } export function getPreviousFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - return fileIndex > 0 ? files[fileIndex - 1] : undefined; + const previousFile = fileIndex > 0 ? files[fileIndex - 1] : undefined; + return previousFile; } interface MoveSelectionParams { @@ -25,6 +28,7 @@ interface MoveSelectionParams { files: AnyFile[]; selectedFileIds: string[]; fileIdSelection: FileIdSelection; + commitId?: string; } export function maybeMoveSelection({ @@ -35,7 +39,8 @@ export function maybeMoveSelection({ file, files, selectedFileIds, - fileIdSelection + fileIdSelection, + commitId }: MoveSelectionParams) { if (!selectedFileIds[0] || selectedFileIds.length === 0) return; @@ -53,9 +58,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); } } @@ -64,9 +70,10 @@ export function maybeMoveSelection({ id: string ) { const file = getFileFunc(files, id); + if (file) { fileIdSelection.clear(); - fileIdSelection.add(file.id); + fileIdSelection.add(file.id, commitId); } } @@ -104,6 +111,7 @@ export function maybeMoveSelection({ } else if (selectionDirection === 'up') { fileIdSelection.remove(lastFileId); } + getAndAddFile(getNextFile, lastFileId); } else { // focus next file From ef2e09e481e18a9b2a918bb979c2fcf7c790823d Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Mon, 26 Aug 2024 23:01:14 +0200 Subject: [PATCH 3/9] fix selection with `shift` --- apps/desktop/src/lib/utils/selection.ts | 7 +++---- apps/desktop/src/lib/vbranches/fileIdSelection.ts | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/lib/utils/selection.ts b/apps/desktop/src/lib/utils/selection.ts index bdac205956..35c25193d3 100644 --- a/apps/desktop/src/lib/utils/selection.ts +++ b/apps/desktop/src/lib/utils/selection.ts @@ -72,8 +72,7 @@ export function maybeMoveSelection({ const file = getFileFunc(files, id); if (file) { - fileIdSelection.clear(); - fileIdSelection.add(file.id, commitId); + fileIdSelection.clearExcept(file.id, commitId); } } @@ -85,7 +84,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 { @@ -109,7 +108,7 @@ export function maybeMoveSelection({ if (selectedFileIds.length === 1) { selectionDirection = 'down'; } else if (selectionDirection === 'up') { - fileIdSelection.remove(lastFileId); + fileIdSelection.remove(lastFileId, commitId); } getAndAddFile(getNextFile, lastFileId); diff --git a/apps/desktop/src/lib/vbranches/fileIdSelection.ts b/apps/desktop/src/lib/vbranches/fileIdSelection.ts index d72ce2da84..f8d708093c 100644 --- a/apps/desktop/src/lib/vbranches/fileIdSelection.ts +++ b/apps/desktop/src/lib/vbranches/fileIdSelection.ts @@ -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); From caceb96fdd4c17af880eab5b505295738a2d69d8 Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Mon, 26 Aug 2024 23:19:41 +0200 Subject: [PATCH 4/9] disable draggable icon for unapplied commits --- apps/desktop/src/lib/commit/CommitCard.svelte | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/lib/commit/CommitCard.svelte b/apps/desktop/src/lib/commit/CommitCard.svelte index 65a29b4e73..3e3267eb3b 100644 --- a/apps/desktop/src/lib/commit/CommitCard.svelte +++ b/apps/desktop/src/lib/commit/CommitCard.svelte @@ -232,10 +232,12 @@ class:integrated={type === 'integrated'} > - {#if type === 'local' || type === 'localAndRemote'} -
- -
+ {#if !isPreview} + {#if type === 'local' || type === 'localAndRemote'} +
+ +
+ {/if} {/if} {#if first} From f945a5d8afab39321b2954d93df58350ad591146 Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Mon, 26 Aug 2024 23:34:13 +0200 Subject: [PATCH 5/9] replace `isPreview` with existing `isUnapplied` --- apps/desktop/src/lib/commit/CommitCard.svelte | 7 +++---- apps/desktop/src/lib/components/BranchPreview.svelte | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/lib/commit/CommitCard.svelte b/apps/desktop/src/lib/commit/CommitCard.svelte index 3e3267eb3b..d2cca46003 100644 --- a/apps/desktop/src/lib/commit/CommitCard.svelte +++ b/apps/desktop/src/lib/commit/CommitCard.svelte @@ -31,7 +31,6 @@ export let branch: VirtualBranch | undefined = undefined; export let commit: DetailedCommit | Commit; export let commitUrl: string | undefined = undefined; - export let isPreview: boolean = false; export let isHeadCommit: boolean = false; export let isUnapplied = false; export let first = false; @@ -232,7 +231,7 @@ class:integrated={type === 'integrated'} > - {#if !isPreview} + {#if !isUnapplied} {#if type === 'local' || type === 'localAndRemote'}
@@ -372,10 +371,10 @@
{/if} diff --git a/apps/desktop/src/lib/components/BranchPreview.svelte b/apps/desktop/src/lib/components/BranchPreview.svelte index 16441c92d4..9a85d60caf 100644 --- a/apps/desktop/src/lib/components/BranchPreview.svelte +++ b/apps/desktop/src/lib/components/BranchPreview.svelte @@ -120,7 +120,7 @@ {#if remoteCommits} {#each remoteCommits as commit, index (commit.id)} Date: Mon, 26 Aug 2024 23:42:50 +0200 Subject: [PATCH 6/9] do not allow mutliple selection for remote commits --- apps/desktop/src/lib/commit/CommitCard.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/lib/commit/CommitCard.svelte b/apps/desktop/src/lib/commit/CommitCard.svelte index d2cca46003..6759262e3a 100644 --- a/apps/desktop/src/lib/commit/CommitCard.svelte +++ b/apps/desktop/src/lib/commit/CommitCard.svelte @@ -371,7 +371,7 @@
Date: Wed, 28 Aug 2024 00:00:28 +0200 Subject: [PATCH 7/9] refactor(utils): small update --- apps/desktop/src/lib/utils/selection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/utils/selection.ts b/apps/desktop/src/lib/utils/selection.ts index 35c25193d3..b7e33d9695 100644 --- a/apps/desktop/src/lib/utils/selection.ts +++ b/apps/desktop/src/lib/utils/selection.ts @@ -8,8 +8,8 @@ import type { AnyFile } from '$lib/vbranches/types'; export function getNextFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - const nextFile = - fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; + const nextFile = fileIndex > 0 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; + console.log('nextFile', nextFile); return nextFile; } From fe842ef60fb81b7d6219d4c47aff100ab0038c1f Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Wed, 28 Aug 2024 00:01:24 +0200 Subject: [PATCH 8/9] revert previous commit --- apps/desktop/src/lib/utils/selection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/utils/selection.ts b/apps/desktop/src/lib/utils/selection.ts index b7e33d9695..35c25193d3 100644 --- a/apps/desktop/src/lib/utils/selection.ts +++ b/apps/desktop/src/lib/utils/selection.ts @@ -8,8 +8,8 @@ import type { AnyFile } from '$lib/vbranches/types'; export function getNextFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - const nextFile = fileIndex > 0 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; - console.log('nextFile', nextFile); + const nextFile = + fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; return nextFile; } From c69a409e0420c586d0082e63d195ddd84da68912 Mon Sep 17 00:00:00 2001 From: Pavel Laptev Date: Wed, 28 Aug 2024 11:17:35 +0200 Subject: [PATCH 9/9] review changes --- apps/desktop/src/lib/utils/selection.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/lib/utils/selection.ts b/apps/desktop/src/lib/utils/selection.ts index 35c25193d3..a30045c2d3 100644 --- a/apps/desktop/src/lib/utils/selection.ts +++ b/apps/desktop/src/lib/utils/selection.ts @@ -8,15 +8,12 @@ import type { AnyFile } from '$lib/vbranches/types'; export function getNextFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - const nextFile = - fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; - return nextFile; + return fileIndex !== -1 && fileIndex + 1 < files.length ? files[fileIndex + 1] : undefined; } export function getPreviousFile(files: AnyFile[], currentId: string): AnyFile | undefined { const fileIndex = files.findIndex((f) => f.id === currentId); - const previousFile = fileIndex > 0 ? files[fileIndex - 1] : undefined; - return previousFile; + return fileIndex > 0 ? files[fileIndex - 1] : undefined; } interface MoveSelectionParams {