Use drawing_cache without disable mechanism
This commit is contained in:
parent
4cb8d4dce2
commit
80e25dbfd3
|
@ -56,7 +56,7 @@ function DocView:new(doc)
|
||||||
self.doc = assert(doc)
|
self.doc = assert(doc)
|
||||||
self.font = "code_font"
|
self.font = "code_font"
|
||||||
self.last_x_offset = {}
|
self.last_x_offset = {}
|
||||||
self.step_cache = {}
|
self.drawing_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,38 +98,51 @@ function DocView:get_filename()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function DocView:get_scrollable_size()
|
function DocView:compute_scrollable_size()
|
||||||
if self.step_cache.enabled and self.step_cache.scrollable_size ~= nil then
|
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
||||||
return self.step_cache.scrollable_size
|
|
||||||
end
|
|
||||||
self.step_cache.scrollable_size = self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
|
||||||
return self.step_cache.scrollable_size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function DocView:get_h_scrollable_size()
|
|
||||||
if self.step_cache.enabled and self.step_cache.h_scrollable_size ~= nil then
|
function DocView:get_scrollable_size()
|
||||||
return self.step_cache.h_scrollable_size
|
return self.drawing_cache.scrollable_size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:compute_h_scrollable_size()
|
||||||
local xmargin = 3 * self:get_font():get_width(' ') -- from DocView:scroll_to_make_visible
|
local xmargin = 3 * self:get_font():get_width(' ') -- from DocView:scroll_to_make_visible
|
||||||
local long_line = next(self.doc.long_lines.line_numbers) or 1
|
local long_line = next(self.doc.long_lines.line_numbers) or 1
|
||||||
self.step_cache.h_scrollable_size = self:get_col_x_offset(long_line, self.doc.long_lines.length)
|
return self:get_col_x_offset(long_line, self.doc.long_lines.length) + self:get_gutter_width() + xmargin
|
||||||
+ self:get_gutter_width() + xmargin
|
|
||||||
return self.step_cache.h_scrollable_size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:get_h_scrollable_size()
|
||||||
|
return self.drawing_cache.h_scrollable_size
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function DocView:get_font()
|
function DocView:get_font()
|
||||||
return style[self.font]
|
return style[self.font]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function DocView:get_line_height()
|
function DocView:compute_line_height()
|
||||||
return math.floor(self:get_font():get_height() * config.line_height)
|
return math.floor(self:get_font():get_height() * config.line_height)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:get_line_height()
|
||||||
|
return self.drawing_cache.line_height
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:compute_gutter_width()
|
||||||
|
return self:get_font():get_width(#self.doc.lines)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function DocView:get_gutter_width()
|
function DocView:get_gutter_width()
|
||||||
local padding = style.padding.x * 2
|
local padding = style.padding.x * 2
|
||||||
return self:get_font():get_width(#self.doc.lines) + padding, padding
|
return self.drawing_cache.gutter_width + padding, padding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -285,7 +298,6 @@ end
|
||||||
|
|
||||||
|
|
||||||
function DocView:on_mouse_moved(x, y, ...)
|
function DocView:on_mouse_moved(x, y, ...)
|
||||||
self.step_cache.enabled = true
|
|
||||||
DocView.super.on_mouse_moved(self, x, y, ...)
|
DocView.super.on_mouse_moved(self, x, y, ...)
|
||||||
|
|
||||||
if self:scrollbar_overlaps_point(x, y) or self.dragging_scrollbar
|
if self:scrollbar_overlaps_point(x, y) or self.dragging_scrollbar
|
||||||
|
@ -309,7 +321,6 @@ function DocView:on_mouse_moved(x, y, ...)
|
||||||
self.doc:set_selection(mouse_selection(self.doc, clicks, l1, c1, l2, c2))
|
self.doc:set_selection(mouse_selection(self.doc, clicks, l1, c1, l2, c2))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.step_cache.enabled = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,14 +334,9 @@ function DocView:on_text_input(text)
|
||||||
self.doc:text_input(text)
|
self.doc:text_input(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DocView:invalidate_step_cache()
|
|
||||||
self.step_cache.scrollable_size = nil
|
|
||||||
self.step_cache.h_scrollable_size = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function DocView:update()
|
function DocView:update()
|
||||||
self:invalidate_step_cache()
|
self:update_drawing_cache()
|
||||||
self.step_cache.enabled = true
|
|
||||||
-- scroll to make caret visible and reset blink timer if it moved
|
-- scroll to make caret visible and reset blink timer if it moved
|
||||||
local line, col = self.doc:get_selection()
|
local line, col = self.doc:get_selection()
|
||||||
if (line ~= self.last_line or col ~= self.last_col) and self.size.x > 0 then
|
if (line ~= self.last_line or col ~= self.last_col) and self.size.x > 0 then
|
||||||
|
@ -352,7 +358,6 @@ function DocView:update()
|
||||||
end
|
end
|
||||||
|
|
||||||
DocView.super.update(self)
|
DocView.super.update(self)
|
||||||
self.step_cache.enabled = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -443,7 +448,6 @@ function DocView:draw_overlay()
|
||||||
end
|
end
|
||||||
|
|
||||||
function DocView:draw()
|
function DocView:draw()
|
||||||
self.step_cache.enabled = true
|
|
||||||
self:draw_background(style.background)
|
self:draw_background(style.background)
|
||||||
|
|
||||||
self:get_font():set_tab_size(config.indent_size)
|
self:get_font():set_tab_size(config.indent_size)
|
||||||
|
@ -470,7 +474,15 @@ function DocView:draw()
|
||||||
|
|
||||||
self:draw_scrollbar()
|
self:draw_scrollbar()
|
||||||
self:draw_h_scrollbar()
|
self:draw_h_scrollbar()
|
||||||
self.step_cache.enabled = false
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:update_drawing_cache()
|
||||||
|
local cache = self.drawing_cache
|
||||||
|
cache.gutter_width = self:compute_gutter_width()
|
||||||
|
cache.line_height = self:compute_line_height()
|
||||||
|
cache.scrollable_size = self:compute_scrollable_size()
|
||||||
|
cache.h_scrollable_size = self:compute_h_scrollable_size()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -754,6 +754,7 @@ function RootView:open_doc(doc)
|
||||||
local view = DocView(doc)
|
local view = DocView(doc)
|
||||||
node:add_view(view)
|
node:add_view(view)
|
||||||
self.root_node:update_layout()
|
self.root_node:update_layout()
|
||||||
|
view:update_drawing_cache()
|
||||||
view:scroll_to_line(view.doc:get_selection(), true, true)
|
view:scroll_to_line(view.doc:get_selection(), true, true)
|
||||||
return view
|
return view
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,6 +56,8 @@ local function set_scale(scale)
|
||||||
renderer.font.set_size(style.code_font, s * style.code_font:get_size())
|
renderer.font.set_size(style.code_font, s * style.code_font:get_size())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view:update_drawing_cache()
|
||||||
|
|
||||||
-- restore scroll positions
|
-- restore scroll positions
|
||||||
for view, n in pairs(scrolls) do
|
for view, n in pairs(scrolls) do
|
||||||
view.scroll.y = n * (view:get_scrollable_size() - view.size.y)
|
view.scroll.y = n * (view:get_scrollable_size() - view.size.y)
|
||||||
|
|
Loading…
Reference in New Issue