aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/linenumbers.lua85
1 files changed, 56 insertions, 29 deletions
diff --git a/plugins/linenumbers.lua b/plugins/linenumbers.lua
index c075776..2b2f508 100644
--- a/plugins/linenumbers.lua
+++ b/plugins/linenumbers.lua
@@ -8,6 +8,7 @@ local command = require "core.command"
config.plugins.linenumbers = common.merge({
show = true,
relative = false,
+ hybrid = false,
-- The config specification used by the settings gui
config_spec = {
name = "Line Numbers",
@@ -24,6 +25,13 @@ config.plugins.linenumbers = common.merge({
path = "relative",
type = "toggle",
default = false
+ },
+ {
+ label = "Hybrid Line Numbers",
+ description = "Display hybrid line numbers starting from active line (Overpowers relative line-numbers).",
+ path = "hybrid",
+ type = "toggle",
+ default = false
}
}
}, config.plugins.linenumbers)
@@ -37,46 +45,49 @@ function DocView:draw_line_gutter(line, x, y, width)
return lh
end
- if config.plugins.linenumbers.relative then
- local color = style.line_number
- local local_idx = line
+ if not (config.plugins.linenumbers.relative or config.plugins.linenumbers.hybrid) then
+ return draw_line_gutter(self, line, x, y, width)
+ end
- for _, line1, _, line2 in self.doc:get_selections(true) do
- if line >= line1 and line <= line2 then
- color = style.line_number2
- break
- end
- end
+ local color = style.line_number
- local l1 = self.doc:get_selection(false)
- if line == l1 then
+ for _, line1, _, line2 in self.doc:get_selections(true) do
+ if line == line1 then
color = style.line_number2
- local_idx = 0
- else
- local_idx = math.abs(line - l1)
+ break
end
+ end
- common.draw_text(
- self:get_font(),
- color, local_idx, "right",
- x + style.padding.x,
- y,
- width, lh
- )
- else
- return draw_line_gutter(self, line, x, y, width)
+ local l1 = self.doc:get_selection(false)
+ local local_idx = math.abs(line - l1)
+ local alignment = "right"
+ local x_offset = style.padding.x
+
+ if config.plugins.linenumbers.hybrid and line == l1 then
+ local_idx = line
+ alignment = "left"
+ x_offset = 0
end
+
+ common.draw_text(
+ self:get_font(),
+ color, local_idx, alignment,
+ x + x_offset,
+ y,
+ width, lh
+ )
+
return lh
end
function DocView:get_gutter_width(...)
if
- not config.plugins.linenumbers.show
+ not config.plugins.linenumbers.show
then
local width = get_gutter_width(self, ...)
local correct_width = self:get_font():get_width(#self.doc.lines)
- + (style.padding.x * 2)
+ + (style.padding.x * 2)
-- compatibility with center doc
if width <= correct_width then
@@ -90,15 +101,15 @@ function DocView:get_gutter_width(...)
end
command.add(nil, {
- ["line-numbers:toggle"] = function()
+ ["line-numbers:toggle"] = function()
config.plugins.linenumbers.show = not config.plugins.linenumbers.show
end,
- ["line-numbers:disable"] = function()
+ ["line-numbers:disable"] = function()
config.plugins.linenumbers.show = false
end,
- ["line-numbers:enable"] = function()
+ ["line-numbers:enable"] = function()
config.plugins.linenumbers.show = true
end,
@@ -110,7 +121,23 @@ command.add(nil, {
config.plugins.linenumbers.relative = true
end,
- ["relative-line-numbers:disable"] = function()
+ ["relative-line-numbers:disable"] = function()
+ config.plugins.linenumbers.relative = false
+ end,
+
+ ["hybrid-line-numbers:toggle"] = function()
+ config.plugins.linenumbers.hybrid = not config.plugins.linenumbers.hybrid
+ if config.plugins.linenumbers.hybrid then
+ config.plugins.linenumbers.relative = false -- Disable relative mode when enabling hybrid mode
+ end
+ end,
+
+ ["hybrid-line-numbers:enable"] = function()
+ config.plugins.linenumbers.hybrid = true
config.plugins.linenumbers.relative = false
+ end,
+
+ ["hybrid-line-numbers:disable"] = function()
+ config.plugins.linenumbers.hybrid = false
end
})