diff options
author | jgmdev <jgmdev@gmail.com> | 2022-05-22 14:37:28 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-05-22 14:37:28 -0400 |
commit | 76bacb1fe9d0d92bb8c22a6767a98b0589d4bdd3 (patch) | |
tree | 11091b18f989d310fe43996b60e15ff482520c50 | |
parent | 694132ec9d81ced3d8c6ebbf10e451bbc5a9e65b (diff) | |
download | lite-xl-plugins-76bacb1fe9d0d92bb8c22a6767a98b0589d4bdd3.tar.gz lite-xl-plugins-76bacb1fe9d0d92bb8c22a6767a98b0589d4bdd3.zip |
Fix various plugins for linewrapping
-rw-r--r-- | plugins/bracketmatch.lua | 12 | ||||
-rw-r--r-- | plugins/centerdoc.lua | 8 | ||||
-rw-r--r-- | plugins/colorpreview.lua | 3 | ||||
-rw-r--r-- | plugins/extend_selection_line.lua | 9 | ||||
-rw-r--r-- | plugins/indentguide.lua | 2 | ||||
-rw-r--r-- | plugins/linenumbers.lua | 18 | ||||
-rw-r--r-- | plugins/markers.lua | 8 | ||||
-rw-r--r-- | plugins/motiontrail.lua | 2 | ||||
-rw-r--r-- | plugins/selectionhighlight.lua | 13 | ||||
-rw-r--r-- | plugins/smoothcaret.lua | 4 |
10 files changed, 44 insertions, 35 deletions
diff --git a/plugins/bracketmatch.lua b/plugins/bracketmatch.lua index e86e64c..5930b7b 100644 --- a/plugins/bracketmatch.lua +++ b/plugins/bracketmatch.lua @@ -96,16 +96,18 @@ end local draw_line_text = DocView.draw_line_text -function DocView:draw_line_text(idx, x, y) - draw_line_text(self, idx, x, y) +function DocView:draw_line_text(line, x, y) + local lh = draw_line_text(self, line, x, y) - if self.doc == state.doc and idx == state.line2 then + if self.doc == state.doc and line == state.line2 then local color = style.bracketmatch_color or style.syntax["function"] - local x1 = x + self:get_col_x_offset(idx, state.col2) - local x2 = x + self:get_col_x_offset(idx, state.col2 + 1) + local x1 = x + self:get_col_x_offset(line, state.col2) + local x2 = x + self:get_col_x_offset(line, state.col2 + 1) local h = math.ceil(1 * SCALE) renderer.draw_rect(x1, y + self:get_line_height() - h, x2 - x1, h, color) end + + return lh end diff --git a/plugins/centerdoc.lua b/plugins/centerdoc.lua index c657725..a771925 100644 --- a/plugins/centerdoc.lua +++ b/plugins/centerdoc.lua @@ -15,14 +15,16 @@ local draw_line_gutter = DocView.draw_line_gutter local get_gutter_width = DocView.get_gutter_width -function DocView:draw_line_gutter(idx, x, y, width) +function DocView:draw_line_gutter(line, x, y, width) + local lh if not config.plugins.centerdoc.enable then - draw_line_gutter(self, idx, x, y, width) + lh = draw_line_gutter(self, line, x, y, width) else local real_gutter_width = get_gutter_width(self) local offset = self:get_gutter_width() - real_gutter_width * 2 - draw_line_gutter(self, idx, x + offset, y, real_gutter_width) + lh = draw_line_gutter(self, line, x + offset, y, real_gutter_width) end + return lh end diff --git a/plugins/colorpreview.lua b/plugins/colorpreview.lua index df80c8c..d255639 100644 --- a/plugins/colorpreview.lua +++ b/plugins/colorpreview.lua @@ -55,8 +55,9 @@ end local draw_line_text = DocView.draw_line_text function DocView:draw_line_text(idx, x, y) - draw_line_text(self, idx, x, y) + local lh = draw_line_text(self, idx, x, y) draw_color_previews(self, idx, x, y, "#(%x%x)(%x%x)(%x%x)(%x?%x?)%f[%W]", 16) draw_color_previews(self, idx, x, y, "#(%x)(%x)(%x)%f[%W]", 16, true) -- support #fff css format draw_color_previews(self, idx, x, y, "rgba?%((%d+)%D+(%d+)%D+(%d+)[%s,]-([%.%d]-)%s-%)", nil) + return lh end diff --git a/plugins/extend_selection_line.lua b/plugins/extend_selection_line.lua index dcdde73..968399c 100644 --- a/plugins/extend_selection_line.lua +++ b/plugins/extend_selection_line.lua @@ -3,17 +3,18 @@ local DocView = require "core.docview" local style = require "core.style" local draw_line_body = DocView.draw_line_body -function DocView:draw_line_body(idx, x, y, ...) - draw_line_body(self, idx, x, y, ...) +function DocView:draw_line_body(line, x, y) + local line_height = draw_line_body(self, line, x, y) local lh = self:get_line_height() for _, line1, _, line2, _ in self.doc:get_selections(true) do - if idx >= line1 and idx < line2 and line1 ~= line2 then + if line >= line1 and line < line2 and line1 ~= line2 then -- draw selection from the end of the line to the end of the available space - local x1 = x + self:get_col_x_offset(idx, #self.doc.lines[idx]) + local x1 = x + self:get_col_x_offset(line, #self.doc.lines[line]) local x2 = x + self.scroll.x + self.size.x if x2 > x1 then renderer.draw_rect(x1, y, x2 - x1, lh, style.selection) end end end + return line_height end diff --git a/plugins/indentguide.lua b/plugins/indentguide.lua index 389ea14..f097a65 100644 --- a/plugins/indentguide.lua +++ b/plugins/indentguide.lua @@ -119,5 +119,5 @@ function DocView:draw_line_text(idx, x, y) local sw = space_sz * i renderer.draw_rect(math.ceil(x + sw), y, w, h, color) end - draw_line_text(self, idx, x, y) + return draw_line_text(self, idx, x, y) end diff --git a/plugins/linenumbers.lua b/plugins/linenumbers.lua index b61e3e4..76c691d 100644 --- a/plugins/linenumbers.lua +++ b/plugins/linenumbers.lua @@ -10,26 +10,27 @@ config.plugins.linenumbers = common.merge({ relative = false }, config.plugins.linenumbers) -local draw = DocView.draw_line_gutter +local draw_line_gutter = DocView.draw_line_gutter local get_width = DocView.get_gutter_width -function DocView:draw_line_gutter(idx, x, y, width) +function DocView:draw_line_gutter(line, x, y, width) + local lh = self:get_line_height() if not config.plugins.linenumbers.show and not config.plugins.linenumbers.relative then - return + return lh end if config.plugins.linenumbers.relative then local color = style.line_number - local local_idx = idx + local local_idx = line local align = "right" local l1 = self.doc:get_selection(false) - if idx == l1 then + if line == l1 then color = style.line_number2 if config.line_numbers then align = "center" @@ -37,7 +38,7 @@ function DocView:draw_line_gutter(idx, x, y, width) local_idx = 0 end else - local_idx = math.abs(idx - l1) + local_idx = math.abs(line - l1) end -- Fix for old version (<=1.16) @@ -52,11 +53,12 @@ function DocView:draw_line_gutter(idx, x, y, width) color, local_idx, align, x + style.padding.x, y + self:get_line_text_y_offset(), - width, self:get_line_height() + width, lh ) else - draw(self, idx, x, y, width) + draw_line_gutter(self, line, x, y, width) end + return lh end function DocView:get_gutter_width(...) diff --git a/plugins/markers.lua b/plugins/markers.lua index a65eaea..176eff1 100644 --- a/plugins/markers.lua +++ b/plugins/markers.lua @@ -1,4 +1,4 @@ --- mod-version:3 --lite-xl 2.1 +-- mod-version:3 --lite-xl 2.1
-- Markers plugin for lite text editor
-- original implementation by Petri Häkkinen
@@ -52,12 +52,12 @@ end local draw_line_gutter = DocView.draw_line_gutter
-function DocView:draw_line_gutter(idx, x, y, width)
- if cache[self.doc] and cache[self.doc][idx] then
+function DocView:draw_line_gutter(line, x, y, width)
+ if cache[self.doc] and cache[self.doc][line] then
local h = self:get_line_height()
renderer.draw_rect(x, y, style.padding.x * 0.4, h, style.selection)
end
- draw_line_gutter(self, idx, x, y, width)
+ return draw_line_gutter(self, line, x, y, width)
end
diff --git a/plugins/motiontrail.lua b/plugins/motiontrail.lua index 112e1cd..fd42b5f 100644 --- a/plugins/motiontrail.lua +++ b/plugins/motiontrail.lua @@ -15,7 +15,7 @@ end local function get_caret_rect(dv) local line, col = dv.doc:get_selection() - local x, y = dv:get_line_screen_position(line) + local x, y = dv:get_line_screen_position(line, col) x = x + dv:get_col_x_offset(line, col) return x, y, style.caret_width, dv:get_line_height() end diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua index 2835eec..d17acff 100644 --- a/plugins/selectionhighlight.lua +++ b/plugins/selectionhighlight.lua @@ -16,15 +16,15 @@ end local draw_line_body = DocView.draw_line_body -function DocView:draw_line_body(idx, x, y) - draw_line_body(self, idx, x, y) +function DocView:draw_line_body(line, x, y) + local line_height = draw_line_body(self, line, x, y) local line1, col1, line2, col2 = self.doc:get_selection(true) if line1 == line2 and col1 ~= col2 then local selection = self.doc:get_text(line1, col1, line2, col2) if not selection:match("^%s+$") then local lh = self:get_line_height() local selected_text = self.doc.lines[line1]:sub(col1, col2 - 1) - local current_line_text = self.doc.lines[idx] + local current_line_text = self.doc.lines[line] local last_col = 1 while true do local start_col, end_col = current_line_text:find( @@ -32,9 +32,9 @@ function DocView:draw_line_body(idx, x, y) ) if start_col == nil then break end -- don't draw box around the selection - if idx ~= line1 or start_col ~= col1 then - local x1 = x + self:get_col_x_offset(idx, start_col) - local x2 = x + self:get_col_x_offset(idx, end_col + 1) + if line ~= line1 or start_col ~= col1 then + local x1 = x + self:get_col_x_offset(line, start_col) + local x2 = x + self:get_col_x_offset(line, end_col + 1) local color = style.selectionhighlight or style.syntax.comment draw_box(x1, y, x2 - x1, lh, color) end @@ -42,5 +42,6 @@ function DocView:draw_line_body(idx, x, y) end end end + return line_height end diff --git a/plugins/smoothcaret.lua b/plugins/smoothcaret.lua index 335dd08..2d0a633 100644 --- a/plugins/smoothcaret.lua +++ b/plugins/smoothcaret.lua @@ -22,7 +22,7 @@ function DocView:update() local idx, v_idx = 1, 1 for _, line, col in self.doc:get_selections() do - local x, y = self:get_line_screen_position(line) + local x, y = self:get_line_screen_position(line, col) -- Keep the position relative to the whole View -- This way scrolling won't animate the caret x = x + self:get_col_x_offset(line, col) + self.scroll.x @@ -57,7 +57,7 @@ function DocView:update() -- Remove unused carets to avoid animating new ones when they are added for i = idx, #self.carets do - self.carets[idx] = nil + self.carets[i] = nil end if self.mouse_selecting ~= self.last_mouse_selecting then |