diff options
author | jgmdev <jgmdev@gmail.com> | 2022-03-11 06:56:50 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-05-22 13:16:10 -0400 |
commit | b05f35fef02d51e210c20b09fcd3e042c5d8ef20 (patch) | |
tree | 96fd317f41e2ca6b88dabe5f88dbebd6fbccf965 | |
parent | 8ff3b1ed350d06a5bd791d4cb23ba3f7f6f81b45 (diff) | |
download | lite-xl-plugins-b05f35fef02d51e210c20b09fcd3e042c5d8ef20.tar.gz lite-xl-plugins-b05f35fef02d51e210c20b09fcd3e042c5d8ef20.zip |
centerdoc: added toggle and zen mode toggle commands
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | plugins/centerdoc.lua | 60 |
2 files changed, 55 insertions, 7 deletions
@@ -33,7 +33,7 @@ to something other than a raw file it should be marked with an asterisk.* | [`bigclock`](plugins/bigclock.lua?raw=1) | Shows the current time and date in a view with large text *([screenshot](https://user-images.githubusercontent.com/3920290/82752891-3318df00-9db9-11ea-803f-261d80d5cf53.png))* | | [`black`](https://git.sr.ht/\~tmpod/black-lite)\* | Integrates the [black](https://github.com/psf/black) Python formatter with lite | | [`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))* | +| [`centerdoc`](plugins/centerdoc.lua?raw=1) | Centers document's content on the screen and adds zen mode support *([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/franko/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))* | | [`contextmenu`](https://github.com/takase1121/lite-contextmenu)\* | Simple context menu *([screenshot](https://github.com/takase1121/lite-contextmenu/blob/master/assets/screenshot.jpg?raw=true))* | diff --git a/plugins/centerdoc.lua b/plugins/centerdoc.lua index f1487f4..c657725 100644 --- a/plugins/centerdoc.lua +++ b/plugins/centerdoc.lua @@ -1,21 +1,69 @@ -- mod-version:3 --lite-xl 2.1 +local core = require "core" local config = require "core.config" +local common = require "core.common" +local command = require "core.command" +local keymap = require "core.keymap" +local treeview = require "plugins.treeview" local DocView = require "core.docview" +config.plugins.centerdoc = common.merge({ + enable = true +}, config.plugins.centerdoc) local draw_line_gutter = DocView.draw_line_gutter local get_gutter_width = DocView.get_gutter_width function DocView:draw_line_gutter(idx, x, y, width) - local real_gutter_width = get_gutter_width(self) - local offset = self:get_gutter_width() - real_gutter_width * 2 - draw_line_gutter(self, idx, x + offset, y, real_gutter_width) + if not config.plugins.centerdoc.enable then + draw_line_gutter(self, idx, x, y, width) + else + local real_gutter_width = get_gutter_width(self) + local offset = self:get_gutter_width() - real_gutter_width * 2 + draw_line_gutter(self, idx, x + offset, y, real_gutter_width) + end 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) + if not config.plugins.centerdoc.enable then + return get_gutter_width(self) + else + 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 end + +local zen_mode = false +local previous_win_status = system.get_window_mode() +local previous_treeview_status = treeview.visible +local previous_statusbar_status = core.status_view.visible + +command.add(nil, { + ["center-doc:toggle"] = function() + config.plugins.centerdoc.enable = not config.plugins.centerdoc.enable + end, + ["center-doc:zen-mode-toggle"] = function() + zen_mode = not zen_mode + + if zen_mode then + previous_win_status = system.get_window_mode() + previous_treeview_status = treeview.visible + previous_statusbar_status = core.status_view.visible + + config.plugins.centerdoc.enable = true + system.set_window_mode("fullscreen") + treeview.visible = false + command.perform "status-bar:hide" + else + config.plugins.centerdoc.enable = false + system.set_window_mode(previous_win_status) + treeview.visible = previous_treeview_status + core.status_view.visible = previous_statusbar_status + end + end, +}) + +keymap.add { ["ctrl+alt+z"] = "center-doc:zen-mode-toggle" } |