Skip to content

Commit 5ff3450

Browse files
committed
feature: add a button to scroll to the top of commit list
Signed-off-by: leo <[email protected]>
1 parent d6295d9 commit 5ff3450

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/Resources/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<StreamGeometry x:Key="Icons.Reset">M883 567l-128-128c-17-17-43-17-60 0l-128 128c-17 17-17 43 0 60 17 17 43 17 60 0l55-55V683c0 21-21 43-43 43H418c-13-38-43-64-77-77V375c51-17 85-64 85-119 0-73-60-128-128-128-73 0-128 55-128 128 0 55 34 102 85 119v269c-51 17-85 64-85 119 0 73 55 128 128 128 55 0 102-34 119-85H640c73 0 128-55 128-128v-111l55 55c9 9 17 13 30 13 13 0 21-4 30-13 17-13 17-43 0-55zM299 213c26 0 43 17 43 43 0 21-21 43-43 43-26 0-43-21-43-43 0-26 17-43 43-43zm0 597c-26 0-43-21-43-43 0-26 17-43 43-43s43 17 43 43c0 21-17 43-43 43zM725 384c-73 0-128-60-128-128 0-73 55-128 128-128s128 55 128 128c0 68-55 128-128 128zm0-171c-26 0-43 17-43 43s17 43 43 43 43-17 43-43-17-43-43-43z</StreamGeometry>
112112
<StreamGeometry x:Key="Icons.Save">M293 122v244h439V146l171 175V829a73 73 0 01-73 73h-98V536H293v366H195a73 73 0 01-73-73V195a73 73 0 0173-73h98zm366 512v268H366V634h293zm-49 49h-195v73h195v-73zm49-561v171H366V122h293z</StreamGeometry>
113113
<StreamGeometry x:Key="Icons.Scan">M0 551V472c0-11 9-19 19-19h984c11 0 19 9 19 19v79c0 11-9 19-19 19H19c-11 0-19-9-19-19zM114 154v240c0 11-9 19-19 19H19C9 413 0 404 0 394V79C0 35 35 0 79 0h315c11 0 19 9 19 19v75c0 11-9 19-19 19H154c-21 0-39 18-39 39zm795 0c0-22-17-39-39-39h-240c-11 0-19-9-19-19V19c0-11 9-19 19-19h315c43 0 79 35 79 79v315c0 11-9 19-19 19h-75c-11 0-19-9-19-19l-1-240zm0 716v-240c0-11 9-19 19-19h75c11 0 19 9 19 19v315c0 43-35 79-79 79h-315c-11 0-19-9-19-19v-75c0-11 9-19 19-19H870c21-1 39-18 39-40zm-795 0c0 21 18 39 39 39h240c11 0 19 9 19 19v75c0 11-9 19-19 19H79C35 1023 0 988 0 945v-315c0-11 9-19 19-19h75c11 0 19 9 19 19V870z</StreamGeometry>
114+
<StreamGeometry x:Key="Icons.ScrollToTop">M155 143h715v81H155V143zm358 94 358 369H662l1 278H363V605H155l358-369z</StreamGeometry>
114115
<StreamGeometry x:Key="Icons.Search">M702 677 590 565a148 148 0 10-25 27L676 703zm-346-200a115 115 0 11115 115A115 115 0 01355 478z</StreamGeometry>
115116
<StreamGeometry x:Key="Icons.Settings">M928 500a21 21 0 00-19-20L858 472a11 11 0 01-9-9c-1-6-2-13-3-19a11 11 0 015-12l46-25a21 21 0 0010-26l-8-22a21 21 0 00-24-13l-51 10a11 11 0 01-12-6c-3-6-6-11-10-17a11 11 0 011-13l34-39a21 21 0 001-28l-15-18a20 20 0 00-27-4l-45 27a11 11 0 01-13-1c-5-4-10-9-15-12a11 11 0 01-3-12l19-49a21 21 0 00-9-26l-20-12a21 21 0 00-27 6L650 193a9 9 0 01-11 3c-1-1-12-5-20-7a11 11 0 01-7-10l1-52a21 21 0 00-17-22l-23-4a21 21 0 00-24 14L532 164a11 11 0 01-11 7h-20a11 11 0 01-11-7l-17-49a21 21 0 00-24-15l-23 4a21 21 0 00-17 22l1 52a11 11 0 01-8 11c-5 2-15 6-19 7c-4 1-8 0-12-4l-33-40A21 21 0 00313 146l-20 12A21 21 0 00285 184l19 49a11 11 0 01-3 12c-5 4-10 8-15 12a11 11 0 01-13 1L228 231a21 21 0 00-27 4L186 253a21 21 0 001 28L221 320a11 11 0 011 13c-3 5-7 11-10 17a11 11 0 01-12 6l-51-10a21 21 0 00-24 13l-8 22a21 21 0 0010 26l46 25a11 11 0 015 12l0 3c-1 6-2 11-3 16a11 11 0 01-9 9l-51 8A21 21 0 0096 500v23A21 21 0 00114 544l51 8a11 11 0 019 9c1 6 2 13 3 19a11 11 0 01-5 12l-46 25a21 21 0 00-10 26l8 22a21 21 0 0024 13l51-10a11 11 0 0112 6c3 6 6 11 10 17a11 11 0 01-1 13l-34 39a21 21 0 00-1 28l15 18a20 20 0 0027 4l45-27a11 11 0 0113 1c5 4 10 9 15 12a11 11 0 013 12l-19 49a21 21 0 009 26l20 12a21 21 0 0027-6L374 832c3-3 7-5 10-4c7 3 12 5 20 7a11 11 0 018 10l-1 52a21 21 0 0017 22l23 4a21 21 0 0024-14l17-50a11 11 0 0111-7h20a11 11 0 0111 7l17 49a21 21 0 0020 15a19 19 0 004 0l23-4a21 21 0 0017-22l-1-52a11 11 0 018-10c8-3 13-5 18-7l1 0c6-2 9 0 11 3l34 41A21 21 0 00710 878l20-12a21 21 0 009-26l-18-49a11 11 0 013-12c5-4 10-8 15-12a11 11 0 0113-1l45 27a21 21 0 0027-4l15-18a21 21 0 00-1-28l-34-39a11 11 0 01-1-13c3-5 7-11 10-17a11 11 0 0112-6l51 10a21 21 0 0024-13l8-22a21 21 0 00-10-26l-46-25a11 11 0 01-5-12l0-3c1-6 2-11 3-16a11 11 0 019-9l51-8a21 21 0 0018-21v-23zm-565 188a32 32 0 01-51 5a270 270 0 011-363a32 32 0 0151 6l91 161a32 32 0 010 31zM512 782a270 270 0 01-57-6a32 32 0 01-20-47l92-160a32 32 0 0127-16h184a32 32 0 0130 41c-35 109-137 188-257 188zm15-328L436 294a32 32 0 0121-47a268 268 0 0155-6c120 0 222 79 257 188a32 32 0 01-30 41h-184a32 32 0 01-28-16z</StreamGeometry>
116117
<StreamGeometry x:Key="Icons.SoftwareUpdate">M900 287c40 69 60 144 60 225s-20 156-60 225c-40 69-94 123-163 163-69 40-144 60-225 60s-156-20-225-60c-69-40-123-94-163-163C84 668 64 593 64 512s20-156 60-225 94-123 163-163c69-40 144-60 225-60s156 20 225 60 123 94 163 163zM762 512c0-9-3-16-9-22L578 315l-44-44c-6-6-13-9-22-9s-16 3-22 9l-44 44-176 176c-6 6-9 13-9 22s3 16 9 22l44 44c6 6 13 9 22 9s16-3 22-9l92-92v269c0 9 3 16 9 22 6 6 13 9 22 9h62c8 0 16-3 22-9 6-6 9-13 9-22V486l92 92c6 6 13 9 22 9 8 0 16-3 22-9l44-44c6-6 9-13 9-22z</StreamGeometry>

src/ViewModels/Histories.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,10 @@ private void NavigateTo(Models.Commit commit)
315315
private List<Models.Commit> _commits = new List<Models.Commit>();
316316
private Models.CommitGraph _graph = null;
317317
private Models.Commit _autoSelectedCommit = null;
318+
private Models.Bisect _bisect = null;
318319
private long _navigationId = 0;
319320
private IDisposable _detailContext = null;
320321

321-
private Models.Bisect _bisect = null;
322-
323322
private GridLength _leftArea = new GridLength(1, GridUnitType.Star);
324323
private GridLength _rightArea = new GridLength(1, GridUnitType.Star);
325324
private GridLength _topArea = new GridLength(1, GridUnitType.Star);

src/Views/Histories.axaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@
240240
IsHitTestVisible="False"
241241
ClipToBounds="True"/>
242242

243+
<Border Width="32" Height="32"
244+
Margin="0,0,16,8"
245+
CornerRadius="16"
246+
Background="{DynamicResource Brush.Accent}"
247+
HorizontalAlignment="Right" VerticalAlignment="Bottom"
248+
Effect="drop-shadow(0 0 8 #80000000)"
249+
PointerPressed="OnScrollToTopPointerPressed"
250+
IsVisible="{Binding $parent[v:Histories].IsScrollToTopVisible}">
251+
<Path Width="16" Height="16" Data="{StaticResource Icons.ScrollToTop}" Fill="White"/>
252+
</Border>
253+
243254
<v:LoadingIcon Width="48" Height="48" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{Binding IsLoading}"/>
244255
</Grid>
245256

src/Views/Histories.axaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public long NavigationId
123123
set => SetValue(NavigationIdProperty, value);
124124
}
125125

126+
public static readonly StyledProperty<bool> IsScrollToTopVisibleProperty =
127+
AvaloniaProperty.Register<Histories, bool>(nameof(IsScrollToTopVisible));
128+
129+
public bool IsScrollToTopVisible
130+
{
131+
get => GetValue(IsScrollToTopVisibleProperty);
132+
set => SetValue(IsScrollToTopVisibleProperty, value);
133+
}
134+
126135
public Histories()
127136
{
128137
InitializeComponent();
@@ -177,6 +186,8 @@ private void OnCommitListLayoutUpdated(object _1, EventArgs _2)
177186
}
178187
}
179188

189+
SetCurrentValue(IsScrollToTopVisibleProperty, startY >= rowHeight);
190+
180191
var clipWidth = dataGrid.Columns[0].ActualWidth - 4;
181192
if (_lastGraphStartY != startY ||
182193
_lastGraphClipWidth != clipWidth ||
@@ -190,6 +201,12 @@ private void OnCommitListLayoutUpdated(object _1, EventArgs _2)
190201
}
191202
}
192203

204+
private void OnScrollToTopPointerPressed(object sender, PointerPressedEventArgs e)
205+
{
206+
if (DataContext is ViewModels.Histories histories)
207+
CommitListContainer.ScrollIntoView(histories.Commits[0], null);
208+
}
209+
193210
private void OnCommitListSelectionChanged(object _, SelectionChangedEventArgs e)
194211
{
195212
if (DataContext is ViewModels.Histories histories)

0 commit comments

Comments
 (0)