diff options
author | rxi <rxi@users.noreply.github.com> | 2020-06-17 12:04:08 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-06-17 12:04:25 +0100 |
commit | 29669bdcb0cd8a1601be4f917aa432385e5ad445 (patch) | |
tree | aac3c1a8297b67d44192120c6cf14e92f6ea5bce /plugins | |
parent | 1d4b264e2988fe91b7071e0f86a22f97983da280 (diff) | |
download | lite-xl-plugins-29669bdcb0cd8a1601be4f917aa432385e5ad445.tar.gz lite-xl-plugins-29669bdcb0cd8a1601be4f917aa432385e5ad445.zip |
Added better support for ctrl+backspace to `autoinsert`
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/autoinsert.lua | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua index a3c8f98..0bf5a5a 100644 --- a/plugins/autoinsert.lua +++ b/plugins/autoinsert.lua @@ -1,4 +1,5 @@ local core = require "core" +local translate = require "core.doc.translate" local config = require "core.config" local DocView = require "core.docview" local command = require "core.command" @@ -60,7 +61,13 @@ function DocView:on_text_input(text) end -command.add("core.docview", { + +local function predicate() + return getmetatable(core.active_view) == DocView + and not core.active_view.doc:has_selection() +end + +command.add(predicate, { ["autoinsert:backspace"] = function() local doc = core.active_view.doc local l, c = doc:get_selection() @@ -70,6 +77,22 @@ command.add("core.docview", { end command.perform "doc:backspace" end, + + ["autoinsert:delete-to-previous-word-start"] = function() + local doc = core.active_view.doc + local le, ce = translate.previous_word_start(doc, doc:get_selection()) + while true do + local l, c = doc:get_selection() + if l == le and c == ce then + break + end + command.perform "autoinsert:backspace" + end + end, }) -keymap.add { ["backspace"] = "autoinsert:backspace" } +keymap.add { + ["backspace"] = "autoinsert:backspace", + ["ctrl+backspace"] = "autoinsert:delete-to-previous-word-start", + ["ctrl+shift+backspace"] = "autoinsert:delete-to-previous-word-start", +} |