diff options
author | Joshua Minor <github@pixelverse.org> | 2021-11-21 01:49:49 -0800 |
---|---|---|
committer | Joshua Minor <github@pixelverse.org> | 2021-11-27 00:36:22 -0800 |
commit | dd62e94c7a660ce62246becb69a91ce4bbf97330 (patch) | |
tree | 93e308865934d49bdd7e9b9789f884d8ba516dc5 /plugins/minimap.lua | |
parent | 3834db399042ac72c032d94b510cf5921e123b3a (diff) | |
download | lite-xl-plugins-dd62e94c7a660ce62246becb69a91ce4bbf97330.tar.gz lite-xl-plugins-dd62e94c7a660ce62246becb69a91ce4bbf97330.zip |
Minimap supports per-line highlight colors, with adjustable gutter_width and highlight_width.
Diffstat (limited to 'plugins/minimap.lua')
-rw-r--r-- | plugins/minimap.lua | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/plugins/minimap.lua b/plugins/minimap.lua index 3f4a2a2..8e8177f 100644 --- a/plugins/minimap.lua +++ b/plugins/minimap.lua @@ -4,6 +4,7 @@ local common = require "core.common" local config = require "core.config" local style = require "core.style" local DocView = require "core.docview" +local Object = require "core.object" -- General plugin settings config.plugins.minimap = { @@ -14,7 +15,22 @@ config.plugins.minimap = { scale = 1, -- how many spaces one tab is equivalent to tab_width = 4, - draw_background = true + draw_background = true, + -- if highlight_width is positive, it is drawn on the left + -- if highlight_width is negative, it is drawn on the right + -- gutter_width pushes the minimap text to the left to make room for a left-side highlight + highlight_width = -5, + gutter_width = 0, + -- try these values: + -- full width: + -- config.plugins.minimap.highlight_width = 100 + -- config.plugins.minimap.gutter_width = 0 + -- left side: + -- config.plugins.minimap.highlight_width = 3 + -- config.plugins.minimap.gutter_width = 4 + -- right side: + -- config.plugins.minimap.highlight_width = -5 + -- config.plugins.minimap.gutter_width = 0 } -- Configure size for rendering each char in the minimap @@ -22,6 +38,22 @@ local char_height = 1 * SCALE * config.plugins.minimap.scale local char_spacing = 0.8 * SCALE * config.plugins.minimap.scale local line_spacing = 2 * SCALE * config.plugins.minimap.scale +local MiniMap = Object:extend() + +function MiniMap:new() + self.line_highlight_color = {} +end + +function MiniMap:set_line_highlight_color(line, color) + self.line_highlight_color[line] = color +end + +function MiniMap:clear_all_line_highlights() + self.line_highlight_color = {} +end + +local minimap = MiniMap() + -- Overloaded since the default implementation adds a extra x3 size of hotspot for the mouse to hit the scrollbar. local prev_scrollbar_overlaps_point = DocView.scrollbar_overlaps_point DocView.scrollbar_overlaps_point = function(self, x, y) @@ -196,6 +228,9 @@ DocView.draw_scrollbar = function(self) -- draw visual rect renderer.draw_rect(x, visible_y, w, scroller_height, visual_color) + local highlight_width = config.plugins.minimap.highlight_width + local gutter_width = config.plugins.minimap.gutter_width + -- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind. local line_y = y @@ -236,9 +271,18 @@ DocView.draw_scrollbar = function(self) endidx = math.min(endidx, line_count) for idx = minimap_start_line, endidx do batch_syntax_type = nil - batch_start = x + batch_start = x + gutter_width batch_width = 0 + local highlight_color = minimap.line_highlight_color[idx] + if highlight_color then + if highlight_width > 0 then + renderer.draw_rect(x, line_y, highlight_width, line_spacing, highlight_color) + else + renderer.draw_rect(x + w + highlight_width, line_y, -highlight_width, line_spacing, highlight_color) + end + end + -- per token for _, type, text in self.doc.highlighter:each_token(idx) do -- flush prev batch @@ -268,9 +312,14 @@ DocView.draw_scrollbar = function(self) else -- render lines without syntax highlighting for idx = 1, line_count - 1 do - batch_start = x + batch_start = x + gutter_width batch_width = 0 + local highlight_color = minimap.line_highlight_color[idx] + if highlight_color then + renderer.draw_rect(x, line_y, highlight_width, line_spacing, highlight_color) + end + for char in common.utf8_chars(self.doc.lines[idx]) do if char == " " or char == "\n" then flush_batch() @@ -304,3 +353,6 @@ command.add(nil, { config.plugins.minimap.syntax_highlight = not config.plugins.minimap.syntax_highlight end }) + +return minimap + |