aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-06-07 11:34:58 -0400
committerjgmdev <jgmdev@gmail.com>2022-06-07 11:34:58 -0400
commit26f595adf71540cd02243ebb41a520b01a752621 (patch)
tree8d3de71a8fd448d063aec10dc2341d4caede81e2 /plugins
parent980c2643c0acbcdccef62248f31010c94cb08cc8 (diff)
downloadlite-xl-plugins-26f595adf71540cd02243ebb41a520b01a752621.tar.gz
lite-xl-plugins-26f595adf71540cd02243ebb41a520b01a752621.zip
changed indentation to 2 spaces for consistency across the repo
Diffstat (limited to 'plugins')
-rw-r--r--plugins/dragdropselected.lua240
-rw-r--r--plugins/language_R.lua69
-rw-r--r--plugins/language_powershell.lua141
-rw-r--r--plugins/language_rivet.lua192
-rw-r--r--plugins/language_ruby.lua2
-rw-r--r--plugins/language_rust.lua122
-rw-r--r--plugins/language_wren.lua4
-rw-r--r--plugins/minimap.lua906
-rw-r--r--plugins/regexreplacepreview.lua215
-rw-r--r--plugins/select_colorscheme.lua16
-rw-r--r--plugins/themeselect.lua5
11 files changed, 961 insertions, 951 deletions
diff --git a/plugins/dragdropselected.lua b/plugins/dragdropselected.lua
index ec998aa..3c6583b 100644
--- a/plugins/dragdropselected.lua
+++ b/plugins/dragdropselected.lua
@@ -1,13 +1,13 @@
-- mod-version:3
--[[
- dragdropselected.lua
- provides basic drag and drop of selected text (in same document)
- version: 20200627_133351
- originally by SwissalpS
-
- TODO: use OS drag and drop events
- TODO: change mouse cursor when duplicating
- TODO: add dragging image
+ dragdropselected.lua
+ provides basic drag and drop of selected text (in same document)
+ version: 20200627_133351
+ originally by SwissalpS
+
+ TODO: use OS drag and drop events
+ TODO: change mouse cursor when duplicating
+ TODO: add dragging image
--]]
local DocView = require "core.docview"
local core = require "core"
@@ -22,16 +22,16 @@ local style = require "core.style"
-- iSelLine2 is line number where selection ends
-- iSelCol2 is column where selection ends
local function isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2)
- if iLine < iSelLine1 then return false end
- if iLine > iSelLine2 then return false end
- if (iLine == iSelLine1) and (iCol < iSelCol1) then return false end
- if (iLine == iSelLine2) and (iCol > iSelCol2) then return false end
- return true
+ if iLine < iSelLine1 then return false end
+ if iLine > iSelLine2 then return false end
+ if (iLine == iSelLine1) and (iCol < iSelCol1) then return false end
+ if (iLine == iSelLine2) and (iCol > iSelCol2) then return false end
+ return true
end -- isInSelection
-- distance between two points
local function distance(x1, y1, x2, y2)
- return math.sqrt(math.pow(x2-x1, 2)+math.pow(y2-y1, 2))
+ return math.sqrt(math.pow(x2-x1, 2)+math.pow(y2-y1, 2))
end
local min_drag = style.code_font:get_width(" ")
@@ -40,126 +40,138 @@ local min_drag = style.code_font:get_width(" ")
local on_mouse_moved = DocView.on_mouse_moved
function DocView:on_mouse_moved(x, y, ...)
- local sCursor = nil
-
- -- make sure we only act if previously on_mouse_pressed was in selection
- if self.bClickedIntoSelection and
- ( -- we are already dragging or we moved enough to start dragging
- not self.drag_start_loc or
- distance(self.drag_start_loc[1],self.drag_start_loc[2], x, y) > min_drag
- ) then
- self.drag_start_loc = nil
-
- -- show that we are dragging something
- sCursor = 'hand'
-
- -- calculate line and column for current mouse position
- local iLine, iCol = self:resolve_screen_position(x, y)
- local iSelLine1 = self.dragged_selection[1]
- local iSelCol1 = self.dragged_selection[2]
- local iSelLine2 = self.dragged_selection[3]
- local iSelCol2 = self.dragged_selection[4]
- self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
- if not isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2) then
- -- show cursor only if outside selection
- self.doc:add_selection(iLine, iCol)
- end
- -- update scroll position
- self:scroll_to_line(iLine, true)
- end -- if previously clicked into selection
+ local sCursor = nil
+
+ -- make sure we only act if previously on_mouse_pressed was in selection
+ if
+ self.bClickedIntoSelection
+ and
+ ( -- we are already dragging or we moved enough to start dragging
+ not self.drag_start_loc or
+ distance(self.drag_start_loc[1],self.drag_start_loc[2], x, y) > min_drag
+ )
+ then
+ self.drag_start_loc = nil
- -- hand off to 'old' on_mouse_moved()
- on_mouse_moved(self, x, y, ...)
- -- override cursor as needed
- if sCursor then self.cursor = sCursor end
+ -- show that we are dragging something
+ sCursor = 'hand'
+
+ -- calculate line and column for current mouse position
+ local iLine, iCol = self:resolve_screen_position(x, y)
+ local iSelLine1 = self.dragged_selection[1]
+ local iSelCol1 = self.dragged_selection[2]
+ local iSelLine2 = self.dragged_selection[3]
+ local iSelCol2 = self.dragged_selection[4]
+ self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
+ if not isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2) then
+ -- show cursor only if outside selection
+ self.doc:add_selection(iLine, iCol)
+ end
+ -- update scroll position
+ self:scroll_to_line(iLine, true)
+ end -- if previously clicked into selection
+
+ -- hand off to 'old' on_mouse_moved()
+ on_mouse_moved(self, x, y, ...)
+ -- override cursor as needed
+ if sCursor then self.cursor = sCursor end
end -- DocView:on_mouse_moved
-- override DocView:on_mouse_pressed
local on_mouse_pressed = DocView.on_mouse_pressed
function DocView:on_mouse_pressed(button, x, y, clicks)
- local caught = DocView.super.on_mouse_pressed(self, button, x, y, clicks)
- if caught then
- return caught
- end
- -- no need to proceed if not left button or has no selection
- if ('left' ~= button)
- or (not self.doc:has_selection())
- or (1 < clicks) then
- return on_mouse_pressed(self, button, x, y, clicks)
- end
- -- convert pixel coordinates to line and column coordinates
- local iLine, iCol = self:resolve_screen_position(x, y)
- -- get selection coordinates
- local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = self.doc:get_selection(true)
- -- set flag for on_mouse_released and on_mouse_moved() methods to detect dragging
- self.bClickedIntoSelection = isInSelection(iLine, iCol, iSelLine1, iSelCol1,
- iSelLine2, iSelCol2)
- if self.bClickedIntoSelection then
- self.drag_start_loc = { x, y }
- -- stash selection for inserting later
- self.sDraggedText = self.doc:get_text(self.doc:get_selection())
- self.dragged_selection = { iSelLine1, iSelCol1, iSelLine2, iSelCol2 }
- else
- self.bClickedIntoSelection = nil
- self.dragged_selection = nil
- -- let 'old' on_mouse_pressed() do whatever it needs to do
- on_mouse_pressed(self, button, x, y, clicks)
- end
+ local caught = DocView.super.on_mouse_pressed(self, button, x, y, clicks)
+ if caught then
+ return caught
+ end
+ -- no need to proceed if not left button or has no selection
+ if
+ ('left' ~= button)
+ or (not self.doc:has_selection())
+ or (1 < clicks)
+ then
+ return on_mouse_pressed(self, button, x, y, clicks)
+ end
+ -- convert pixel coordinates to line and column coordinates
+ local iLine, iCol = self:resolve_screen_position(x, y)
+ -- get selection coordinates
+ local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = self.doc:get_selection(true)
+ -- set flag for on_mouse_released and on_mouse_moved() methods to detect dragging
+ self.bClickedIntoSelection = isInSelection(iLine, iCol, iSelLine1, iSelCol1,
+ iSelLine2, iSelCol2)
+ if self.bClickedIntoSelection then
+ self.drag_start_loc = { x, y }
+ -- stash selection for inserting later
+ self.sDraggedText = self.doc:get_text(self.doc:get_selection())
+ self.dragged_selection = { iSelLine1, iSelCol1, iSelLine2, iSelCol2 }
+ else
+ self.bClickedIntoSelection = nil
+ self.dragged_selection = nil
+ -- let 'old' on_mouse_pressed() do whatever it needs to do
+ on_mouse_pressed(self, button, x, y, clicks)
+ end
end -- DocView:on_mouse_pressed
-- override DocView:on_mouse_released()
local on_mouse_released = DocView.on_mouse_released
function DocView:on_mouse_released(button, x, y)
- local iLine, iCol = self:resolve_screen_position(x, y)
- if self.bClickedIntoSelection then
- local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = table.unpack(self.dragged_selection)
- if not self.drag_start_loc
- and not isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2) then
- -- insert stashed selected text at current position
- if iLine < iSelLine1 or (iLine == iSelLine1 and iCol < iSelCol1) then
- -- delete first
- self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
- if not keymap.modkeys['ctrl'] then
- self.doc:delete_to(0)
- end
- self.doc:set_selection(iLine, iCol)
- self.doc:text_input(self.sDraggedText)
- else
- -- insert first
- self.doc:set_selection(iLine, iCol)
- self.doc:text_input(self.sDraggedText)
- self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
- if not keymap.modkeys['ctrl'] then
- self.doc:delete_to(0)
- end
- self.doc:set_selection(iLine, iCol)
- end
- elseif self.drag_start_loc then
- -- deselect only if the drag never happened
- self.doc:set_selection(iLine, iCol)
+ local iLine, iCol = self:resolve_screen_position(x, y)
+ if self.bClickedIntoSelection then
+ local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = table.unpack(self.dragged_selection)
+ if
+ not self.drag_start_loc
+ and
+ not isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2)
+ then
+ -- insert stashed selected text at current position
+ if iLine < iSelLine1 or (iLine == iSelLine1 and iCol < iSelCol1) then
+ -- delete first
+ self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
+ if not keymap.modkeys['ctrl'] then
+ self.doc:delete_to(0)
end
- -- unset stash and flag(s) TODO:
- self.sDraggedText = ''
- self.bClickedIntoSelection = nil
+ self.doc:set_selection(iLine, iCol)
+ self.doc:text_input(self.sDraggedText)
+ else
+ -- insert first
+ self.doc:set_selection(iLine, iCol)
+ self.doc:text_input(self.sDraggedText)
+ self.doc:set_selection(iSelLine1, iSelCol1, iSelLine2, iSelCol2)
+ if not keymap.modkeys['ctrl'] then
+ self.doc:delete_to(0)
+ end
+ self.doc:set_selection(iLine, iCol)
+ end
+ elseif self.drag_start_loc then
+ -- deselect only if the drag never happened
+ self.doc:set_selection(iLine, iCol)
end
+ -- unset stash and flag(s) TODO:
+ self.sDraggedText = ''
+ self.bClickedIntoSelection = nil
+ end
- -- hand over to old handler
- on_mouse_released(self, button, x, y)
+ -- hand over to old handler
+ on_mouse_released(self, button, x, y)
end -- DocView:on_mouse_released
-- override DocView:draw_caret()
local draw_caret = DocView.draw_caret
function DocView:draw_caret(x, y)
- if self.bClickedIntoSelection then
- local iLine, iCol = self:resolve_screen_position(x, y)
- -- don't show carets inside selections
- if isInSelection(iLine, iCol,
- self.dragged_selection[1], self.dragged_selection[2],
- self.dragged_selection[3], self.dragged_selection[4]) then
- return
- end
+ if self.bClickedIntoSelection then
+ local iLine, iCol = self:resolve_screen_position(x, y)
+ -- don't show carets inside selections
+ if
+ isInSelection(
+ iLine, iCol,
+ self.dragged_selection[1], self.dragged_selection[2],
+ self.dragged_selection[3], self.dragged_selection[4]
+ )
+ then
+ return
end
- draw_caret(self, x, y)
+ end
+ draw_caret(self, x, y)
end -- DocView:draw_caret()
diff --git a/plugins/language_R.lua b/plugins/language_R.lua
index a0bebed..afe3d1e 100644
--- a/plugins/language_R.lua
+++ b/plugins/language_R.lua
@@ -2,39 +2,38 @@
local syntax = require "core.syntax"
syntax.add{
- name = "R",
- files = {"%.r$", "%.rds$", "%.rda$", "%.rdata$", "%.R$"},
- comment = "#",
- patterns = {
- {pattern = {"#", "\n"}, type = "comment"},
- {pattern = {'"', '"'}, type = "string"},
- {pattern = {"'", "'"}, type = "string"},
- {pattern = "[%a_][%w_]*%f[(]", type = "function"},
- {pattern = "[%a_][%w_]*", type = "symbol"},
- {pattern = "[%+%-=/%*%^%%<>!|&]", type = "operator"},
- {pattern = "0x[%da-fA-F]+", type = "number"},
- {pattern = "-?%d+[%d%.eE]*", type = "number"},
- {pattern = "-?%.?%d+", type = "number"},
-
- },
- symbols = {
- ["TRUE"] = "literal",
- ["FALSE"] = "literal",
- ["NA"] = "literal",
- ["NULL"] = "literal",
- ["Inf"] = "literal",
- ["if"] = "keyword",
- ["else"] = "keyword",
- ["while"] = "keyword",
- ["function"] = "keyword",
- ["break"] = "keyword",
- ["next"] = "keyword",
- ["repeat"] = "keyword",
- ["in"] = "keyword",
- ["for"] = "keyword",
- ["NA_integer"] = "keyword",
- ["NA_complex"] = "keyword",
- ["NA_character"] = "keyword",
- ["NA_real"] = "keyword"
- }
+ name = "R",
+ files = {"%.r$", "%.rds$", "%.rda$", "%.rdata$", "%.R$"},
+ comment = "#",
+ patterns = {
+ {pattern = {"#", "\n"}, type = "comment"},
+ {pattern = {'"', '"'}, type = "string"},
+ {pattern = {"'", "'"}, type = "string"},
+ {pattern = "[%a_][%w_]*%f[(]", type = "function"},
+ {pattern = "[%a_][%w_]*", type = "symbol"},
+ {pattern = "[%+%-=/%*%^%%<>!|&]", type = "operator"},
+ {pattern = "0x[%da-fA-F]+", type = "number"},
+ {pattern = "-?%d+[%d%.eE]*", type = "number"},
+ {pattern = "-?%.?%d+", type = "number"},
+ },
+ symbols = {
+ ["TRUE"] = "literal",
+ ["FALSE"] = "literal",
+ ["NA"] = "literal",
+ ["NULL"] = "literal",
+ ["Inf"] = "literal",
+ ["if"] = "keyword",
+ ["else"] = "keyword",
+ ["while"] = "keyword",
+ ["function"] = "keyword",
+ ["break"] = "keyword",
+ ["next"] = "keyword",
+ ["repeat"] = "keyword",
+ ["in"] = "keyword",
+ ["for"] = "keyword",
+ ["NA_integer"] = "keyword",
+ ["NA_complex"] = "keyword",
+ ["NA_character"] = "keyword",
+ ["NA_real"] = "keyword"
+ }
}
diff --git a/plugins/language_powershell.lua b/plugins/language_powershell.lua
index 3350419..fdba844 100644
--- a/plugins/language_powershell.lua
+++ b/plugins/language_powershell.lua
@@ -2,73 +2,76 @@
local syntax = require "core.syntax"
syntax.add {
- name = "PowerShell",
- files = {"%.ps1$", "%.psm1$", "%.psd1$", "%.ps1xml$", "%.pssc$", "%.psrc$", "%.cdxml$"},
- comment = "#",
- patterns = {
- {pattern = "#.*\n", type = "comment"},
- {pattern = [[\.]], type = "normal"},
- {pattern = {'"', '"'}, type = "string"},
- {pattern = {"'", "'"}, type = "string"},
- {pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number"},
- {pattern = "[%+=/%*%^%%<>!~|&,:]+", type = "operator"},
- {pattern = "%f[%S]%-[%w%-_]+", type = "function"},
- {pattern = "[%u][%a]+[%-][%u][%a]+", type = "function"},
- {pattern = "${.*}", type = "symbol"},
- {pattern = "$[%a_@*][%w_]*", type = "keyword2"},
- {pattern = "$[%$][%a]+", type = "keyword2"},
- {pattern = "[%a_][%w_]*", type = "symbol"}
- },
- symbols = {
- ["if"] = "keyword",
- ["else"] = "keyword",
- ["elseif"] = "keyword",
- ["switch"] = "keyword",
- ["default"] = "keyword",
- ["function"] = "keyword",
- ["filter"] = "keyword",
- ["workflow"] = "keyword",
- ["configuration"] = "keyword",
- ["class"] = "keyword",
- ["enum"] = "keyword",
- ["Parameter"] = "keyword",
- ["ValidateScript"] = "keyword",
- ["CmdletBinding"] = "keyword",
- ["try"] = "keyword",
- ["catch"] = "keyword",
- ["finally"] = "keyword",
- ["throw"] = "keyword",
- ["while"] = "keyword",
- ["for"] = "keyword",
- ["do"] = "keyword",
- ["until"] = "keyword",
- ["break"] = "keyword",
- ["continue"] = "keyword",
- ["foreach"] = "keyword",
- ["in"] = "keyword",
- ["return"] = "keyword",
- ["where"] = "function",
- ["select"] = "function",
- ["filter"] = "keyword",
- ["in"] = "keyword",
- ["trap"] = "keyword",
- ["param"] = "keyword",
- ["data"] = "keyword",
- ["dynamicparam"] = "keyword",
- ["begin"] = "function",
- ["process"] = "function",
- ["end"] = "function",
- ["exit"] = "function",
- ["inlinescript"] = "function",
- ["parallel"] = "function",
- ["sequence"] = "function",
- ["true"] = "literal",
- ["false"] = "literal",
- ["TODO"] = "comment",
- ["FIXME"] = "comment",
- ["XXX"] = "comment",
- ["TBD"] = "comment",
- ["HACK"] = "comment",
- ["NOTE"] = "comment"
- }
+ name = "PowerShell",
+ files = {
+ "%.ps1$", "%.psm1$", "%.psd1$", "%.ps1xml$",
+ "%.pssc$", "%.psrc$", "%.cdxml$"
+ },
+ comment = "#",
+ patterns = {
+ {pattern = "#.*\n", type = "comment"},
+ {pattern = [[\.]], type = "normal"},
+ {pattern = {'"', '"'}, type = "string"},
+ {pattern = {"'", "'"}, type = "string"},
+ {pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number"},
+ {pattern = "[%+=/%*%^%%<>!~|&,:]+", type = "operator"},
+ {pattern = "%f[%S]%-[%w%-_]+", type = "function"},
+ {pattern = "[%u][%a]+[%-][%u][%a]+", type = "function"},
+ {pattern = "${.*}", type = "symbol"},
+ {pattern = "$[%a_@*][%w_]*", type = "keyword2"},
+ {pattern = "$[%$][%a]+", type = "keyword2"},
+ {pattern = "[%a_][%w_]*", type = "symbol"}
+ },
+ symbols = {
+ ["if"] = "keyword",
+ ["else"] = "keyword",
+ ["elseif"] = "keyword",
+ ["switch"] = "keyword",
+ ["default"] = "keyword",
+ ["function"] = "keyword",
+ ["filter"] = "keyword",
+ ["workflow"] = "keyword",
+ ["configuration"] = "keyword",
+ ["class"] = "keyword",
+ ["enum"] = "keyword",
+ ["Parameter"] = "keyword",
+ ["ValidateScript"] = "keyword",
+ ["CmdletBinding"] = "keyword",
+ ["try"] = "keyword",
+ ["catch"] = "keyword",
+ ["finally"] = "keyword",
+ ["throw"] = "keyword",
+ ["while"] = "keyword",
+ ["for"] = "keyword",
+ ["do"] = "keyword",
+ ["until"] = "keyword",
+ ["break"] = "keyword",
+ ["continue"] = "keyword",
+ ["foreach"] = "keyword",
+ ["in"] = "keyword",
+ ["return"] = "keyword",
+ ["where"] = "function",
+ ["select"] = "function",
+ ["filter"] = "keyword",
+ ["in"] = "keyword",
+ ["trap"] = "keyword",
+ ["param"] = "keyword",
+ ["data"] = "keyword",
+ ["dynamicparam"] = "keyword",
+ ["begin"] = "function",
+ ["process"] = "function",
+ ["end"] = "function",
+ ["exit"] = "function",
+ ["inlinescript"] = "function",
+ ["parallel"] = "function",
+ ["sequence"] = "function",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["TODO"] = "comment",
+ ["FIXME"] = "comment",
+ ["XXX"] = "comment",
+ ["TBD"] = "comment",
+ ["HACK"] = "comment",
+ ["NOTE"] = "comment"
+ }
}
diff --git a/plugins/language_rivet.lua b/plugins/language_rivet.lua
index 30d5e4e..574b368 100644
--- a/plugins/language_rivet.lua
+++ b/plugins/language_rivet.lua
@@ -6,108 +6,108 @@
local syntax = require "core.syntax"
syntax.add {
- name = "Rivet",
- files = {"%.ri$"},
- comment = "//",
- block_comment = {"/*", "*/"},
- patterns = {
- {pattern = "//.-\n", type = "comment"},
- {pattern = {"/%*", "%*/"}, type = "comment"},
- {pattern = {'[rb]?"', '"', "\\"}, type = "string"},
- {pattern = {"[b]?'", "'", '\\' }, type = "string"},
- {pattern = "0b[01_]+", type = "number"},
- {pattern = "0o[0-7_]+", 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 = "-?%.?%d+", type = "number"},
- {pattern = "[%+%-=/%*%^%%<>!~|&%.%?]", type = "operator"},
- {pattern = "[%a_][%w_]*::", type = "keyword2"},
- {pattern = "[A-Z][%w_]*", type = "keyword2"}, -- types and constants
- {pattern = "[%a_][%w_]*%f[(]", type = "function"},
- {pattern = "[%a_][%w_]*!%f[(]", type = "keyword2"},
- {pattern = "[%a_][%w_]*", type = "symbol"},
- {pattern = {"#%[", "%]"}, type = "keyword"},
- {pattern = "%$%s?[%a_][%w_]*", type = "keyword2"},
- {pattern = "%@%s?[%a_][%w_]*", type = "keyword2"},
- },
- symbols = {
- ["extern"] = "keyword",
- ["use"] = "keyword",
+ name = "Rivet",
+ files = {"%.ri$"},
+ comment = "//",
+ block_comment = {"/*", "*/"},
+ patterns = {
+ {pattern = "//.-\n", type = "comment"},
+ {pattern = {"/%*", "%*/"}, type = "comment"},
+ {pattern = {'[rb]?"', '"', "\\"}, type = "string"},
+ {pattern = {"[b]?'", "'", '\\' }, type = "string"},
+ {pattern = "0b[01_]+", type = "number"},
+ {pattern = "0o[0-7_]+", 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 = "-?%.?%d+", type = "number"},
+ {pattern = "[%+%-=/%*%^%%<>!~|&%.%?]", type = "operator"},
+ {pattern = "[%a_][%w_]*::", type = "keyword2"},
+ {pattern = "[A-Z][%w_]*", type = "keyword2"}, -- types and constants
+ {pattern = "[%a_][%w_]*%f[(]", type = "function"},
+ {pattern = "[%a_][%w_]*!%f[(]", type = "keyword2"},
+ {pattern = "[%a_][%w_]*", type = "symbol"},
+ {pattern = {"#%[", "%]"}, type = "keyword"},
+ {pattern = "%$%s?[%a_][%w_]*", type = "keyword2"},
+ {pattern = "%@%s?[%a_][%w_]*", type = "keyword2"},
+ },
+ symbols = {
+ ["extern"] = "keyword",
+ ["use"] = "keyword",
- ["pub"] = "keyword",
- ["as"] = "keyword",
+ ["pub"] = "keyword",
+ ["as"] = "keyword",
- ["pkg"] = "keyword",
- ["mod"] = "keyword",
- ["const"] = "keyword",
- ["static"] = "keyword",
- ["trait"] = "keyword",
- ["struct"] = "keyword",
- ["union"] = "keyword",
- ["type"] = "keyword",
- ["errtype"] = "keyword",
- ["enum"] = "keyword",
- ["fn"] = "keyword",
- ["test"] = "keyword",
- ["extend"] = "keyword",
+ ["pkg"] = "keyword",
+ ["mod"] = "keyword",
+ ["const"] = "keyword",
+ ["static"] = "keyword",
+ ["trait"] = "keyword",
+ ["struct"] = "keyword",
+ ["union"] = "keyword",
+ ["type"] = "keyword",
+ ["errtype"] = "keyword",
+ ["enum"] = "keyword",
+ ["fn"] = "keyword",
+ ["test"] = "keyword",
+ ["extend"] = "keyword",
- -- comptime `if` and `match` expr
- ["$if"] = "keyword",
- ["$elif"] = "keyword",
- ["$else"] = "keyword",
- ["$match"] = "keyword",
+ -- comptime `if` and `match` expr
+ ["$if"] = "keyword",
+ ["$elif"] = "keyword",
+ ["$else"] = "keyword",
+ ["$match"] = "keyword",
- ["if"] = "keyword",
- ["elif"] = "keyword",
- ["else"] = "keyword",
- ["match"] = "keyword",
- ["while"] = "keyword",
- ["for"] = "keyword",
+ ["if"] = "keyword",
+ ["elif"] = "keyword",
+ ["else"] = "keyword",
+ ["match"] = "keyword",
+ ["while"] = "keyword",
+ ["for"] = "keyword",
- ["break"] = "keyword",
- ["continue"] = "keyword",
- ["return"] = "keyword",
- ["raise"] = "keyword",
+ ["break"] = "keyword",
+ ["continue"] = "keyword",
+ ["return"] = "keyword",
+ ["raise"] = "keyword",
- ["let"] = "keyword",
- ["mut"] = "keyword",
- ["unsafe"] = "keyword",
- ["goto"] = "keyword",
- ["orelse"] = "keyword",
- ["catch"] = "keyword",
- ["cast"] = "keyword",
- ["or"] = "keyword",
- ["and"] = "keyword",
- ["is"] = "keyword",
- ["in"] = "keyword",
+ ["let"] = "keyword",
+ ["mut"] = "keyword",
+ ["unsafe"] = "keyword",
+ ["goto"] = "keyword",
+ ["orelse"] = "keyword",
+ ["catch"] = "keyword",
+ ["cast"] = "keyword",
+ ["or"] = "keyword",
+ ["and"] = "keyword",
+ ["is"] = "keyword",
+ ["in"] = "keyword",
- -- types
- ["c_void"] = "keyword2",
- ["void"] = "keyword2",
- ["bool"] = "keyword2",
- ["i8"] = "keyword2",
- ["i16"] = "keyword2",
- ["i32"] = "keyword2",
- ["i64"] = "keyword2",
- ["u8"] = "keyword2",
- ["u16"] = "keyword2",
- ["u32"] = "keyword2",
- ["u64"] = "keyword2",
- ["f32"] = "keyword2",
- ["f64"] = "keyword2",
- ["rune"] = "keyword2",
- ["isize"] = "keyword2",
- ["usize"] = "keyword2",
- ["str"] = "keyword2",
- ["Self"] = "keyword2",
+ -- types
+ ["c_void"] = "keyword2",
+ ["void"] = "keyword2",
+ ["bool"] = "keyword2",
+ ["i8"] = "keyword2",
+ ["i16"] = "keyword2",
+ ["i32"] = "keyword2",
+ ["i64"] = "keyword2",
+ ["u8"] = "keyword2",
+ ["u16"] = "keyword2",
+ ["u32"] = "keyword2",
+ ["u64"] = "keyword2",
+ ["f32"] = "keyword2",
+ ["f64"] = "keyword2",
+ ["rune"] = "keyword2",
+ ["isize"] = "keyword2",
+ ["usize"] = "keyword2",
+ ["str"] = "keyword2",
+ ["Self"] = "keyword2",
- -- literals
- ["base"] = "literal",
- ["self"] = "literal",
- ["true"] = "literal",
- ["false"] = "literal",
- ["none"] = "literal"
- }
+ -- literals
+ ["base"] = "literal",
+ ["self"] = "literal",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["none"] = "literal"
+ }
}
diff --git a/plugins/language_ruby.lua b/plugins/language_ruby.lua
index af700c2..30f2be1 100644
--- a/plugins/language_ruby.lua
+++ b/plugins/language_ruby.lua
@@ -23,7 +23,6 @@ syntax.add {
},
symbols = {
["nil"] = "literal",
- ["end"] = "literal",
["true"] = "literal",
["false"] = "literal",
["private"] = "keyword",
@@ -63,7 +62,6 @@ syntax.add {
["self"] = "keyword",
["super"] = "keyword",
["then"] = "keyword",
- ["true"] = "keyword",
["undef"] = "keyword",
["unless"] = "keyword",
["until"] = "keyword",
diff --git a/plugins/language_rust.lua b/plugins/language_rust.lua
index 44a9980..848e8b1 100644
--- a/plugins/language_rust.lua
+++ b/plugins/language_rust.lua
@@ -23,68 +23,66 @@ syntax.add {
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
- ["as"] = "keyword",
- ["async"] = "keyword",
- ["await"] = "keyword",
- ["break"] = "keyword",
- ["const"] = "keyword",
- ["continue"] = "keyword",
- ["crate"] = "keyword",
- ["dyn"] = "keyword",
- ["else"] = "keyword",
- ["enum"] = "keyword",
- ["extern"] = "keyword",
- ["false"] = "keyword",
- ["fn"] = "keyword",
- ["for"] = "keyword",
- ["if"] = "keyword",
- ["impl"] = "keyword",
- ["in"] = "keyword",
- ["let"] = "keyword",
- ["loop"] = "keyword",
- ["match"] = "keyword",
- ["mod"] = "keyword",
- ["move"] = "keyword",
- ["mut"] = "keyword",
- ["pub"] = "keyword",
- ["ref"] = "keyword",
- ["return"] = "keyword",
- ["Self"] = "keyword",
- ["self"] = "keyword",
- ["static"] = "keyword",
- ["struct"] = "keyword",
- ["super"] = "keyword",
- ["trait"] = "keyword",
- ["true"] = "keyword",
- ["type"] = "keyword",
- ["unsafe"] = "keyword",
- ["use"] = "keyword",
- ["where"] = "keyword",
- ["while"] = "keyword",
- ["i32"] = "keyword2",
- ["i64"] = "keyword2",
- ["i128"] = "keyword2",
- ["i16"] = "keyword2",
- ["i8"] = "keyword2",
- ["u8"] = "keyword2",
- ["u16"] = "keyword2",
- ["u32"] = "keyword2",
- ["u64"] = "keyword2",
- ["usize"] = "keyword2",
- ["isize"] = "keyword2",
- ["f32"] = "keyword2",
- ["f64"] = "keyword2",
- ["f128"] = "keyword2",
- ["String"] = "keyword2",
- ["char"] = "keyword2",
- ["str"] = "keyword2",
- ["bool"] = "keyword2",
- ["true"] = "literal",
- ["false"] = "literal",
- ["None"] = "literal",
- ["Some"] = "literal",
- ["Option"] = "literal",
- ["Result"] = "literal",
+ ["as"] = "keyword",
+ ["async"] = "keyword",
+ ["await"] = "keyword",
+ ["break"] = "keyword",
+ ["const"] = "keyword",
+ ["continue"] = "keyword",
+ ["crate"] = "keyword",
+ ["dyn"] = "keyword",
+ ["else"] = "keyword",
+ ["enum"] = "keyword",
+ ["extern"] = "keyword",
+ ["fn"] = "keyword",
+ ["for"] = "keyword",
+ ["if"] = "keyword",
+ ["impl"] = "keyword",
+ ["in"] = "keyword",
+ ["let"] = "keyword",
+ ["loop"] = "keyword",
+ ["match"] = "keyword",
+ ["mod"] = "keyword",
+ ["move"] = "keyword",
+ ["mut"] = "keyword",
+ ["pub"] = "keyword",
+ ["ref"] = "keyword",
+ ["return"] = "keyword",
+ ["Self"] = "keyword",
+ ["self"] = "keyword",
+ ["static"] = "keyword",
+ ["struct"] = "keyword",
+ ["super"] = "keyword",
+ ["trait"] = "keyword",
+ ["type"] = "keyword",
+ ["unsafe"] = "keyword",
+ ["use"] = "keyword",
+ ["where"] = "keyword",
+ ["while"] = "keyword",
+ ["i32"] = "keyword2",
+ ["i64"] = "keyword2",
+ ["i128"] = "keyword2",
+ ["i16"] = "keyword2",
+ ["i8"] = "keyword2",
+ ["u8"] = "keyword2",
+ ["u16"] = "keyword2",
+ ["u32"] = "keyword2",
+ ["u64"] = "keyword2",
+ ["usize"] = "keyword2",
+ ["isize"] = "keyword2",
+ ["f32"] = "keyword2",
+ ["f64"] = "keyword2",
+ ["f128"] = "keyword2",
+ ["String"] = "keyword2",
+ ["char"] = "keyword2",
+ ["str"] = "keyword2",
+ ["bool"] = "keyword2",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["None"] = "literal",
+ ["Some"] = "literal",
+ ["Option"] = "literal",
+ ["Result"] = "literal",
},
}
diff --git a/plugins/language_wren.lua b/plugins/language_wren.lua
index 42f4fbd..2022dbf 100644
--- a/plugins/language_wren.lua
+++ b/plugins/language_wren.lua
@@ -22,19 +22,15 @@ syntax.add {
["class"] = "keyword",
["construct"] = "keyword",
["else"] = "keyword",
- ["false"] = "keyword",
["for"] = "keyword",
["foreign"] = "keyword",
["if"] = "keyword",
["import"] = "keyword",
["in"] = "keyword",
["is"] = "keyword",
- ["null"] = "keyword",
["return"] = "keyword",
["static"] = "keyword",
["super"] = "keyword",
- ["this"] = "keyword",
- ["true"] = "keyword",
["var"] = "keyword",
["while"] = "keyword",
["this"] = "keyword2",
diff --git a/plugins/minimap.lua b/plugins/minimap.lua
index 37cbda7..f2638c8 100644
--- a/plugins/minimap.lua
+++ b/plugins/minimap.lua
@@ -22,159 +22,159 @@ local Object = require "core.object"
-- General plugin settings
config.plugins.minimap = common.merge({
- enabled = true,
- width = 100,
- instant_scroll = false,
- syntax_highlight = true,
- scale = 1,
- -- hide on small docs (can be true, false or min number of lines)
- avoid_small_docs = false,
- -- how many spaces one tab is equivalent to
- tab_width = 4,
- draw_background = true,
- -- you can override these colors
- selection_color = nil,
- caret_color = nil,
- -- If other plugins provide per-line highlights,
- -- this controls the placement. (e.g. gitdiff_highlight)
- highlight_align = 'left',
- highlight_width = 3,
- gutter_width = 5,
- -- The config specification used by the settings gui
- config_spec = {
- name = "Mini Map",
- {
- label = "Enabled",
- description = "Activate the minimap by default.",
- path = "enabled",
- type = "toggle",
- default = true
- },
- {
- label = "Width",
- description = "Width of the minimap in pixels.",
- path = "width",
- type = "number",
- default = 100,
- min = 50,
- max = 1000
- },
- {
- label = "Instant Scroll",
- description = "When enabled disables the scrolling animation.",
- path = "instant_scroll",
- type = "toggle",
- default = false
- },
- {
- label = "Syntax Highlighting",
- description = "Disable to improve performance.",
- path = "syntax_highlight",
- type = "toggle",
- default = true
- },
- {
- label = "Scale",
- description = "Size of the minimap using a scaling factor.",
- path = "scale",
- type = "number",
- default = 1,
- min = 0.5,
- max = 10,
- step = 0.1
- },
- {
- label = "Hide for small Docs",
- description = "Hide the minimap when a Doc is small enough.",
- path = "avoid_small_docs",
- type = "toggle",
- default = false
- },
- {
- label = "Small Docs definition",
- description = "Size of a Doc to be considered small. Use 0 to automatically decide.",
- path = "avoid_small_docs_len",
- type = "number",
- default = 0,
- min = 0,
- on_apply = function(value)
- if value == 0 then
- config.plugins.minimap.avoid_small_docs = true
- else
- config.plugins.minimap.avoid_small_docs = value
- end
- end
- },
- {
- label = "Tabs Width",
- description = "The amount of spaces that represent a tab.",
- path = "tab_width",
- type = "number",
- default = 4,
- min = 1,
- max = 8
- },
- {
- label = "Draw Background",
- description = "When disabled makes the minimap transparent.",
- path = "draw_background",
- type = "toggle",
- default = true
- },
- {
- label = "Selection Color",
- description = "Background color of selected text in html notation eg: #FFFFFF. Leave empty to use default.",
- path = "selection_color_html",
- type = "string",
- on_apply = function(value)
- if value and value:match("#%x%x%x%x%x%x") then
- config.plugins.minimap.selection_color = { common.color(value) }
- else
- config.plugins.minimap.selection_color = nil
- end
- end
- },
- {
- label = "Caret Color",
- description = "Background color of active line in html notation eg: #FFFFFF. Leave empty to use default.",
- path = "caret_color_html",
- type = "string",
- on_apply = function(value)
- if value and value:match("#%x%x%x%x%x%x") then
- config.plugins.minimap.caret_color = { common.color(value) }
- else
- config.plugins.minimap.caret_color = nil
- end
- end
- },
- {
- label = "Highlight Alignment",
- path = "highlight_align",
- type = "selection",
- default = "left",
- values = {
- {"Left", "left"},
- {"Right", "right"}
- }
- },
- {
- label = "Highlight Width",
- path = "highlight_width",
- type = "number",
- default = 3,
- min = 0,
- max = 50
- },
- {
- label = "Gutter Width",
- description = "Left padding of the minimap.",
- path = "gutter_width",
- type = "number",
- default = 5,
- min = 0,
- max = 50
- },
- }
+ enabled = true,
+ width = 100,
+ instant_scroll = false,
+ syntax_highlight = true,
+ scale = 1,
+ -- hide on small docs (can be true, false or min number of lines)
+ avoid_small_docs = false,
+ -- how many spaces one tab is equivalent to
+ tab_width = 4,
+ draw_background = true,
+ -- you can override these colors
+ selection_color = nil,
+ caret_color = nil,
+ -- If other plugins provide per-line highlights,
+ -- this controls the placement. (e.g. gitdiff_highlight)
+ highlight_align = 'left',
+ highlight_width = 3,
+ gutter_width = 5,
+ -- The config specification used by the settings gui
+ config_spec = {
+ name = "Mini Map",
+ {
+ label = "Enabled",
+ description = "Activate the minimap by default.",
+ path = "enabled",
+ type = "toggle",
+ default = true
+ },
+ {
+ label = "Width",
+ description = "Width of the minimap in pixels.",
+ path = "width",
+ type = "number",
+ default = 100,
+ min = 50,
+ max = 1000
+ },
+ {
+ label = "Instant Scroll",
+ description = "When enabled disables the scrolling animation.",
+ path = "instant_scroll",
+ type = "toggle",
+ default = false
+ },
+ {
+ label = "Syntax Highlighting",
+ description = "Disable to improve performance.",
+ path = "syntax_highlight",
+ type = "toggle",
+ default = true
+ },
+ {
+ label = "Scale",
+ description = "Size of the minimap using a scaling factor.",
+ path = "scale",
+ type = "number",
+ default = 1,
+ min = 0.5,
+ max = 10,
+ step = 0.1
+ },
+ {
+ label = "Hide for small Docs",
+ description = "Hide the minimap when a Doc is small enough.",
+ path = "avoid_small_docs",
+ type = "toggle",
+ default = false
+ },
+ {
+ label = "Small Docs definition",
+ description = "Size of a Doc to be considered small. Use 0 to automatically decide.",
+ path = "avoid_small_docs_len",
+ type = "number",
+ default = 0,
+ min = 0,
+ on_apply = function(value)
+ if value == 0 then
+ config.plugins.minimap.avoid_small_docs = true
+ else
+ config.plugins.minimap.avoid_small_docs = value
+ end
+ end
+ },
+ {
+ label = "Tabs Width",
+ description = "The amount of spaces that represent a tab.",
+ path = "tab_width",
+ type = "number",
+ default = 4,
+ min = 1,
+ max = 8
+ },
+ {
+ label = "Draw Background",
+ description = "When disabled makes the minimap transparent.",
+ path = "draw_background",
+ type = "toggle",
+ default = true
+ },
+ {
+ label = "Selection Color",
+ description = "Background color of selected text in html notation eg: #FFFFFF. Leave empty to use default.",
+ path = "selection_color_html",
+ type = "string",
+ on_apply = function(value)
+ if value and value:match("#%x%x%x%x%x%x") then
+ config.plugins.minimap.selection_color = { common.color(value) }
+ else
+ config.plugins.minimap.selection_color = nil
+ end
+ end
+ },
+ {
+ label = "Caret Color",
+ description = "Background color of active line in html notation eg: #FFFFFF. Leave empty to use default.",
+ path = "caret_color_html",
+ type = "string",
+ on_apply = function(value)
+ if value and value:match("#%x%x%x%x%x%x") then
+ config.plugins.minimap.caret_color = { common.color(value) }
+ else
+ config.plugins.minimap.caret_color = nil
+ end
+ end
+ },
+ {
+ label = "Highlight Alignment",
+ path = "highlight_align",
+ type = "selection",
+ default = "left",
+ values = {
+ {"Left", "left"},
+ {"Right", "right"}
+ }
+ },
+ {
+ label = "Highlight Width",
+ path = "highlight_width",
+ type = "number",
+ default = 3,
+ min = 0,
+ max = 50
+ },
+ {
+ label = "Gutter Width",
+ description = "Left padding of the minimap.",
+ path = "gutter_width",
+ type = "number",
+ default = 5,
+ min = 0,
+ max = 50
+ },
+ }
}, config.plugins.minimap)
-- Configure size for rendering each char in the minimap
@@ -188,118 +188,118 @@ function MiniMap:new()
end
function MiniMap:line_highlight_color(line_index)
- -- other plugins can override this, and return a color
+ -- other plugins can override this, and return a color
end
local minimap = MiniMap()
local per_docview = setmetatable({}, { __mode = "k" })
local function show_minimap(docview)
- if not docview:is(DocView) then return false end
- if
- not config.plugins.minimap.enabled
- or not docview:is(DocView)
- or per_docview[docview] == false
- then
- return false
- end
- if config.plugins.minimap.avoid_small_docs then
- local last_line = #docview.doc.lines
- if type(config.plugins.minimap.avoid_small_docs) == "number" then
- return last_line > config.plugins.minimap.avoid_small_docs
- else
- local _, y = docview:get_line_screen_position(last_line, docview.doc.lines[last_line])
- y = y + docview.scroll.y - docview.position.y + docview:get_line_height()
- return y > docview.size.y
- end
- end
- return true
+ if not docview:is(DocView) then return false end
+ if
+ not config.plugins.minimap.enabled
+ or not docview:is(DocView)
+ or per_docview[docview] == false
+ then
+ return false
+ end
+ if config.plugins.minimap.avoid_small_docs then
+ local last_line = #docview.doc.lines
+ if type(config.plugins.minimap.avoid_small_docs) == "number" then
+ return last_line > config.plugins.minimap.avoid_small_docs
+ else
+ local _, y = docview:get_line_screen_position(last_line, docview.doc.lines[last_line])
+ y = y + docview.scroll.y - docview.position.y + docview:get_line_height()
+ return y > docview.size.y
+ end
+ end
+ return true
end
-- 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 show_minimap(self) then
- return prev_scrollbar_overlaps_point(self, x, y)
- end
+ if not show_minimap(self) 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 show_minimap(self) 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.plugins.minimap.instant_scroll)
- end
-
- end
-
- return prev_on_mouse_pressed(self, button, x, y, clicks)
+ if not show_minimap(self) 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.plugins.minimap.instant_scroll)
+ end
+
+ end
+
+ return prev_on_mouse_pressed(self, button, x, y, clicks)
end
-- Overloaded with pretty much the same logic as original DocView implementation,
@@ -307,244 +307,244 @@ 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 show_minimap(self) 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 show_minimap(self) 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 show_minimap(self) then return prev_get_scrollbar_rect(self) end
+ if not show_minimap(self) then return prev_get_scrollbar_rect(self) end
- return self.position.x + self.size.x - config.plugins.minimap.width * SCALE,
- self.position.y, config.plugins.minimap.width * SCALE, self.size.y
+ return self.position.x + self.size.x - config.plugins.minimap.width * SCALE,
+ self.position.y, config.plugins.minimap.width * SCALE, self.size.y
end
local prev_get_scrollbar_track_rect = DocView.get_scrollbar_track_rect
DocView.get_scrollbar_track_rect = function(self)
- if not show_minimap(self) then return prev_get_scrollbar_track_rect(self) end
+ if not show_minimap(self) then return prev_get_scrollbar_track_rect(self) end
- return self.position.x + self.size.x - config.plugins.minimap.width * SCALE,
- self.position.y, config.plugins.minimap.width * SCALE, self.size.y
+ return self.position.x + self.size.x - config.plugins.minimap.width * SCALE,
+ self.position.y, config.plugins.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 show_minimap(self) 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.plugins.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)
-
- -- highlight the selected lines, and the line with the caret on it
- local selection_color = config.plugins.minimap.selection_color or style.dim
- local caret_color = config.plugins.minimap.caret_color or style.caret
- local selection_line, selection_col, selection_line2, selection_col2 = self.doc:get_selection()
- local selection_y = y + (selection_line - minimap_start_line) * line_spacing
- local selection2_y = y + (selection_line2 - minimap_start_line) * line_spacing
- local selection_min_y = math.min(selection_y, selection2_y)
- local selection_h = math.abs(selection2_y - selection_y)+1
- renderer.draw_rect(x, selection_min_y, w, selection_h, selection_color)
- renderer.draw_rect(x, selection_y, w, line_spacing, caret_color)
-
- local highlight_align = config.plugins.minimap.highlight_align
- 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
-
- -- 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.plugins.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.plugins.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
-
- local highlight_x
- if highlight_align == 'left' then
- highlight_x = x
- else
- highlight_x = x + w - highlight_width
- end
- local function render_highlight(idx, line_y)
- local highlight_color = minimap:line_highlight_color(idx)
- if highlight_color then
- renderer.draw_rect(highlight_x, line_y, highlight_width, line_spacing, highlight_color)
- end
- end
-
- local endidx = minimap_start_line + max_minmap_lines
- endidx = math.min(endidx, line_count)
- -- render lines with syntax highlighting
- if config.plugins.minimap.syntax_highlight then
-
- -- keep track of the highlight type, since this needs to break batches as well
- batch_syntax_type = nil
-
- -- per line
- for idx = minimap_start_line, endidx do
- batch_syntax_type = nil
- batch_start = x + gutter_width
- batch_width = 0
-
- render_highlight(idx, line_y)
-
- -- 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.plugins.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 = minimap_start_line, endidx do
- batch_start = x + gutter_width
- batch_width = 0
-
- render_highlight(idx, line_y)
-
- 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 char == " " then
- flush_batch()
- batch_start = batch_start + (char_spacing * config.plugins.minimap.tab_width)
- 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
+ if not show_minimap(self) 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.plugins.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)
+
+ -- highlight the selected lines, and the line with the caret on it
+ local selection_color = config.plugins.minimap.selection_color or style.dim
+ local caret_color = config.plugins.minimap.caret_color or style.caret
+ local selection_line, selection_col, selection_line2, selection_col2 = self.doc:get_selection()
+ local selection_y = y + (selection_line - minimap_start_line) * line_spacing
+ local selection2_y = y + (selection_line2 - minimap_start_line) * line_spacing
+ local selection_min_y = math.min(selection_y, selection2_y)
+ local selection_h = math.abs(selection2_y - selection_y)+1
+ renderer.draw_rect(x, selection_min_y, w, selection_h, selection_color)
+ renderer.draw_rect(x, selection_y, w, line_spacing, caret_color)
+
+ local highlight_align = config.plugins.minimap.highlight_align
+ 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
+
+ -- 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.plugins.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.plugins.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
+
+ local highlight_x
+ if highlight_align == 'left' then
+ highlight_x = x
+ else
+ highlight_x = x + w - highlight_width
+ end
+ local function render_highlight(idx, line_y)
+ local highlight_color = minimap:line_highlight_color(idx)
+ if highlight_color then
+ renderer.draw_rect(highlight_x, line_y, highlight_width, line_spacing, highlight_color)
+ end
+ end
+
+ local endidx = minimap_start_line + max_minmap_lines
+ endidx = math.min(endidx, line_count)
+ -- render lines with syntax highlighting
+ if config.plugins.minimap.syntax_highlight then
+
+ -- keep track of the highlight type, since this needs to break batches as well
+ batch_syntax_type = nil
+
+ -- per line
+ for idx = minimap_start_line, endidx do
+ batch_syntax_type = nil
+ batch_start = x + gutter_width
+ batch_width = 0
+
+ render_highlight(idx, line_y)
+
+ -- 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.plugins.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 = minimap_start_line, endidx do
+ batch_start = x + gutter_width
+ batch_width = 0
+
+ render_highlight(idx, line_y)
+
+ 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 char == " " then
+ flush_batch()
+ batch_start = batch_start + (char_spacing * config.plugins.minimap.tab_width)
+ 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
local prev_update = DocView.update
DocView.update = function (self)
- if not show_minimap(self) then return prev_update(self) end
- self.size.x = self.size.x - config.plugins.minimap.width * SCALE
- return prev_update(self)
+ if not show_minimap(self) then return prev_update(self) end
+ self.size.x = self.size.x - config.plugins.minimap.width * SCALE
+ return prev_update(self)
end
command.add(nil, {
- ["minimap:toggle-visibility"] = function()
- config.plugins.minimap.enabled = not config.plugins.minimap.enabled
- end,
- ["minimap:toggle-syntax-highlighting"] = function()
- config.plugins.minimap.syntax_highlight = not config.plugins.minimap.syntax_highlight
- end
+ ["minimap:toggle-visibility"] = function()
+ config.plugins.minimap.enabled = not config.plugins.minimap.enabled
+ end,
+ ["minimap:toggle-syntax-highlighting"] = function()
+ config.plugins.minimap.syntax_highlight = not config.plugins.minimap.syntax_highlight
+ end
})
command.add("core.docview!", {
- ["minimap:toggle-visibility-for-current-view"] = function()
- per_docview[core.active_view] = per_docview[core.active_view] == false
- end
+ ["minimap:toggle-visibility-for-current-view"] = function()
+ per_docview[core.active_view] = per_docview[core.active_view] == false
+ end
})
return minimap
diff --git a/plugins/regexreplacepreview.lua b/plugins/regexreplacepreview.lua
index 85845ad..7ca8bc1 100644
--- a/plugins/regexreplacepreview.lua
+++ b/plugins/regexreplacepreview.lua
@@ -6,121 +6,126 @@ local command = require "core.command"
-- Takes the following pattern: /pattern/replace/
-- Capture groupings can be replaced using \1 through \9
local function regex_replace_file(view, pattern, old_lines, raw, start_line, end_line)
- local doc = view.doc
- local start_pattern, end_pattern, end_replacement, start_replacement = 2, 2;
- repeat
- end_pattern = string.find(pattern, "/", end_pattern)
- until end_pattern == nil or pattern[end_pattern-1] ~= "\\"
- if end_pattern == nil then
- end_pattern = #pattern + 1
- else
- end_pattern = end_pattern - 1
- start_replacement = end_pattern+2;
- end_replacement = end_pattern+2;
- repeat
- end_replacement = string.find(pattern, "/", end_replacement)
- until end_replacement == nil or pattern[end_replacement-1] ~= "\\"
- end
- end_replacement = end_replacement and (end_replacement - 1)
+ local doc = view.doc
+ local start_pattern, end_pattern, end_replacement, start_replacement = 2, 2;
+ repeat
+ end_pattern = string.find(pattern, "/", end_pattern)
+ until end_pattern == nil or pattern[end_pattern-1] ~= "\\"
+ if end_pattern == nil then
+ end_pattern = #pattern + 1
+ else
+ end_pattern = end_pattern - 1
+ start_replacement = end_pattern+2;
+ end_replacement = end_pattern+2;
+ repeat
+ end_replacement = string.find(pattern, "/", end_replacement)
+ until end_replacement == nil or pattern[end_replacement-1] ~= "\\"
+ end
+ end_replacement = end_replacement and (end_replacement - 1)
- local re = start_pattern ~= end_pattern and regex.compile(pattern:sub(start_pattern, end_pattern))
+ local re = start_pattern ~= end_pattern
+ and regex.compile(pattern:sub(start_pattern, end_pattern))
- local replacement = end_replacement and pattern:sub(start_replacement, end_replacement)
- local replace_line = raw and function(line, new_text)
- if line == #doc.lines then
- doc:raw_remove(line, 1, line, #doc.lines[line], { idx = 1 }, 0)
- else
- doc:raw_remove(line, 1, line+1, 1, { idx = 1 }, 0)
- end
- doc:raw_insert(line, 1, new_text, { idx = 1 }, 0)
- end or function(line, new_text)
- if line == #doc.lines then
- doc:remove(line, 1, line, #doc.lines[line])
- else
- doc:remove(line, 1, line+1, 1)
- end
- doc:insert(line, 1, new_text)
- end
+ local replacement = end_replacement and pattern:sub(
+ start_replacement, end_replacement
+ )
+ local replace_line = raw and function(line, new_text)
+ if line == #doc.lines then
+ doc:raw_remove(line, 1, line, #doc.lines[line], { idx = 1 }, 0)
+ else
+ doc:raw_remove(line, 1, line+1, 1, { idx = 1 }, 0)
+ end
+ doc:raw_insert(line, 1, new_text, { idx = 1 }, 0)
+ end or function(line, new_text)
+ if line == #doc.lines then
+ doc:remove(line, 1, line, #doc.lines[line])
+ else
+ doc:remove(line, 1, line+1, 1)
+ end
+ doc:insert(line, 1, new_text)
+ end
- local line_scroll = nil
- if re then
- for i = (start_line or 1), (end_line or #doc.lines) do
- local new_text, matches, rmatches
- local old_text = old_lines[i] or doc.lines[i]
- local old_length = #old_text
- if replacement then
- new_text, matches, rmatches = regex.gsub(re, old_text, replacement)
- end
- if matches and #matches > 0 then
- old_lines[i] = old_text
- replace_line(i, new_text)
- if line_scroll == nil then
- line_scroll = i
- doc:set_selection(i, rmatches[1][1], i, rmatches[1][2])
- end
- elseif old_lines[i] then
- replace_line(i, old_lines[i])
- old_lines[i] = nil
- end
- if not replacement then
- local s,e = regex.match(re, old_text)
- if s then
- line_scroll = i
- doc:set_selection(i, s, i, e)
- break
- end
- end
+ local line_scroll = nil
+ if re then
+ for i = (start_line or 1), (end_line or #doc.lines) do
+ local new_text, matches, rmatches
+ local old_text = old_lines[i] or doc.lines[i]
+ local old_length = #old_text
+ if replacement then
+ new_text, matches, rmatches = regex.gsub(re, old_text, replacement)
end
- if line_scroll then
- view:scroll_to_line(line_scroll, true)
+ if matches and #matches > 0 then
+ old_lines[i] = old_text
+ replace_line(i, new_text)
+ if line_scroll == nil then
+ line_scroll = i
+ doc:set_selection(i, rmatches[1][1], i, rmatches[1][2])
+ end
+ elseif old_lines[i] then
+ replace_line(i, old_lines[i])
+ old_lines[i] = nil
end
- end
- if replacement == nil then
- for k,v in pairs(old_lines) do
- replace_line(k, v)
+ if not replacement then
+ local s,e = regex.match(re, old_text)
+ if s then
+ line_scroll = i
+ doc:set_selection(i, s, i, e)
+ break
+ end
end
- old_lines = {}
- end
- return old_lines, line_scroll ~= nil
+ end
+ if line_scroll then
+ view:scroll_to_line(line_scroll, true)
+ end
+ end
+ if replacement == nil then
+ for k,v in pairs(old_lines) do
+ replace_line(k, v)
+ end
+ old_lines = {}
+ end
+ return old_lines, line_scroll ~= nil
end
command.add("core.docview", {
- ["regex-replace-preview:find-replace-regex"] = function()
- core.command_view:set_text("/")
- local old_lines = {}
- local view = core.active_view
- local doc = view.doc
- local original_selection = { doc:get_selection(true) }
- local selection = doc:has_selection() and { doc:get_selection(true) } or {}
- core.command_view:enter(
- "Regex Replace (enter pattern as /old/new/)",
- function(pattern)
- regex_replace_file(view, pattern, {}, false, selection[1], selection[3])
- end,
- function(pattern)
- local incremental, has_replacement = regex_replace_file(view, pattern, old_lines, true, selection[1], selection[3])
- if incremental then
- old_lines = incremental
+ ["regex-replace-preview:find-replace-regex"] = function()
+ core.command_view:set_text("/")
+ local old_lines = {}
+ local view = core.active_view
+ local doc = view.doc
+ local original_selection = { doc:get_selection(true) }
+ local selection = doc:has_selection() and { doc:get_selection(true) } or {}
+ core.command_view:enter(
+ "Regex Replace (enter pattern as /old/new/)",
+ function(pattern)
+ regex_replace_file(view, pattern, {}, false, selection[1], selection[3])
+ end,
+ function(pattern)
+ local incremental, has_replacement = regex_replace_file(
+ view, pattern, old_lines, true, selection[1], selection[3]
+ )
+ if incremental then
+ old_lines = incremental
+ end
+ if not has_replacement then
+ doc:set_selection(table.unpack(original_selection))
+ end
+ end,
+ function(pattern)
+ for k,v in pairs(old_lines) do
+ if v then
+ if k == #doc.lines then
+ doc:raw_remove(k, 1, k, #doc.lines[k], { idx = 1 }, 0)
+ else
+ doc:raw_remove(k, 1, k+1, 1, { idx = 1 }, 0)
end
- if not has_replacement then
- doc:set_selection(table.unpack(original_selection))
- end
- end,
- function(pattern)
- for k,v in pairs(old_lines) do
- if v then
- if k == #doc.lines then
- doc:raw_remove(k, 1, k, #doc.lines[k], { idx = 1 }, 0)
- else
- doc:raw_remove(k, 1, k+1, 1, { idx = 1 }, 0)
- end
- doc:raw_insert(k, 1, v, { idx = 1 }, 0)
- end
- end
- doc:set_selection(table.unpack(original_selection))
- end
- )
- end
+ doc:raw_insert(k, 1, v, { idx = 1 }, 0)
+ end
+ end
+ doc:set_selection(table.unpack(original_selection))
+ end
+ )
+ end
})
keymap.add { ["ctrl+shift+r"] = "regex-replace-preview:find-replace-regex" }
diff --git a/plugins/select_colorscheme.lua b/plugins/select_colorscheme.lua
index 4406aa1..0d60251 100644
--- a/plugins/select_colorscheme.lua
+++ b/plugins/select_colorscheme.lua
@@ -65,10 +65,10 @@ local function make_color_module_name(name)
end
function Settings:change_color(name)
- if self:is_change_color(name) then
- core.reload_module(make_color_module_name(name))
- self.color_scheme = name
- end
+ if self:is_change_color(name) then
+ core.reload_module(make_color_module_name(name))
+ self.color_scheme = name
+ end
end
function Settings:save_settings()
@@ -121,10 +121,10 @@ local color_scheme_suggest = function(text)
end
command.add(nil, {
- ["ui:color scheme"] = function()
- core.command_view:enter("Select color scheme", color_scheme_submit, color_scheme_suggest)
- end,
- })
+ ["ui:color scheme"] = function()
+ core.command_view:enter("Select color scheme", color_scheme_submit, color_scheme_suggest)
+ end,
+})
-- ----------------------------------------------------------------
Settings:init()
diff --git a/plugins/themeselect.lua b/plugins/themeselect.lua
index 6a06715..fe4ff34 100644
--- a/plugins/themeselect.lua
+++ b/plugins/themeselect.lua
@@ -7,12 +7,11 @@ local core = require "core"
-- usage:
-- require("plugins.themeselect").add_pattern("%.md$", "summer")
-local theme_select = { }
+local theme_select = {}
local saved_colors_module = "core.style"
-local themes_patterns = {
-}
+local themes_patterns = {}
local reload_module = core.reload_module
local set_visited = core.set_visited