From 788facf44f34c6b950cf43cf04a8cd1e1aaa596f Mon Sep 17 00:00:00 2001 From: Sattva <74269253+Sattva-108@users.noreply.github.com> Date: Fri, 16 May 2025 08:24:44 +0300 Subject: [PATCH] restore-chat: EditBox auto-scrolls to cursor - The copy-chat window now always scrolls to keep the cursor visible. - Works when moving with arrow keys, Home/End, or Shift+Up/Down. - Makes copying or selecting messages easier and more comfortable. --- Leatrix_Plus.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Leatrix_Plus.lua b/Leatrix_Plus.lua index 181bb8b..8e38bf0 100644 --- a/Leatrix_Plus.lua +++ b/Leatrix_Plus.lua @@ -13259,6 +13259,46 @@ function LeaPlusLC:Player() edit:SetWidth(scroll:GetWidth()) scroll:SetScrollChild(edit) + -- Add this once when creating the editbox/scroll frame + + edit:HookScript("OnCursorChanged", function(self) + if not IsMouseButtonDown("LeftButton") and not IsMouseButtonDown("RightButton") then + LibCompat.After(0.02, function() + local fontHeight = select(2, edit:GetFont()) or 14 + local cursorPos = edit:GetCursorPosition() + local text = edit:GetText() + local n = 0 + for i = 1, cursorPos do + if text:sub(i,i) == "\n" then n = n + 1 end + end + local line = n + 1 + + -- Count total lines in editbox + local totalLines = 1 + for _ in text:gmatch("\n") do totalLines = totalLines + 1 end + + local scrollMax = scroll:GetVerticalScrollRange() + + -- If we're на последней строке — всегда вниз + if line == totalLines then + scroll:SetVerticalScroll(scrollMax) + else + local scrollMin = scroll:GetVerticalScroll() + local scrollHeight = scroll:GetHeight() + local minLine = math.floor(scrollMin / fontHeight + 1.5) + local maxLine = math.floor((scrollMin + scrollHeight) / fontHeight + 0.5) + if line < minLine then + scroll:SetVerticalScroll((line - 1) * fontHeight) + elseif line > maxLine then + scroll:SetVerticalScroll(math.max(0, (line - math.floor(scrollHeight / fontHeight)) * fontHeight)) + end + end + end) + end + end) + + + -- helper to close local function Close() edit:ClearFocus()