From 7484421845ed8d377dd8868ebe38ad3ccc8ace23 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 4 Feb 2017 14:20:18 +0100 Subject: [PATCH] Also fixed pagination for negative offsets (refs #54) --- luascripts/util/pagination.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/luascripts/util/pagination.lua b/luascripts/util/pagination.lua index 6b981a8..1030f95 100644 --- a/luascripts/util/pagination.lua +++ b/luascripts/util/pagination.lua @@ -22,10 +22,14 @@ function pagination.calculate(count, limit, offset) offset = offset or 0 if offset < 0 then - offset = count + offset - end - - if limit + offset > count then + if count < math.abs(offset) then + limit = count + offset = 0 + else + limit = math.min(math.abs(offset), 30) + offset = count + offset + end + elseif limit + offset > count then limit = count % limit end