Skip to content

Commit 13061fb

Browse files
committed
Enable amend by dragging hunk in v3
1 parent c0eb889 commit 13061fb

File tree

4 files changed

+47
-47
lines changed

4 files changed

+47
-47
lines changed

apps/desktop/src/components/v3/FileListItemWrapper.svelte

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!-- This is a V3 replacement for `FileListItemWrapper.svelte` -->
22
<script lang="ts">
33
import FileContextMenu from '$components/v3/FileContextMenu.svelte';
4-
import { BranchStack } from '$lib/branches/branch';
54
import { draggableChips } from '$lib/dragging/draggable';
65
import { ChangeDropData } from '$lib/dragging/draggables';
76
import { getFilename } from '$lib/files/utils';
@@ -10,7 +9,7 @@
109
import { IdSelection } from '$lib/selection/idSelection.svelte';
1110
import { key, type SelectionId } from '$lib/selection/key';
1211
import { computeChangeStatus } from '$lib/utils/fileStatus';
13-
import { getContext, maybeGetContextStore } from '@gitbutler/shared/context';
12+
import { getContext } from '@gitbutler/shared/context';
1413
import FileListItemV3 from '@gitbutler/ui/file/FileListItemV3.svelte';
1514
import FileViewHeader from '@gitbutler/ui/file/FileViewHeader.svelte';
1615
import { stickyHeader } from '@gitbutler/ui/utils/stickyHeader';
@@ -53,8 +52,6 @@
5352
onCloseClick
5453
}: Props = $props();
5554
56-
const stack = maybeGetContextStore(BranchStack);
57-
const stackId = $derived($stack?.id);
5855
const idSelection = getContext(IdSelection);
5956
const changeSelection = getContext(ChangeSelectionService);
6057
const diffService = getContext(DiffService);
@@ -121,7 +118,7 @@
121118
use:draggableChips={{
122119
label: getFilename(change.path),
123120
filePath: change.path,
124-
data: new ChangeDropData(stackId || '', change, idSelection, selectionId),
121+
data: new ChangeDropData(change, idSelection, selectionId),
125122
viewportId: 'board-viewport',
126123
selector: '.selected-draggable',
127124
disabled: showCheckbox

apps/desktop/src/components/v3/UnifiedDiffView.svelte

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
22
import HunkContextMenu from '$components/v3/HunkContextMenu.svelte';
33
import LineSelection from '$components/v3/unifiedDiffLineSelection.svelte';
4+
import { draggableElement } from '$lib/dragging/draggable';
5+
import { ChangeDropData } from '$lib/dragging/draggables';
46
import { canBePartiallySelected, type DiffHunk } from '$lib/hunks/hunk';
57
import { Project } from '$lib/project/project';
68
import {
@@ -169,38 +171,44 @@
169171
{#if diff.type === 'Patch'}
170172
{#each diff.subject.hunks as hunk}
171173
{@const [staged, stagedLines] = getStageState(hunk)}
172-
<HunkDiff
173-
hideCheckboxes={!isCommiting}
174-
filePath={change.path}
175-
hunkStr={hunk.diff}
176-
{staged}
177-
{stagedLines}
178-
diffLigatures={$userSettings.diffLigatures}
179-
tabSize={$userSettings.tabSize}
180-
wrapText={$userSettings.wrapText}
181-
diffFont={$userSettings.diffFont}
182-
diffContrast={$userSettings.diffContrast}
183-
inlineUnifiedDiffs={$userSettings.inlineUnifiedDiffs}
184-
onLineClick={(p) => {
185-
if (!canBePartiallySelected(diff.subject)) {
186-
const select = selection === undefined;
187-
updateStage(hunk, select, diff.subject.hunks);
188-
return;
189-
}
190-
lineSelection.toggleStageLines(selection, hunk, p, diff.subject.hunks);
174+
<div
175+
use:draggableElement={{
176+
data: new ChangeDropData(change, idSelection, selectionId)
191177
}}
192-
onChangeStage={(selected) => {
193-
updateStage(hunk, selected, diff.subject.hunks);
194-
}}
195-
handleLineContextMenu={(params) => {
196-
contextMenu?.open(params.event, {
197-
hunk,
198-
selectedLines: stagedLines,
199-
beforeLineNumber: params.beforeLineNumber,
200-
afterLineNumber: params.afterLineNumber
201-
});
202-
}}
203-
/>
178+
>
179+
<HunkDiff
180+
hideCheckboxes={!isCommiting}
181+
filePath={change.path}
182+
hunkStr={hunk.diff}
183+
{staged}
184+
{stagedLines}
185+
diffLigatures={$userSettings.diffLigatures}
186+
tabSize={$userSettings.tabSize}
187+
wrapText={$userSettings.wrapText}
188+
diffFont={$userSettings.diffFont}
189+
diffContrast={$userSettings.diffContrast}
190+
inlineUnifiedDiffs={$userSettings.inlineUnifiedDiffs}
191+
onLineClick={(p) => {
192+
if (!canBePartiallySelected(diff.subject)) {
193+
const select = selection === undefined;
194+
updateStage(hunk, select, diff.subject.hunks);
195+
return;
196+
}
197+
lineSelection.toggleStageLines(selection, hunk, p, diff.subject.hunks);
198+
}}
199+
onChangeStage={(selected) => {
200+
updateStage(hunk, selected, diff.subject.hunks);
201+
}}
202+
handleLineContextMenu={(params) => {
203+
contextMenu?.open(params.event, {
204+
hunk,
205+
selectedLines: stagedLines,
206+
beforeLineNumber: params.beforeLineNumber,
207+
afterLineNumber: params.afterLineNumber
208+
});
209+
}}
210+
/>
211+
</div>
204212
<HunkContextMenu
205213
bind:this={contextMenu}
206214
trigger={viewport}

apps/desktop/src/lib/commits/dropHandler.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ export class AmendCommitWithChangeDzHandler implements DropzoneHandler {
6666
this.result = result;
6767
}
6868
accepts(data: unknown): boolean {
69-
return (
70-
data instanceof ChangeDropData && data.stackId !== this.stackId && !this.commit.isConflicted
71-
);
69+
return data instanceof ChangeDropData && !this.commit.isConflicted;
7270
}
7371

7472
async ondrop(data: ChangeDropData) {
@@ -140,8 +138,6 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
140138

141139
/**
142140
* Handler that is able to amend a commit using `AnyFile`.
143-
*
144-
* TODO: Refactor this to be V2 & V3 compatible.
145141
*/
146142
export class AmendCommitDzHandler implements DropzoneHandler {
147143
constructor(

apps/desktop/src/lib/dragging/draggables.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export class HunkDropData {
2626

2727
export class ChangeDropData {
2828
constructor(
29-
readonly stackId: string,
30-
readonly file: TreeChange,
29+
readonly change: TreeChange,
3130
/**
3231
* When a a file is dragged we compare it to what is already selected,
3332
* if dragged item is part of the selection we consider that to be to
@@ -40,19 +39,19 @@ export class ChangeDropData {
4039
) {}
4140

4241
changedPaths(params: SelectionId): string[] {
43-
if (this.selection.has(this.file.path, this.selectionId)) {
42+
if (this.selection.has(this.change.path, this.selectionId)) {
4443
return this.selection.keys(params);
4544
} else {
46-
return [key({ ...this.selectionId, path: this.file.path })];
45+
return [key({ ...this.selectionId, path: this.change.path })];
4746
}
4847
}
4948

5049
get filePaths(): string[] {
51-
if (this.selection.has(this.file.path, this.selectionId)) {
50+
if (this.selection.has(this.change.path, this.selectionId)) {
5251
const selectionKeys = this.selection.keys(this.selectionId);
5352
return selectionKeys.map((key) => readKey(key).path);
5453
} else {
55-
return [this.file.path];
54+
return [this.change.path];
5655
}
5756
}
5857

0 commit comments

Comments
 (0)