Skip to content

Commit

Permalink
Merge pull request #79 from anmcgrath/handle_empty_row_cols_better
Browse files Browse the repository at this point in the history
  • Loading branch information
anmcgrath authored Jun 20, 2024
2 parents 498e450 + 79a4f5d commit bdf0f67
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 218 deletions.
4 changes: 2 additions & 2 deletions src/BlazorDatasheet.Core/Layout/CellLayoutProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public Viewport GetViewPort(double left, double top, double containerWidth, doub
var visibleRowEnd = ComputeRow(top + containerHeight);
var visibleColEnd = ComputeColumn(left + containerWidth);

visibleRowEnd = Math.Clamp(visibleRowEnd, 0, _sheet.NumRows - 1);
visibleColEnd = Math.Min(_sheet.NumCols - 1, visibleColEnd);
visibleRowEnd = Math.Clamp(visibleRowEnd, 0, Math.Max(_sheet.NumRows - 1, 0));
visibleColEnd = Math.Clamp(visibleColEnd, 0, Math.Max(_sheet.NumCols - 1, 0));

var startRow = Math.Max(visibleRowStart - overflowY, 0);
var endRow = Math.Min(Math.Max(_sheet.NumRows - 1, 0), visibleRowEnd + overflowY);
Expand Down
11 changes: 9 additions & 2 deletions src/BlazorDatasheet.Core/Selecting/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,23 @@ public void Set(List<IRegion> regions)

public void ConstrainSelectionToSheet()
{
if (_sheet.NumRows == 0 || _sheet.NumCols == 0)
{
this.ClearSelections();
return;
}

var constrainedRegions = new List<IRegion>();
for (int i = 0; i < _regions.Count; i++)
{
var intersection = _regions[i].GetIntersection(_sheet.Region);
if (intersection != null)
constrainedRegions.Add(intersection);
}

ActiveRegion = null;
_regions.Clear();
_regions.AddRange(constrainedRegions);
EmitSelectionChange();
Set(constrainedRegions);
}

/// <summary>
Expand Down
Loading

0 comments on commit bdf0f67

Please sign in to comment.