Skip to content

Commit 5b818b6

Browse files
committed
refactor: use a single property to indicate drop direction
Signed-off-by: leo <longshuang@msn.cn>
1 parent a3f3415 commit 5b818b6

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

src/ViewModels/InteractiveRebase.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Text.Json;
66
using System.Threading.Tasks;
7-
7+
using Avalonia;
88
using Avalonia.Collections;
99
using Avalonia.Threading;
1010

@@ -82,16 +82,10 @@ public bool IsFullMessageUsed
8282
set => SetProperty(ref _isFullMessageUsed, value);
8383
}
8484

85-
public bool IsDropBeforeVisible
86-
{
87-
get => _isDropBeforeVisible;
88-
set => SetProperty(ref _isDropBeforeVisible, value);
89-
}
90-
91-
public bool IsDropAfterVisible
85+
public Thickness DropDirectionIndicator
9286
{
93-
get => _isDropAfterVisible;
94-
set => SetProperty(ref _isDropAfterVisible, value);
87+
get => _dropDirectionIndicator;
88+
set => SetProperty(ref _dropDirectionIndicator, value);
9589
}
9690

9791
public bool IsMessageUserEdited
@@ -116,8 +110,7 @@ public InteractiveRebaseItem(int order, Models.Commit c, string message, bool ca
116110
private bool _canSquashOrFixup = true;
117111
private bool _showEditMessageButton = false;
118112
private bool _isFullMessageUsed = true;
119-
private bool _isDropBeforeVisible = false;
120-
private bool _isDropAfterVisible = false;
113+
private Thickness _dropDirectionIndicator = new Thickness(0);
121114
}
122115

123116
public class InteractiveRebase : ObservableObject

src/Views/InteractiveRebase.axaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@
118118
<ColumnDefinition Width="Auto" SharedSizeGroup="CommitTimeColumn"/>
119119
</Grid.ColumnDefinitions>
120120

121+
<!-- Drop Direction Indicator -->
122+
<Border Grid.Column="0" Grid.ColumnSpan="8"
123+
Background="Transparent"
124+
BorderThickness="{Binding DropDirectionIndicator, Mode=OneWay}"
125+
BorderBrush="{DynamicResource Brush.Accent}"/>
126+
121127
<!-- Original Order -->
122128
<TextBlock Grid.Column="0"
123129
Margin="4,0,0,0"
@@ -189,20 +195,6 @@
189195
Text="{Binding Commit.CommitterTimeStr}"
190196
Opacity="{Binding IsFullMessageUsed, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"/>
191197
</Border>
192-
193-
<!-- Drop Indicator -->
194-
<Rectangle Grid.Column="0" Grid.ColumnSpan="8"
195-
Height="2"
196-
VerticalAlignment="Top"
197-
Fill="{DynamicResource Brush.Accent}"
198-
IsVisible="{Binding IsDropBeforeVisible, Mode=OneWay}"
199-
IsHitTestVisible="False"/>
200-
<Rectangle Grid.Column="0" Grid.ColumnSpan="8"
201-
Height="2"
202-
VerticalAlignment="Bottom"
203-
Fill="{DynamicResource Brush.Accent}"
204-
IsVisible="{Binding IsDropAfterVisible, Mode=OneWay}"
205-
IsHitTestVisible="False"/>
206198
</Grid>
207199
</DataTemplate>
208200
</v:InteractiveRebaseListBox.ItemTemplate>

src/Views/InteractiveRebase.axaml.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ private void OnRowDragOver(object sender, DragEventArgs e)
266266

267267
var p = e.GetPosition(control);
268268
var before = p.Y < control.Bounds.Height * 0.5;
269-
270-
dst.IsDropBeforeVisible = before;
271-
dst.IsDropAfterVisible = !before;
269+
dst.DropDirectionIndicator = before ? new Thickness(0, 2, 0, 0) : new Thickness(0, 0, 0, 2);
272270
e.DragEffects = DragDropEffects.Move;
273271
e.Handled = true;
274272
}
@@ -278,8 +276,7 @@ private void OnRowDragLeave(object sender, DragEventArgs e)
278276
if (sender is not Control { DataContext: ViewModels.InteractiveRebaseItem dst })
279277
return;
280278

281-
dst.IsDropBeforeVisible = false;
282-
dst.IsDropAfterVisible = false;
279+
dst.DropDirectionIndicator = new Thickness(0);
283280
e.Handled = true;
284281
}
285282

@@ -315,8 +312,7 @@ private void OnRowDrop(object sender, DragEventArgs e)
315312
vm.Move(commits, before ? idx : idx + 1);
316313
IRItemListBox.SelectedItems = commits;
317314

318-
dst.IsDropBeforeVisible = false;
319-
dst.IsDropAfterVisible = false;
315+
dst.DropDirectionIndicator = new Thickness(0);
320316
e.DragEffects = DragDropEffects.None;
321317
e.Handled = true;
322318
}

0 commit comments

Comments
 (0)