diff options
author | rxi <rxi@users.noreply.github.com> | 2020-04-23 20:49:37 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-04-23 20:49:37 +0100 |
commit | 676f04945010aeb2ae71325bf2d1d6f336a5e162 (patch) | |
tree | 31b2e18df5e84fbc731840e5f1b28c974eea868a /plugins/autowrap.lua | |
parent | 9049e189d49440939192874d54af15a21eebbafb (diff) | |
download | lite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.tar.gz lite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.zip |
Moved all plugins to `plugins` dir
Diffstat (limited to 'plugins/autowrap.lua')
-rw-r--r-- | plugins/autowrap.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua new file mode 100644 index 0000000..85d4c24 --- /dev/null +++ b/plugins/autowrap.lua @@ -0,0 +1,35 @@ +require "plugins.reflow" +local config = require "core.config" +local command = require "core.command" +local DocView = require "core.docview" + +config.autowrap_files = { "%.md$", "%.txt$" } + + +local on_text_input = DocView.on_text_input + +DocView.on_text_input = function(self, ...) + on_text_input(self, ...) + + -- early-exit if the filename does not match a file type pattern + local filename = self.doc.filename or "" + local matched = false + for _, ptn in ipairs(config.autowrap_files) do + if filename:match(ptn) then + matched = true + break + end + end + if not matched then return end + + -- do automatic reflow on line if we're typing at the end of the line and have + -- reached the line limit + local line, col = self.doc:get_selection() + local text = self.doc:get_text(line, 1, line, math.huge) + if #text >= config.line_limit and col > #text then + command.perform("doc:select-lines") + command.perform("reflow:reflow") + command.perform("doc:move-to-next-char") + command.perform("doc:move-to-previous-char") + end +end |