From fcf09d66182dc9c2e65e1b807bffa1e391dfc9dc Mon Sep 17 00:00:00 2001 From: Stepets Date: Sat, 25 Oct 2014 14:11:35 +0400 Subject: [PATCH] added indicator tracking --- objects/textinput.lua | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/objects/textinput.lua b/objects/textinput.lua index 07241d5..588584d 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -937,6 +937,54 @@ function newobject:UpdateIndicator() self.indicatory = texty end + -- indicator should be visible, so correcting scrolls + local indicatorRelativeX = width + self.textoffsetx - self.offsetx + local leftlimit, rightlimit = 0, self:GetWidth() + if self.linenumberspanel then + leftlimit = leftlimit + self:GetLineNumbersPanel().width + end + if self.vbar then + rightlimit = rightlimit - self:GetVerticalScrollBody().width + end + if not (indicatorRelativeX > leftlimit and indicatorRelativeX < rightlimit) then + local hbody = self:GetHorizontalScrollBody() + if hbody then + local twidth = 0 + for k, v in ipairs(lines) do + local linewidth = 0 + if self.masked then + linewidth = font:getWidth(v:gsub(".", self.maskchar)) + else + linewidth = font:getWidth(v) + end + if linewidth > twidth then + twidth = linewidth + end + end + local correction = self:GetWidth() / 2 + if indicatorRelativeX < leftlimit then + correction = correction * -1 + end + print(correction) + hbody:GetScrollBar():ScrollTo((width + correction) / twidth) + end + end + local indicatorRelativeY = (line - 1) * theight + self.textoffsety - self.offsety + local uplimit, downlimit = 0, self:GetHeight() + if self.hbar then + downlimit = downlimit - self:GetHorizontalScrollBody().height + end + if not (indicatorRelativeY > uplimit and indicatorRelativeY < downlimit) then + local vbody = self:GetVerticalScrollBody() + if vbody then + local correction = self:GetHeight() / 2 / theight + if indicatorRelativeY < uplimit then + correction = correction * -1 + end + vbody:GetScrollBar():ScrollTo((line - 1 + correction)/#lines) + end + end + return self end