From 29669bdcb0cd8a1601be4f917aa432385e5ad445 Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 17 Jun 2020 12:04:08 +0100 Subject: Added better support for ctrl+backspace to `autoinsert` --- plugins/autoinsert.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'plugins') 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", +} -- cgit v1.2.3