Add an InsertDelete hook

This commit is contained in:
Maxime Coste 2017-03-30 10:38:56 +01:00
parent fa7f29a120
commit 2cfe3cae36
4 changed files with 13 additions and 1 deletions

View File

@ -1415,6 +1415,8 @@ existing hooks are:
* `InsertKey`: A key is received in insert mode, the key is used for filtering
* `InsertChar`: A character is inserted in insert mode, the character is used
for filtering
* `InsertDelete`: A character is deleted in insert mode, the character deleted
by the main selection is used for filtering
* `InsertMove`: The cursor moved (without inserting) in insert mode, the key
that triggered the move is used for filtering
* `WinCreate`: A window was created, the filtering text is the buffer name

View File

@ -68,6 +68,10 @@ Default hooks
a character is received in insert mode, the character is used for
filtering
*InsertDelete*::
a character is deleted in insert mode, the character deleted by
the main selection is used for filtering
*InsertMove*::
the cursor moved (without inserting) in insert mode, the key that
triggered the move is used for filtering

View File

@ -761,7 +761,7 @@ const CommandDesc remove_highlighter_cmd = {
static constexpr auto hooks = {
"BufCreate", "BufNewFile", "BufOpenFile", "BufClose", "BufWritePost",
"BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption",
"InsertBegin", "InsertChar", "InsertEnd", "InsertIdle", "InsertKey",
"InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey",
"InsertMove", "InsertCompletionHide", "InsertCompletionShow",
"KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError",
"NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "RawKey",

View File

@ -1067,8 +1067,14 @@ public:
auto pos = sel.cursor();
sels.emplace_back(buffer.char_prev(pos));
}
auto& main = context().selections().main();
String main_char = buffer.string(buffer.char_prev(main.cursor()),
main.cursor());
if (not sels.empty())
SelectionList{buffer, std::move(sels)}.erase();
if (not main_char.empty())
context().hooks().run_hook("InsertDelete", main_char, context());
}
else if (key == Key::Delete)
{