aboutsummaryrefslogtreecommitdiff
path: root/plugins/autowrap.lua
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-03-11 07:03:46 -0400
committerjgmdev <jgmdev@gmail.com>2022-05-22 13:16:10 -0400
commit6c7cb500350377e89a930228747c4aa5f13e8716 (patch)
tree502caff229fbc12a76a8dab065e5382123e69620 /plugins/autowrap.lua
parentcb965ffffc17804c57832d1871d56d37a6f8f5e1 (diff)
downloadlite-xl-plugins-6c7cb500350377e89a930228747c4aa5f13e8716.tar.gz
lite-xl-plugins-6c7cb500350377e89a930228747c4aa5f13e8716.zip
autowrap: fixed missing require 'core.common', added toggle command
Diffstat (limited to 'plugins/autowrap.lua')
-rw-r--r--plugins/autowrap.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua
index 0f34eec..e318fd3 100644
--- a/plugins/autowrap.lua
+++ b/plugins/autowrap.lua
@@ -2,9 +2,13 @@
require "plugins.reflow"
local config = require "core.config"
local command = require "core.command"
+local common = require "core.common"
local DocView = require "core.docview"
-config.plugins.autowrap = common.merge({ files = { "%.md$", "%.txt$" } }, config.plugins.autowrap)
+config.plugins.autowrap = common.merge({
+ enable = false,
+ files = { "%.md$", "%.txt$" }
+}, config.plugins.autowrap)
local on_text_input = DocView.on_text_input
@@ -12,6 +16,8 @@ local on_text_input = DocView.on_text_input
DocView.on_text_input = function(self, ...)
on_text_input(self, ...)
+ if not config.plugins.autowrap.enable then return end
+
-- early-exit if the filename does not match a file type pattern
local filename = self.doc.filename or ""
local matched = false
@@ -35,3 +41,9 @@ DocView.on_text_input = function(self, ...)
command.perform("doc:move-to-end-of-line")
end
end
+
+command.add(nil, {
+ ["auto-wrap:toggle"] = function()
+ config.plugins.autowrap.enable = not config.plugins.autowrap.enable
+ end
+})