aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-06-15 20:55:32 -0400
committerjgmdev <jgmdev@gmail.com>2022-06-15 20:55:32 -0400
commitd7501e50159a5a90ae4595a55e582b48fcc10632 (patch)
tree1018a0194fc0caa2901dc58a576b7c95ca8ce486 /plugins
parente9abdcbcc92518668d1c338b6fabf45055775f01 (diff)
downloadlite-xl-plugins-d7501e50159a5a90ae4595a55e582b48fcc10632.tar.gz
lite-xl-plugins-d7501e50159a5a90ae4595a55e582b48fcc10632.zip
linenumbers: fix gutter width and centerdoc combo
Diffstat (limited to 'plugins')
-rw-r--r--plugins/linenumbers.lua48
1 files changed, 25 insertions, 23 deletions
diff --git a/plugins/linenumbers.lua b/plugins/linenumbers.lua
index 03b5fb2..c075776 100644
--- a/plugins/linenumbers.lua
+++ b/plugins/linenumbers.lua
@@ -29,7 +29,7 @@ config.plugins.linenumbers = common.merge({
}, config.plugins.linenumbers)
local draw_line_gutter = DocView.draw_line_gutter
-local get_width = DocView.get_gutter_width
+local get_gutter_width = DocView.get_gutter_width
function DocView:draw_line_gutter(line, x, y, width)
local lh = self:get_line_height()
@@ -38,39 +38,33 @@ function DocView:draw_line_gutter(line, x, y, width)
end
if config.plugins.linenumbers.relative then
-
local color = style.line_number
local local_idx = line
- local align = "right"
+
+ 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 l1 = self.doc:get_selection(false)
if line == l1 then
color = style.line_number2
- if config.line_numbers then
- align = "center"
- else
- local_idx = 0
- end
+ local_idx = 0
else
local_idx = math.abs(line - l1)
end
- -- Fix for old version (<=1.16)
- if width == nil then
- local gpad = style.padding.x * 2
- local gw = self:get_font():get_width(#self.doc.lines) + gpad
- width = gpad and gw - gpad or gw
- end
-
common.draw_text(
self:get_font(),
- color, local_idx, align,
+ color, local_idx, "right",
x + style.padding.x,
- y + self:get_line_text_y_offset(),
- width, lh
+ y,
+ width, lh
)
else
- draw_line_gutter(self, line, x, y, width)
+ return draw_line_gutter(self, line, x, y, width)
end
return lh
end
@@ -78,12 +72,20 @@ end
function DocView:get_gutter_width(...)
if
not config.plugins.linenumbers.show
- and
- not config.plugins.linenumbers.relative
then
- return style.padding.x
+ local width = get_gutter_width(self, ...)
+
+ local correct_width = self:get_font():get_width(#self.doc.lines)
+ + (style.padding.x * 2)
+
+ -- compatibility with center doc
+ if width <= correct_width then
+ width = style.padding.x
+ end
+
+ return width, 0
else
- return get_width(self, ...)
+ return get_gutter_width(self, ...)
end
end