added indicator tracking

This commit is contained in:
Stepets 2014-10-25 14:11:35 +04:00
parent b435889831
commit fcf09d6618

View File

@ -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