From 991bc5eb3e5cf2fec8fc287b45d6801de26d7ccf Mon Sep 17 00:00:00 2001 From: Max <33982882+maxboeer@users.noreply.github.com> Date: Mon, 1 Jun 2026 05:19:36 +0200 Subject: [PATCH] Let scrollbar only scroll to whole row numbers --- compcount.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compcount.lua b/compcount.lua index 8e93a92..6a3bc52 100644 --- a/compcount.lua +++ b/compcount.lua @@ -470,9 +470,13 @@ local function runScrollableGrid(options) targetScrollRow = tonumber(initialTargetRow) or currentScrollRow end + local function snapScrollRow(row) + return math.floor((tonumber(row) or 0) + 0.5) + end + local function persistScrollState() if options.setScrollState then - options.setScrollState(currentScrollRow, targetScrollRow) + options.setScrollState(snapScrollRow(targetScrollRow), snapScrollRow(targetScrollRow)) end end @@ -503,7 +507,7 @@ local function runScrollableGrid(options) end local function scrollTo(row) - local clampedRow = clampScrollRow(row) + local clampedRow = clampScrollRow(snapScrollRow(row)) if clampedRow ~= targetScrollRow then targetScrollRow = clampedRow @@ -520,7 +524,7 @@ local function runScrollableGrid(options) totalRows = math.ceil(#entries / columns) maxScrollRow = math.max(0, totalRows - rowsPerView) currentScrollRow = clampScrollRow(currentScrollRow) - targetScrollRow = clampScrollRow(targetScrollRow) + targetScrollRow = clampScrollRow(snapScrollRow(targetScrollRow)) persistScrollState() local firstVisibleRow = math.floor(currentScrollRow)