Improve `lineguide` plugin (#1056)
* Add more options to lineguide * Allow lineguide plugin to load but remain disabled * Use config.line_limit for default ruler
This commit is contained in:
parent
ec0e3018a8
commit
1e91080680
|
@ -54,7 +54,6 @@ setmetatable(config.plugins, {
|
||||||
|
|
||||||
-- Disable these plugins by default.
|
-- Disable these plugins by default.
|
||||||
config.plugins.trimwhitespace = false
|
config.plugins.trimwhitespace = false
|
||||||
config.plugins.lineguide = false
|
|
||||||
config.plugins.drawwhitespace = false
|
config.plugins.drawwhitespace = false
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -1,21 +1,59 @@
|
||||||
-- mod-version:3
|
-- mod-version:3
|
||||||
|
local common = require "core.common"
|
||||||
|
local command = require "core.command"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
local DocView = require "core.docview"
|
local DocView = require "core.docview"
|
||||||
local CommandView = require "core.commandview"
|
local CommandView = require "core.commandview"
|
||||||
|
|
||||||
local draw_overlay = DocView.draw_overlay
|
config.plugins.lineguide = common.merge({
|
||||||
|
enabled = false,
|
||||||
|
width = 2,
|
||||||
|
rulers = {
|
||||||
|
-- 80,
|
||||||
|
-- 100,
|
||||||
|
-- 120,
|
||||||
|
config.line_limit
|
||||||
|
}
|
||||||
|
}, config.plugins.lineguide)
|
||||||
|
|
||||||
function DocView:draw_overlay(...)
|
local function get_ruler(v)
|
||||||
if not self:is(CommandView) then
|
local result = nil
|
||||||
local offset = self:get_font():get_width("n") * config.line_limit
|
if type(v) == 'number' then
|
||||||
local x = self:get_line_screen_position(1) + offset
|
result = { columns = v }
|
||||||
local y = self.position.y
|
elseif type(v) == 'table' then
|
||||||
local w = math.ceil(SCALE * 1)
|
result = v
|
||||||
local h = self.size.y
|
|
||||||
|
|
||||||
local color = style.guide or style.selection
|
|
||||||
renderer.draw_rect(x, y, w, h, color)
|
|
||||||
end
|
end
|
||||||
draw_overlay(self, ...)
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local draw_overlay = DocView.draw_overlay
|
||||||
|
function DocView:draw_overlay(...)
|
||||||
|
draw_overlay(self, ...)
|
||||||
|
|
||||||
|
if config.plugins.lineguide.enabled and not self:is(CommandView) then
|
||||||
|
local line_x = self:get_line_screen_position(1)
|
||||||
|
local character_width = self:get_font():get_width("n")
|
||||||
|
local ruler_width = config.plugins.lineguide.width
|
||||||
|
local ruler_color = style.guide or style.selection
|
||||||
|
|
||||||
|
for k,v in ipairs(config.plugins.lineguide.rulers) do
|
||||||
|
local ruler = get_ruler(v)
|
||||||
|
|
||||||
|
if ruler then
|
||||||
|
local x = line_x + (character_width * ruler.columns)
|
||||||
|
local y = self.position.y
|
||||||
|
local w = ruler_width
|
||||||
|
local h = self.size.y
|
||||||
|
|
||||||
|
renderer.draw_rect(x, y, w, h, ruler.color or ruler_color)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
command.add(nil, {
|
||||||
|
["lineguide:toggle"] = function()
|
||||||
|
config.plugins.lineguide.enabled = not config.plugins.lineguide.enabled
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue