Make `DocView` aware of scrollbars sizes (#1177)
* Make `DocView:scroll_to_make_visible` aware of vertical scrollbar width * Make `DocView` aware of horizontal scrollbar size
This commit is contained in:
parent
e85a439656
commit
95c1805293
|
@ -112,7 +112,8 @@ end
|
||||||
|
|
||||||
function DocView:get_scrollable_size()
|
function DocView:get_scrollable_size()
|
||||||
if not config.scroll_past_end then
|
if not config.scroll_past_end then
|
||||||
return self:get_line_height() * (#self.doc.lines) + style.padding.y * 2
|
local _, _, _, h_scroll = self.h_scrollbar:get_track_rect()
|
||||||
|
return self:get_line_height() * (#self.doc.lines) + style.padding.y * 2 + h_scroll
|
||||||
end
|
end
|
||||||
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
||||||
end
|
end
|
||||||
|
@ -244,7 +245,8 @@ function DocView:scroll_to_line(line, ignore_if_visible, instant)
|
||||||
if not (ignore_if_visible and line > min and line < max) then
|
if not (ignore_if_visible and line > min and line < max) then
|
||||||
local x, y = self:get_line_screen_position(line)
|
local x, y = self:get_line_screen_position(line)
|
||||||
local ox, oy = self:get_content_offset()
|
local ox, oy = self:get_content_offset()
|
||||||
self.scroll.to.y = math.max(0, y - oy - self.size.y / 2)
|
local _, _, _, scroll_h = self.h_scrollbar:get_track_rect()
|
||||||
|
self.scroll.to.y = math.max(0, y - oy - (self.size.y - scroll_h) / 2)
|
||||||
if instant then
|
if instant then
|
||||||
self.scroll.y = self.scroll.to.y
|
self.scroll.y = self.scroll.to.y
|
||||||
end
|
end
|
||||||
|
@ -258,17 +260,20 @@ end
|
||||||
|
|
||||||
|
|
||||||
function DocView:scroll_to_make_visible(line, col)
|
function DocView:scroll_to_make_visible(line, col)
|
||||||
local ox, oy = self:get_content_offset()
|
local _, oy = self:get_content_offset()
|
||||||
local _, ly = self:get_line_screen_position(line, col)
|
local _, ly = self:get_line_screen_position(line, col)
|
||||||
local lh = self:get_line_height()
|
local lh = self:get_line_height()
|
||||||
self.scroll.to.y = common.clamp(self.scroll.to.y, ly - oy - self.size.y + lh * 2, ly - oy - lh)
|
local _, _, _, scroll_h = self.h_scrollbar:get_track_rect()
|
||||||
|
self.scroll.to.y = common.clamp(self.scroll.to.y, ly - oy - self.size.y + scroll_h + lh * 2, ly - oy - lh)
|
||||||
local gw = self:get_gutter_width()
|
local gw = self:get_gutter_width()
|
||||||
local xoffset = self:get_col_x_offset(line, col)
|
local xoffset = self:get_col_x_offset(line, col)
|
||||||
local xmargin = 3 * self:get_font():get_width(' ')
|
local xmargin = 3 * self:get_font():get_width(' ')
|
||||||
local xsup = xoffset + gw + xmargin
|
local xsup = xoffset + gw + xmargin
|
||||||
local xinf = xoffset - xmargin
|
local xinf = xoffset - xmargin
|
||||||
if xsup > self.scroll.x + self.size.x then
|
local _, _, scroll_w = self.v_scrollbar:get_track_rect()
|
||||||
self.scroll.to.x = xsup - self.size.x
|
local size_x = math.max(0, self.size.x - scroll_w)
|
||||||
|
if xsup > self.scroll.x + size_x then
|
||||||
|
self.scroll.to.x = xsup - size_x
|
||||||
elseif xinf < self.scroll.x then
|
elseif xinf < self.scroll.x then
|
||||||
self.scroll.to.x = math.max(0, xinf)
|
self.scroll.to.x = math.max(0, xinf)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue