aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/language_ts.lua73
-rw-r--r--plugins/language_yaml.lua57
-rw-r--r--plugins/language_zig.lua160
-rw-r--r--plugins/minimap.lua511
4 files changed, 416 insertions, 385 deletions
diff --git a/plugins/language_ts.lua b/plugins/language_ts.lua
new file mode 100644
index 0000000..96cf0d3
--- /dev/null
+++ b/plugins/language_ts.lua
@@ -0,0 +1,73 @@
+-- mod-version:1 -- lite-xl 1.16
+-- copied from language_js, but added regex highlighting back
+local syntax = require "core.syntax"
+
+syntax.add {
+ files = { "%.ts$" },
+ comment = "//",
+ patterns = {
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { '/%g', '/', '\\' }, type = "string" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = { "`", "`", '\\' }, type = "string" },
+ { pattern = "0x[%da-fA-F]+", type = "number" },
+ { pattern = "-?%d+[%d%.eE]*", type = "number" },
+ { pattern = "-?%.?%d+", type = "number" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
+ { pattern = "interface%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
+ { pattern = "type%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ },
+ symbols = {
+ ["async"] = "keyword",
+ ["await"] = "keyword",
+ ["break"] = "keyword",
+ ["case"] = "keyword",
+ ["catch"] = "keyword",
+ ["class"] = "keyword",
+ ["const"] = "keyword",
+ ["continue"] = "keyword",
+ ["debugger"] = "keyword",
+ ["default"] = "keyword",
+ ["delete"] = "keyword",
+ ["do"] = "keyword",
+ ["else"] = "keyword",
+ ["export"] = "keyword",
+ ["extends"] = "keyword",
+ ["finally"] = "keyword",
+ ["for"] = "keyword",
+ ["function"] = "keyword",
+ ["get"] = "keyword",
+ ["if"] = "keyword",
+ ["import"] = "keyword",
+ ["implements"] = "keyword",
+ ["in"] = "keyword",
+ ["instanceof"] = "keyword",
+ ["let"] = "keyword",
+ ["new"] = "keyword",
+ ["return"] = "keyword",
+ ["set"] = "keyword",
+ ["static"] = "keyword",
+ ["super"] = "keyword",
+ ["switch"] = "keyword",
+ ["throw"] = "keyword",
+ ["try"] = "keyword",
+ ["typeof"] = "keyword",
+ ["var"] = "keyword",
+ ["void"] = "keyword",
+ ["while"] = "keyword",
+ ["with"] = "keyword",
+ ["yield"] = "keyword",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["null"] = "literal",
+ ["undefined"] = "literal",
+ ["arguments"] = "keyword2",
+ ["Infinity"] = "keyword2",
+ ["NaN"] = "keyword2",
+ ["this"] = "keyword2",
+ },
+}
diff --git a/plugins/language_yaml.lua b/plugins/language_yaml.lua
new file mode 100644
index 0000000..40e19b6
--- /dev/null
+++ b/plugins/language_yaml.lua
@@ -0,0 +1,57 @@
+-- mod-version:1 -- lite-xl 1.16
+local syntax = require "core.syntax"
+
+syntax.add {
+ files = { "%.yml$", "%.yaml$" },
+ comment = "#",
+ patterns = {
+ { pattern = { "#", "\n"}, type = "comment" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = "%-?%.inf", type = "number" },
+ { pattern = "%.NaN", type = "number" },
+ {
+ pattern = "%&()%g+",
+ type = { "keyword", "literal" }
+ },
+ { pattern = "!%g+", type = "keyword" },
+ { pattern = "<<", type = "literal" },
+ {
+ pattern = "[%s]%*()[%w%d_]+",
+ type = { "keyword", "keyword2" }
+ },
+ {
+ pattern = "%*()[%w%d_]+",
+ type = { "keyword", "literal" }
+ },
+ {
+ pattern = "[%[%{]()%s*[%w%d]+%g+%s*():%s",
+ type = { "operator", "keyword2", "operator" }
+ },
+ {
+ pattern = "[%s][%w%d]+%g+%s*():%s",
+ type = { "keyword2", "operator" }
+ },
+ {
+ pattern = "[%w%d]+%g+%s*():%s",
+ type = { "literal", "operator" }
+ },
+ { pattern = "0%d+", type = "number" },
+ { pattern = "0x%x+", type = "number" },
+ { pattern = "[%+%-]?%d+[,%.eE:%+%d]*%d+", type = "number" },
+ { pattern = "[%*%|%!>%%]", type = "keyword" },
+ { pattern = "[%-:%?%*%{%}%[%]]", type = "operator" },
+ -- Everything else for keywords to work
+ {
+ pattern = "[%d%a_][%g_]*()[%]%},]",
+ type = { "string", "operator" }
+ },
+ { pattern = "[%d%a_][%g_]*", type = "string" },
+ },
+ symbols = {
+ ["true"] = "number",
+ ["false"] = "number",
+ ["y"] = "number",
+ ["n"] = "number"
+ }
+}
diff --git a/plugins/language_zig.lua b/plugins/language_zig.lua
index 2c098af..ed6f385 100644
--- a/plugins/language_zig.lua
+++ b/plugins/language_zig.lua
@@ -5,31 +5,38 @@ syntax.add {
files = { "%.zig$" },
comment = "//",
patterns = {
- { pattern = "//.-\n", type = "comment" },
- { pattern = "#!.-\n", type = "comment" },
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "'", "'", '\\' }, type = "string" },
- { pattern = "-?[iuf][%d_]+", type = "keyword2" },
- { pattern = "-?\\x[%x_]+", type = "number" },
- { pattern = "-?\\u{[%x_]+}", type = "number" },
- { pattern = "-?%d+[%d%.eE]*f?", type = "number" },
- { pattern = "-?%.?%d+f?", type = "number" },
- { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
- { pattern = "[%a_][%w_]*%f[(]", type = "function" },
- { pattern = "@?[%a_][%w_]*", type = "symbol" },
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = "\\\\.-\n", type = "string" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = "[iu][%d_]+", type = "keyword2" },
+ { pattern = "0b[01_]+", type = "number" },
+ { pattern = "0o[0-7_]+", type = "number" },
+ { pattern = "0x[%x_]+", type = "number" },
+ { pattern = "0x[%x_]+%.[%x_]*[pP][-+]?%d+", type = "number" },
+ { pattern = "0x[%x_]+%.[%x_]*", type = "number" },
+ { pattern = "0x%.[%x_]+[pP][-+]?%d+", type = "number" },
+ { pattern = "0x%.[%x_]+", type = "number" },
+ { pattern = "0x[%x_]+[pP][-+]?%d+", type = "number" },
+ { pattern = "0x[%x_]+", type = "number" },
+ { pattern = "%d[%d_]*%.[%d_]*[eE][-+]?%d+", type = "number" },
+ { pattern = "%d[%d_]*%.[%d_]*", type = "number" },
+ { pattern = "%d[%d_]*", type = "number" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&%.%?]", type = "operator" },
+ { pattern = "[%a_][%w_]*()%s*%(", type = {"function", "normal"} },
+ { pattern = "[A-Z][%w_]*", type = "keyword2" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ { pattern = "@()[%a_][%w_]*", type = {"operator", "function"} },
},
symbols = {
["fn"] = "keyword",
-
["asm"] = "keyword",
["volatile"] = "keyword",
-
["continue"] = "keyword",
["break"] = "keyword",
["switch"] = "keyword",
["for"] = "keyword",
["while"] = "keyword",
-
["var"] = "keyword",
["anytype"] = "keyword",
["const"] = "keyword",
@@ -42,146 +49,39 @@ syntax.add {
["errdefer"] = "keyword",
["align"] = "keyword",
["usingnamespace"] = "keyword",
-
["noasync"] = "keyword",
["async"] = "keyword",
["await"] = "keyword",
["cancel"] = "keyword",
["suspend"] = "keyword",
["resume"] = "keyword",
-
["threadlocal"] = "keyword",
-
["linksection"] = "keyword",
-
["callconv"] = "keyword",
-
["try"] = "keyword",
["catch"] = "keyword",
["orelse"] = "keyword",
["unreachable"] = "keyword",
- ["noreturn"] = "keyword",
["error"] = "keyword",
["if"] = "keyword",
["else"] = "keyword",
["return"] = "keyword",
["comptime"] = "keyword",
-
["stdcallcc"] = "keyword",
["ccc"] = "keyword",
["nakedcc"] = "keyword",
-
["and"] = "keyword",
["or"] = "keyword",
-
- -- std
- ["@import"] = "keyword",
- ["@cImport"] = "keyword",
-
- [ "@addWithOverflow" ] = "function",
- [ "@alignCast" ] = "function",
- [ "@alignOf" ] = "function",
- [ "@as" ] = "function",
- [ "@asyncCall" ] = "function",
- [ "@atomicLoad" ] = "function",
- [ "@atomicRmw" ] = "function",
- [ "@atomicStore" ] = "function",
- [ "@bitCast" ] = "function",
- [ "@bitOffsetOf" ] = "function",
- [ "@boolToInt" ] = "function",
- [ "@bitSizeOf" ] = "function",
- [ "@breakpoint" ] = "function",
- [ "@mulAdd" ] = "function",
- [ "@byteSwap" ] = "function",
- [ "@bitReverse" ] = "function",
- [ "@byteOffsetOf" ] = "function",
- [ "@call" ] = "function",
- [ "@cDefine" ] = "function",
- [ "@cImport" ] = "function",
- [ "@cInclude" ] = "function",
- [ "@clz" ] = "function",
- [ "@cmpxchgStrong" ] = "function",
- [ "@cmpxchgWeak" ] = "function",
- [ "@compileError" ] = "function",
- [ "@compileLog" ] = "function",
- [ "@ctz" ] = "function",
- [ "@cUndef" ] = "function",
- [ "@divExact" ] = "function",
- [ "@divFloor" ] = "function",
- [ "@divTrunc" ] = "function",
- [ "@embedFile" ] = "function",
- [ "@enumToInt" ] = "function",
- [ "@errorName" ] = "function",
- [ "@errorReturnTrace" ] = "function",
- [ "@errorToInt" ] = "function",
- [ "@errSetCast" ] = "function",
- [ "@export" ] = "function",
- [ "@fence" ] = "function",
- [ "@field" ] = "function",
- [ "@fieldParentPtr" ] = "function",
- [ "@floatCast" ] = "function",
- [ "@floatToInt" ] = "function",
- [ "@Frame" ] = "function",
- [ "@frame" ] = "function",
- [ "@frameAddress" ] = "function",
- [ "@frameSize" ] = "function",
- [ "@hasDecl" ] = "function",
- [ "@hasField" ] = "function",
- [ "@import" ] = "function",
- [ "@intCast" ] = "function",
- [ "@intToEnum" ] = "function",
- [ "@intToError" ] = "function",
- [ "@intToFloat" ] = "function",
- [ "@intToPtr" ] = "function",
- [ "@memcpy" ] = "function",
- [ "@memset" ] = "function",
- [ "@wasmMemorySize" ] = "function",
- [ "@wasmMemoryGrow" ] = "function",
- [ "@mod" ] = "function",
- [ "@mulWithOverflow" ] = "function",
- [ "@panic" ] = "function",
- [ "@popCount" ] = "function",
- [ "@ptrCast" ] = "function",
- [ "@ptrToInt" ] = "function",
- [ "@rem" ] = "function",
- [ "@returnAddress" ] = "function",
- [ "@setAlignStack" ] = "function",
- [ "@setCold" ] = "function",
- [ "@setEvalBranchQuota" ] = "function",
- [ "@setFloatMode" ] = "function",
- [ "@setRuntimeSafety" ] = "function",
- [ "@shlExact" ] = "function",
- [ "@shlWithOverflow" ] = "function",
- [ "@shrExact" ] = "function",
- [ "@shuffle" ] = "function",
- [ "@sizeOf" ] = "function",
- [ "@splat" ] = "function",
- [ "@src" ] = "function",
- [ "@sqrt" ] = "function",
- [ "@sin" ] = "function",
- [ "@cos" ] = "function",
- [ "@exp" ] = "function",
- [ "@exp2" ] = "function",
- [ "@log" ] = "function",
- [ "@log2" ] = "function",
- [ "@log10" ] = "function",
- [ "@fabs" ] = "function",
- [ "@floor" ] = "function",
- [ "@ceil" ] = "function",
- [ "@trunc" ] = "function",
- [ "@round" ] = "function",
- [ "@subWithOverflow" ] = "function",
- [ "@tagName" ] = "function",
- [ "@TagType" ] = "function",
- [ "@This" ] = "function",
- [ "@truncate" ] = "function",
- [ "@Type" ] = "function",
- [ "@typeInfo" ] = "function",
- [ "@typeName" ] = "function",
- [ "@TypeOf" ] = "function",
- [ "@unionInit" ] = "function",
+ ["struct"] = "keyword",
+ ["enum"] = "keyword",
+ ["union"] = "keyword",
+ ["opaque"] = "keyword",
-- types
+ ["f16"] = "keyword2",
+ ["f32"] = "keyword2",
+ ["f64"] = "keyword2",
+ ["f128"] = "keyword2",
["void"] = "keyword2",
["c_void"] = "keyword2",
["isize"] = "keyword2",
diff --git a/plugins/minimap.lua b/plugins/minimap.lua
index f58a609..ecae5eb 100644
--- a/plugins/minimap.lua
+++ b/plugins/minimap.lua
@@ -1,107 +1,112 @@
--- mod-version:1 -- lite-xl 1.16
--- Pulled from git@github.com:andsve/lite-plugins.git
-
-local command = require "core.command"
-local common = require "core.common"
-local config = require "core.config"
-local style = require "core.style"
-local DocView = require "core.docview"
+-- mod-version:1
+local command = require "core.command"
+local common = require "core.common"
+local config = require "core.config"
+local style = require "core.style"
+local DocView = require "core.docview"
-- General plugin settings
-config.minimap_enabled = true
-config.minimap_width = 100
-config.minimap_instant_scroll = false
+config.minimap_enabled = true
+config.minimap_width = 100
+config.minimap_instant_scroll = false
config.minimap_syntax_highlight = true
-config.minimap_scale = 1
-config.minimap_draw_background = true
+config.minimap_scale = 1
+
+-- how many spaces one tab is equivalent to
+config.minimap_tab_width = 4
+
+config.minimap_draw_background = true
-- Configure size for rendering each char in the minimap
-local char_height = 1 * SCALE * config.minimap_scale
+local char_height = 1 * SCALE * config.minimap_scale
local char_spacing = 0.8 * SCALE * config.minimap_scale
local line_spacing = 2 * SCALE * config.minimap_scale
-- 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)
- if not config.minimap_enabled then return prev_scrollbar_overlaps_point(self, x, y) end
+ if not config.minimap_enabled then
+ return prev_scrollbar_overlaps_point(self, x, y)
+ end
- local sx, sy, sw, sh = self:get_scrollbar_rect()
- return x >= sx and x < sx + sw and y >= sy and y < sy + sh
+ local sx, sy, sw, sh = self:get_scrollbar_rect()
+ return x >= sx and x < sx + sw and y >= sy and y < sy + sh
end
-- Helper function to determine if current file is too large to be shown fully inside the minimap area.
local function is_file_too_large(self)
- local line_count = #self.doc.lines
- local _, _, _, sh = self:get_scrollbar_rect()
+ local line_count = #self.doc.lines
+ local _, _, _, sh = self:get_scrollbar_rect()
- -- check if line count is too large to fit inside the minimap area
- local max_minmap_lines = math.floor(sh / line_spacing)
- return line_count > 1 and line_count > max_minmap_lines
+ -- check if line count is too large to fit inside the minimap area
+ local max_minmap_lines = math.floor(sh / line_spacing)
+ return line_count > 1 and line_count > max_minmap_lines
end
-- Overloaded with an extra check if the user clicked inside the minimap to automatically scroll to that line.
local prev_on_mouse_pressed = DocView.on_mouse_pressed
DocView.on_mouse_pressed = function(self, button, x, y, clicks)
- if not config.minimap_enabled then return prev_on_mouse_pressed(self, button, x, y, clicks) end
-
- -- check if user clicked in the minimap area and jump directly to that line
- -- unless they are actually trying to perform a drag
- local minimap_hit = self:scrollbar_overlaps_point(x, y)
- if minimap_hit then
- local line_count = #self.doc.lines
- local minimap_height = line_count * line_spacing
-
- -- check if line count is too large to fit inside the minimap area
- local is_too_large = is_file_too_large(self)
- if is_too_large then
- local _, _, _, sh = self:get_scrollbar_rect()
- minimap_height = sh
- end
-
- -- calc which line to jump to
- local dy = y - self.position.y
- local jump_to_line = math.floor((dy / minimap_height) * line_count) + 1
-
- local _, cy, _, cy2 = self:get_content_bounds()
- local lh = self:get_line_height()
- local visible_lines_count = math.max(1, (cy2 - cy) / lh)
- local visible_lines_start = math.max(1, math.floor(cy / lh))
-
- -- calc if user hit the currently visible area
- local hit_visible_area = true
- if is_too_large then
-
- local visible_height = visible_lines_count * line_spacing
- local scroll_pos = (visible_lines_start-1) / (line_count - visible_lines_count - 1)
- scroll_pos = math.min(1.0, scroll_pos) -- 0..1
- local visible_y = self.position.y + scroll_pos * (minimap_height - visible_height)
-
- local t = (line_count - visible_lines_start) / visible_lines_count
- if t <= 1 then
- visible_y = visible_y + visible_height * (1.0 - t)
- end
-
- if y < visible_y or y > visible_y + visible_height then
- hit_visible_area = false
- end
- else
-
- -- If the click is on the currently visible line numbers,
- -- ignore it since then they probably want to initiate a drag instead.
- if jump_to_line < visible_lines_start or jump_to_line > visible_lines_start + visible_lines_count then
- hit_visible_area = false
- end
- end
-
- -- if user didn't click on the visible area (ie not dragging), scroll accordingly
- if not hit_visible_area then
- self:scroll_to_line(jump_to_line, false, config.minimap_instant_scroll)
- return
- end
-
- end
-
- return prev_on_mouse_pressed(self, button, x, y, clicks)
+ if not config.minimap_enabled then
+ return prev_on_mouse_pressed(self, button, x, y, clicks)
+ end
+
+ -- check if user clicked in the minimap area and jump directly to that line
+ -- unless they are actually trying to perform a drag
+ local minimap_hit = self:scrollbar_overlaps_point(x, y)
+ if minimap_hit then
+ local line_count = #self.doc.lines
+ local minimap_height = line_count * line_spacing
+
+ -- check if line count is too large to fit inside the minimap area
+ local is_too_large = is_file_too_large(self)
+ if is_too_large then
+ local _, _, _, sh = self:get_scrollbar_rect()
+ minimap_height = sh
+ end
+
+ -- calc which line to jump to
+ local dy = y - self.position.y
+ local jump_to_line = math.floor((dy / minimap_height) * line_count) + 1
+
+ local _, cy, _, cy2 = self:get_content_bounds()
+ local lh = self:get_line_height()
+ local visible_lines_count = math.max(1, (cy2 - cy) / lh)
+ local visible_lines_start = math.max(1, math.floor(cy / lh))
+
+ -- calc if user hit the currently visible area
+ local hit_visible_area = true
+ if is_too_large then
+
+ local visible_height = visible_lines_count * line_spacing
+ local scroll_pos = (visible_lines_start - 1) /
+ (line_count - visible_lines_count - 1)
+ scroll_pos = math.min(1.0, scroll_pos) -- 0..1
+ local visible_y = self.position.y + scroll_pos *
+ (minimap_height - visible_height)
+
+ local t = (line_count - visible_lines_start) / visible_lines_count
+ if t <= 1 then visible_y = visible_y + visible_height * (1.0 - t) end
+
+ if y < visible_y or y > visible_y + visible_height then
+ hit_visible_area = false
+ end
+ else
+
+ -- If the click is on the currently visible line numbers,
+ -- ignore it since then they probably want to initiate a drag instead.
+ if jump_to_line < visible_lines_start or jump_to_line > visible_lines_start +
+ visible_lines_count then hit_visible_area = false end
+ end
+
+ -- if user didn't click on the visible area (ie not dragging), scroll accordingly
+ if not hit_visible_area then
+ self:scroll_to_line(jump_to_line, false, config.minimap_instant_scroll)
+ return
+ end
+
+ end
+
+ return prev_on_mouse_pressed(self, button, x, y, clicks)
end
-- Overloaded with pretty much the same logic as original DocView implementation,
@@ -109,190 +114,186 @@ end
-- since the "scrollbar" essentially represents the lines visible in the content view.
local prev_on_mouse_moved = DocView.on_mouse_moved
DocView.on_mouse_moved = function(self, x, y, dx, dy)
- if not config.minimap_enabled then return prev_on_mouse_moved(self, x, y, dx, dy) end
-
- if self.dragging_scrollbar then
- local line_count = #self.doc.lines
- local lh = self:get_line_height()
- local delta = lh / line_spacing * dy
-
- if is_file_too_large(self) then
- local _, sy, _, sh = self:get_scrollbar_rect()
- delta = (line_count * lh) / sh * dy
- end
-
- self.scroll.to.y = self.scroll.to.y + delta
- end
-
- -- we need to "hide" that the scrollbar is dragging so that View doesnt does its own scrolling logic
- local t = self.dragging_scrollbar
- self.dragging_scrollbar = false
- local r = prev_on_mouse_moved(self, x, y, dx, dy)
- self.dragging_scrollbar = t
- return r
+ if not config.minimap_enabled then
+ return prev_on_mouse_moved(self, x, y, dx, dy)
+ end
+
+ if self.dragging_scrollbar then
+ local line_count = #self.doc.lines
+ local lh = self:get_line_height()
+ local delta = lh / line_spacing * dy
+
+ if is_file_too_large(self) then
+ local _, sy, _, sh = self:get_scrollbar_rect()
+ delta = (line_count * lh) / sh * dy
+ end
+
+ self.scroll.to.y = self.scroll.to.y + delta
+ end
+
+ -- we need to "hide" that the scrollbar is dragging so that View doesnt does its own scrolling logic
+ local t = self.dragging_scrollbar
+ self.dragging_scrollbar = false
+ local r = prev_on_mouse_moved(self, x, y, dx, dy)
+ self.dragging_scrollbar = t
+ return r
end
-- Overloaded since we want the mouse to interact with the full size of the minimap area,
-- not juse the scrollbar.
local prev_get_scrollbar_rect = DocView.get_scrollbar_rect
-DocView.get_scrollbar_rect = function (self)
- if not config.minimap_enabled then return prev_get_scrollbar_rect(self) end
-
- return
- self.position.x + self.size.x - config.minimap_width * SCALE,
- self.position.y,
- config.minimap_width * SCALE,
- self.size.y
+DocView.get_scrollbar_rect = function(self)
+ if not config.minimap_enabled then return prev_get_scrollbar_rect(self) end
+
+ return self.position.x + self.size.x - config.minimap_width * SCALE,
+ self.position.y, config.minimap_width * SCALE, self.size.y
end
-- Overloaded so we can render the minimap in the "scrollbar area".
local prev_draw_scrollbar = DocView.draw_scrollbar
-DocView.draw_scrollbar = function (self)
- if not config.minimap_enabled then return prev_draw_scrollbar(self) end
-
- local x, y, w, h = self:get_scrollbar_rect()
-
- local highlight = self.hovered_scrollbar or self.dragging_scrollbar
- local visual_color = highlight and style.scrollbar2 or style.scrollbar
-
- local _, cy, _, cy2 = self:get_content_bounds()
- local lh = self:get_line_height()
- local visible_lines_count = math.max(1, (cy2 - cy) / lh)
- local visible_lines_start = math.max(1, math.floor(cy / lh))
- local scroller_height = visible_lines_count * line_spacing
- local line_count = #self.doc.lines
-
- local visible_y = self.position.y + (visible_lines_start-1) * line_spacing
-
-
- -- check if file is too large to fit inside the minimap area
- local max_minmap_lines = math.floor(h / line_spacing)
- local minimap_start_line = 1
- if is_file_too_large(self) then
-
- local scroll_pos = (visible_lines_start-1) / (line_count - visible_lines_count - 1)
- scroll_pos = math.min(1.0, scroll_pos) -- 0..1, procent of visual area scrolled
-
- local scroll_pos_pixels = scroll_pos * (h - scroller_height)
- visible_y = self.position.y + scroll_pos_pixels
-
- -- offset visible area if user is scrolling past end
- local t = (line_count - visible_lines_start) / visible_lines_count
- if t <= 1 then
- visible_y = visible_y + scroller_height * (1.0 - t)
- end
-
- minimap_start_line = visible_lines_start - math.floor(scroll_pos_pixels / line_spacing)
- minimap_start_line = math.max(1, math.min(minimap_start_line, line_count - max_minmap_lines))
- end
-
- if config.minimap_draw_background then
- renderer.draw_rect(x, y, w, h, style.minimap_background or style.background)
- end
- -- draw visual rect
- renderer.draw_rect(x, visible_y, w, scroller_height, visual_color)
-
- -- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind.
- local line_y = y
-
- -- when not using syntax highlighted rendering, just use the normal color but dim it 50%.
- local color = style.syntax["normal"]
- color = { color[1],color[2],color[3],color[4] * 0.5 }
-
- -- we try to "batch" characters so that they can be rendered as just one rectangle instead of one for each.
- local batch_width = 0
- local batch_start = x
- local minimap_cutoff_x = x + config.minimap_width * SCALE
-
- -- render lines with syntax highlighting
- if config.minimap_syntax_highlight then
-
- -- keep track of the highlight type, since this needs to break batches as well
- local batch_syntax_type = nil
-
- local function flush_batch(type)
- if batch_width > 0 then
- -- fetch and dim colors
- color = style.syntax[batch_syntax_type]
- color = { color[1], color[2], color[3], color[4] * 0.5 }
- renderer.draw_rect(batch_start, line_y, batch_width, char_height, color)
- end
- batch_syntax_type = type
- batch_start = batch_start + batch_width
- batch_width = 0
- end
-
- -- per line
- local endidx = minimap_start_line + max_minmap_lines
- endidx = math.min(endidx, line_count)
- for idx=minimap_start_line,endidx do
- batch_syntax_type = nil
- batch_start = x
- batch_width = 0
-
- -- per token
- for _, type, text in self.doc.highlighter:each_token(idx) do
- -- flush prev batch
- if not batch_syntax_type then batch_syntax_type = type end
- if batch_syntax_type ~= type then
- flush_batch(type)
- end
-
- -- per character
- for char in common.utf8_chars(text) do
- if char == " " or char == "\n" then
- flush_batch(type)
- batch_start = batch_start + char_spacing
- elseif batch_start + batch_width > minimap_cutoff_x then
- flush_batch(type)
- break
- else
- batch_width = batch_width + char_spacing
- end
-
- end
- end
- flush_batch(nil)
- line_y = line_y + line_spacing
- end
-
- else -- render lines without syntax highlighting
-
- local function flush_batch()
- if batch_width > 0 then
- renderer.draw_rect(batch_start, line_y, batch_width, char_height, color)
- end
- batch_start = batch_start + batch_width
- batch_width = 0
- end
-
- for idx=1,line_count-1 do
- batch_start = x
- batch_width = 0
-
- for char in common.utf8_chars(self.doc.lines[idx]) do
- if char == " " or char == "\n" then
- flush_batch()
- batch_start = batch_start + char_spacing
- elseif batch_start + batch_width > minimap_cutoff_x then
- flush_batch()
- else
- batch_width = batch_width + char_spacing
- end
- end
- flush_batch()
- line_y = line_y + line_spacing
- end
-
- end
+DocView.draw_scrollbar = function(self)
+ if not config.minimap_enabled then return prev_draw_scrollbar(self) end
+
+ local x, y, w, h = self:get_scrollbar_rect()
+
+ local highlight = self.hovered_scrollbar or self.dragging_scrollbar
+ local visual_color = highlight and style.scrollbar2 or style.scrollbar
+
+ local _, cy, _, cy2 = self:get_content_bounds()
+ local lh = self:get_line_height()
+ local visible_lines_count = math.max(1, (cy2 - cy) / lh)
+ local visible_lines_start = math.max(1, math.floor(cy / lh))
+ local scroller_height = visible_lines_count * line_spacing
+ local line_count = #self.doc.lines
+
+ local visible_y = self.position.y + (visible_lines_start - 1) * line_spacing
+
+ -- check if file is too large to fit inside the minimap area
+ local max_minmap_lines = math.floor(h / line_spacing)
+ local minimap_start_line = 1
+ if is_file_too_large(self) then
+
+ local scroll_pos = (visible_lines_start - 1) /
+ (line_count - visible_lines_count - 1)
+ scroll_pos = math.min(1.0, scroll_pos) -- 0..1, procent of visual area scrolled
+
+ local scroll_pos_pixels = scroll_pos * (h - scroller_height)
+ visible_y = self.position.y + scroll_pos_pixels
+
+ -- offset visible area if user is scrolling past end
+ local t = (line_count - visible_lines_start) / visible_lines_count
+ if t <= 1 then visible_y = visible_y + scroller_height * (1.0 - t) end
+
+ minimap_start_line = visible_lines_start -
+ math.floor(scroll_pos_pixels / line_spacing)
+ minimap_start_line = math.max(1, math.min(minimap_start_line,
+ line_count - max_minmap_lines))
+ end
+
+ if config.minimap_draw_background then
+ renderer.draw_rect(x, y, w, h, style.minimap_background or style.background)
+ end
+ -- draw visual rect
+ renderer.draw_rect(x, visible_y, w, scroller_height, visual_color)
+
+ -- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind.
+ local line_y = y
+
+ -- when not using syntax highlighted rendering, just use the normal color but dim it 50%.
+ local color = style.syntax["normal"]
+ color = {color[1], color[2], color[3], color[4] * 0.5}
+
+ -- we try to "batch" characters so that they can be rendered as just one rectangle instead of one for each.
+ local batch_width = 0
+ local batch_start = x
+ local minimap_cutoff_x = x + config.minimap_width * SCALE
+ local batch_syntax_type = nil
+ local function flush_batch(type)
+ local old_color = color
+ color = style.syntax[batch_syntax_type]
+ if config.minimap_syntax_highlight and color ~= nil then
+ -- fetch and dim colors
+ color = {color[1], color[2], color[3], color[4] * 0.5}
+ else
+ color = old_color
+ end
+ if batch_width > 0 then
+ renderer.draw_rect(batch_start, line_y, batch_width, char_height, color)
+ end
+ batch_syntax_type = type
+ batch_start = batch_start + batch_width
+ batch_width = 0
+ end
+
+ -- render lines with syntax highlighting
+ if config.minimap_syntax_highlight then
+
+ -- keep track of the highlight type, since this needs to break batches as well
+ batch_syntax_type = nil
+
+ -- per line
+ local endidx = minimap_start_line + max_minmap_lines
+ endidx = math.min(endidx, line_count)
+ for idx = minimap_start_line, endidx do
+ batch_syntax_type = nil
+ batch_start = x
+ batch_width = 0
+
+ -- per token
+ for _, type, text in self.doc.highlighter:each_token(idx) do
+ -- flush prev batch
+ if not batch_syntax_type then batch_syntax_type = type end
+ if batch_syntax_type ~= type then flush_batch(type) end
+
+ -- per character
+ for char in common.utf8_chars(text) do
+ if char == " " or char == "\n" then
+ flush_batch(type)
+ batch_start = batch_start + char_spacing
+ elseif char == " " then
+ flush_batch(type)
+ batch_start = batch_start + (char_spacing * config.minimap_tab_width)
+ elseif batch_start + batch_width > minimap_cutoff_x then
+ flush_batch(type)
+ break
+ else
+ batch_width = batch_width + char_spacing
+ end
+
+ end
+ end
+ flush_batch(nil)
+ line_y = line_y + line_spacing
+ end
+
+ else -- render lines without syntax highlighting
+ for idx = 1, line_count - 1 do
+ batch_start = x
+ batch_width = 0
+
+ for char in common.utf8_chars(self.doc.lines[idx]) do
+ if char == " " or char == "\n" then
+ flush_batch()
+ batch_start = batch_start + char_spacing
+ elseif batch_start + batch_width > minimap_cutoff_x then
+ flush_batch()
+ else
+ batch_width = batch_width + char_spacing
+ end
+ end
+ flush_batch()
+ line_y = line_y + line_spacing
+ end
+
+ end
end
command.add(nil, {
- ["minimap:toggle-visibility"] = function()
- config.minimap_enabled = not config.minimap_enabled
- end,
- ["minimap:toggle-syntax-highlighting"] = function()
- config.minimap_syntax_highlight = not config.minimap_syntax_highlight
- end,
+ ["minimap:toggle-visibility"] = function()
+ config.minimap_enabled = not config.minimap_enabled
+ end,
+ ["minimap:toggle-syntax-highlighting"] = function()
+ config.minimap_syntax_highlight = not config.minimap_syntax_highlight
+ end
})