From 0e779bba0f1c9235a4af908d0bcb3134baa89587 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Nov 2023 15:29:37 -0500 Subject: [PATCH] Reverted cursor API to something more compatible with old API. (#1674) * Reverted cursor API to something more compatible with old API. * Implemented discord discussion. * Reduced thiccness of overwrite cursor. --- data/core/docview.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/data/core/docview.lua b/data/core/docview.lua index c2502040..b679eb6f 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -460,14 +460,16 @@ function DocView:draw_line_text(line, x, y) return self:get_line_height() end -function DocView:draw_caret(x, y, line, col) + +function DocView:draw_overwrite_caret(x, y, width) local lh = self:get_line_height() - if self.doc.overwrite then - local w = self:get_font():get_width(self.doc:get_char(line, col)) - renderer.draw_rect(x, y + lh, w, style.caret_width * 2, style.caret) - else - renderer.draw_rect(x, y, style.caret_width, lh, style.caret) - end + renderer.draw_rect(x, y + lh - style.caret_width, width, style.caret_width, style.caret) +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(line, x, y) @@ -547,7 +549,7 @@ function DocView:draw_ime_decoration(line1, col1, line2, col2) line_size = style.caret_width renderer.draw_rect(x + math.min(x1, x2), y + lh - line_size, math.abs(x1 - x2), line_size, style.caret) end - self:draw_caret(x + x1, y, line1, col) + self:draw_caret(x + x1, y) end @@ -565,7 +567,11 @@ function DocView:draw_overlay() if config.disable_blink or (core.blink_timer - core.blink_start) % T < T / 2 then local x, y = self:get_line_screen_position(line1, col1) - self:draw_caret(x, y, line1, col1) + if self.doc.overwrite then + self:draw_overwrite_caret(x, y, self:get_font():get_width(self.doc:get_char(line1, col1))) + else + self:draw_caret(x, y) + end end end end