Skip to content

Commit

Permalink
Fix near page indexes crashing on invalid page number
Browse files Browse the repository at this point in the history
... which can very plausibly occur when rows get removed

fixes  #1835
  • Loading branch information
exyi committed Aug 12, 2024
1 parent d824028 commit ba42313
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Framework/Core/Controls/Options/PagingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ public virtual IList<int> GetNearPageIndexes()
/// </summary>
protected virtual IList<int> GetDefaultNearPageIndexes(int distance)
{
var firstIndex = Math.Max(PageIndex - distance, 0);
var lastIndex = Math.Min(PageIndex + distance + 1, PagesCount);
var count = this.PagesCount;
var index = Math.Max(0, Math.Min(count - 1, PageIndex)); // clamp index to be a valid page
var firstIndex = Math.Max(index - distance, 0);
var lastIndex = Math.Min(index + distance + 1, count);
return Enumerable
.Range(firstIndex, lastIndex - firstIndex)
.ToList();
Expand Down

0 comments on commit ba42313

Please sign in to comment.