Skip to content

Commit

Permalink
Merge pull request #221 from DennisvHest/220-shiftclick-to-select-map…
Browse files Browse the repository at this point in the history
…s-on-pages-other-than-page-1-selects-the-wrong-maps

Fixed shift+click selecting on pages other than the first page
  • Loading branch information
DennisvHest authored Sep 14, 2024
2 parents ef4939b + 1b9c05f commit f30e1fe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions MapMaven/Components/Maps/MapBrowser.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ async Task RemoveSelectedMapsFromSelectedPlaylist()

public void OnRowClick(DataGridRowClickEventArgs<Map> args)
{
var mapIndex = TableRef.CurrentPage * TableRef.RowsPerPage + args.RowIndex;

if (args.MouseEventArgs.CtrlKey || args.MouseEventArgs.ShiftKey)
{
if (!Selectable)
Expand All @@ -309,19 +311,19 @@ public void OnRowClick(DataGridRowClickEventArgs<Map> args)

if (args.MouseEventArgs.ShiftKey)
{
var lastSelectedRowIndex = LastSelectedRowIndex ?? args.RowIndex;
var lastSelectedRowIndex = LastSelectedRowIndex ?? mapIndex;

var mapsToSelect = TableRef.FilteredItems
.Skip(Math.Min(lastSelectedRowIndex, args.RowIndex))
.Take(Math.Abs(args.RowIndex - lastSelectedRowIndex) + 1)
.Skip(Math.Min(lastSelectedRowIndex, mapIndex))
.Take(Math.Abs(mapIndex - lastSelectedRowIndex) + 1)
.ToList();

MapService.SelectMaps(mapsToSelect);
}
}

if (Selectable)
LastSelectedRowIndex = args.RowIndex;
LastSelectedRowIndex = mapIndex;
}

/// <summary>
Expand All @@ -346,12 +348,14 @@ public string RowClassFunc(Map map, int index)
if (!Selectable)
return string.Empty;

var mapIndex = TableRef.CurrentPage * TableRef.RowsPerPage + index;

string classes = string.Empty;

if (MapService.MapIsSelected(map))
classes += "row-selected";

if (index == LastSelectedRowIndex)
if (mapIndex == LastSelectedRowIndex)
classes += " row-selected-active";

return classes;
Expand Down

0 comments on commit f30e1fe

Please sign in to comment.