Abstracted out draw caret, so that the line guide can draw under it. (#287)

* Abstracted out draw caret, so that the line guide can draw under it.

* Moved caret drawing out to draw_overlay.
This commit is contained in:
Adam 2021-06-20 16:16:35 -04:00 committed by GitHub
parent 559be66e80
commit 2486f253eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 22 deletions

View File

@ -350,6 +350,10 @@ function DocView:draw_line_text(idx, x, y)
end end
end end
function DocView:draw_caret(x, y)
local lh = self:get_line_height()
renderer.draw_rect(x, y, style.caret_width, lh, style.caret)
end
function DocView:draw_line_body(idx, x, y) function DocView:draw_line_body(idx, x, y)
-- draw selection if it overlaps this line -- draw selection if it overlaps this line
@ -374,18 +378,6 @@ function DocView:draw_line_body(idx, x, y)
-- draw line's text -- draw line's text
self:draw_line_text(idx, x, y) self:draw_line_text(idx, x, y)
-- draw caret if it overlaps this line
local T = config.blink_period
for _, line, col in self.doc:get_selections() do
if line == idx and core.active_view == self
and (core.blink_timer - core.blink_start) % T < T / 2
and system.window_has_focus() then
local lh = self:get_line_height()
local x1 = x + self:get_col_x_offset(line, col)
renderer.draw_rect(x1, y, style.caret_width, lh, style.caret)
end
end
end end
@ -403,30 +395,45 @@ function DocView:draw_line_gutter(idx, x, y)
end end
function DocView:draw_overlay()
if core.active_view == self then
local minline, maxline = self:get_visible_line_range()
-- draw caret if it overlaps this line
local T = config.blink_period
for _, line, col in self.doc:get_selections() do
if line >= minline and line <= maxline
and (core.blink_timer - core.blink_start) % T < T / 2
and system.window_has_focus() then
local x, y = self:get_line_screen_position(line)
self:draw_caret(x + self:get_col_x_offset(line, col), y)
end
end
end
end
function DocView:draw() function DocView:draw()
self:draw_background(style.background) self:draw_background(style.background)
local font = self:get_font() self:get_font():set_tab_size(config.indent_size)
font:set_tab_size(config.indent_size)
local minline, maxline = self:get_visible_line_range() local minline, maxline = self:get_visible_line_range()
local lh = self:get_line_height() local lh = self:get_line_height()
local _, y = self:get_line_screen_position(minline) local x, y = self:get_line_screen_position(minline)
local x = self.position.x
for i = minline, maxline do for i = minline, maxline do
self:draw_line_gutter(i, x, y) self:draw_line_gutter(i, self.position.x, y)
y = y + lh y = y + lh
end end
local x, y = self:get_line_screen_position(minline)
local gw = self:get_gutter_width() local gw = self:get_gutter_width()
local pos = self.position local pos = self.position
x, y = self:get_line_screen_position(minline)
core.push_clip_rect(pos.x + gw, pos.y, self.size.x, self.size.y) core.push_clip_rect(pos.x + gw, pos.y, self.size.x, self.size.y)
for i = minline, maxline do for i = minline, maxline do
self:draw_line_body(i, x, y) self:draw_line_body(i, x, y)
y = y + lh y = y + lh
end end
self:draw_overlay()
core.pop_clip_rect() core.pop_clip_rect()
self:draw_scrollbar() self:draw_scrollbar()