aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-05-16 19:53:17 +0100
committerrxi <rxi@users.noreply.github.com>2020-05-16 19:54:16 +0100
commitf2e5821e22b5f813fae1b6d3087b3d75c82f438b (patch)
tree3e7e519289bb9872290fae128f26df743214f496
parent4312007bad8d14861baec21d67e2b583e6f56121 (diff)
downloadlite-xl-plugins-f2e5821e22b5f813fae1b6d3087b3d75c82f438b.tar.gz
lite-xl-plugins-f2e5821e22b5f813fae1b6d3087b3d75c82f438b.zip
Added ./plugins/centerdoc.lua
-rw-r--r--README.md1
-rw-r--r--plugins/centerdoc.lua19
2 files changed, 20 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0b47525..f5f095f 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ Plugin | Description
-------|-----------------------------------------
[`autowrap`](plugins/autowrap.lua?raw=1) | Automatically hardwraps lines when typing
[`bracketmatch`](plugins/bracketmatch.lua?raw=1) | Underlines matching pair for bracket under the caret *([screenshot](https://user-images.githubusercontent.com/3920290/80132745-0c863f00-8594-11ea-8875-c455c6fd7eae.png))*
+[`centerdoc`](plugins/centerdoc.lua?raw=1) | Centers document's content on the screen *([screenshot](https://user-images.githubusercontent.com/3920290/82127896-bf6e4500-97ae-11ea-97fc-ba9a552bc9a4.png))*
[`colorpreview`](plugins/colorpreview.lua?raw=1) | Underlays color values (eg. `#ff00ff` or `rgb(255, 0, 255)`) with their resultant color. *([screenshot](https://user-images.githubusercontent.com/3920290/80743752-731bd780-8b15-11ea-97d3-847db927c5dc.png))*
[`console`](https://github.com/rxi/console)* | A console for running external commands and capturing their output *([gif](https://user-images.githubusercontent.com/3920290/81343656-49325a00-90ad-11ea-8647-ff39d8f1d730.gif))*
[`copyfilelocation`](plugins/copyfilelocation.lua?raw=1) | Copy file location to clipboard
diff --git a/plugins/centerdoc.lua b/plugins/centerdoc.lua
new file mode 100644
index 0000000..1921467
--- /dev/null
+++ b/plugins/centerdoc.lua
@@ -0,0 +1,19 @@
+local config = require "core.config"
+local DocView = require "core.docview"
+
+
+local draw_line_gutter = DocView.draw_line_gutter
+local get_gutter_width = DocView.get_gutter_width
+
+
+function DocView:draw_line_gutter(idx, x, y)
+ local offset = self:get_gutter_width() - get_gutter_width(self)
+ draw_line_gutter(self, idx, x + offset, y)
+end
+
+
+function DocView:get_gutter_width()
+ local real_gutter_width = get_gutter_width(self)
+ local width = real_gutter_width + self:get_font():get_width("n") * config.line_limit
+ return math.max((self.size.x - width) / 2, real_gutter_width)
+end