From f2e5821e22b5f813fae1b6d3087b3d75c82f438b Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 16 May 2020 19:53:17 +0100 Subject: Added ./plugins/centerdoc.lua --- README.md | 1 + plugins/centerdoc.lua | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 plugins/centerdoc.lua 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 -- cgit v1.2.3