From 97cb4b690615626a5c56d9d5c6c841d668c3feb2 Mon Sep 17 00:00:00 2001 From: Sattva <74269253+Sattva-108@users.noreply.github.com> Date: Fri, 16 May 2025 09:44:31 +0300 Subject: [PATCH] restore-chat: fix mouse-scroll scrolling down with mouse while window too small was not working --- Leatrix_Plus.lua | 55 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/Leatrix_Plus.lua b/Leatrix_Plus.lua index 33f2b89..4e79de8 100644 --- a/Leatrix_Plus.lua +++ b/Leatrix_Plus.lua @@ -13282,23 +13282,50 @@ function LeaPlusLC:Player() currentEdit:SetHeight(math.max(needed, scroll:GetHeight())) -- scroll is LeaPlusLC.RecentChatScroll end + -- scroll with mouse-wheel -- scroll with mouse-wheel scroll:SetScript("OnMouseWheel", function(self, delta) - local cur = self:GetVerticalScroll() - local max = self:GetVerticalScrollRange() - local h = self:GetHeight() - local step= 20 - if delta > 0 then - cur = IsShiftKeyDown() and 0 - or IsAltKeyDown() and cur - h - or cur - step - else - cur = IsShiftKeyDown() and max - or IsAltKeyDown() and cur + h - or cur + step + local currentEdit = LeaPlusLC.RecentChatEdit -- self is the scroll frame + + local maxScrollRange = self:GetVerticalScrollRange() + + -- If there's nothing to scroll (content fits within view), do nothing. + if not maxScrollRange or maxScrollRange <= 0 then + return end - if cur < 0 then cur = 0 elseif cur > max then cur = max end - self:SetVerticalScroll(cur) + + local currentScroll = self:GetVerticalScroll() + local viewHeight = self:GetHeight() -- The visible height of the scroll area + + local stepAmount + if IsAltKeyDown() then + -- Alt + Wheel: Page up/down + stepAmount = viewHeight + else + -- Normal Wheel: Scroll by a few lines + local fontHeight = 14 -- Default reasonable font height + if currentEdit and currentEdit:IsShown() then + local _, fh = currentEdit:GetFont() + if fh and fh > 0 then + fontHeight = fh + end + end + local linesToScroll = 3 -- Scroll 3 lines per tick + stepAmount = fontHeight * linesToScroll + end + + local newScrollPosition + if delta > 0 then -- Scrolling up (wheel moved away from user) + newScrollPosition = IsShiftKeyDown() and 0 or (currentScroll - stepAmount) + else -- Scrolling down (wheel moved towards user) + newScrollPosition = IsShiftKeyDown() and maxScrollRange or (currentScroll + stepAmount) + end + + -- Clamp the new scroll position to be within the valid range [0, maxScrollRange] + newScrollPosition = math.max(0, newScrollPosition) + newScrollPosition = math.min(newScrollPosition, maxScrollRange) + + self:SetVerticalScroll(newScrollPosition) end) ----------------------------------------