Add <a-c> and <a-d> for changing/deleting without yanking

As asked for in #1175
This commit is contained in:
Maxime Coste 2017-07-11 13:49:29 +09:00
parent 42e5d95cd8
commit 81b5de6fd8
3 changed files with 25 additions and 6 deletions

View File

@ -406,6 +406,9 @@ Changes
* `.`: repeat last insert mode change (`i`, `a`, or `c`, including * `.`: repeat last insert mode change (`i`, `a`, or `c`, including
the inserted text) the inserted text)
* `<a-d>`: delete current selection
* `<a-c>`: delete current selection and enter insert mode
* `I`: enter insert mode at current selection begin line start * `I`: enter insert mode at current selection begin line start
* `A`: enter insert mode at current selection end line end * `A`: enter insert mode at current selection end line end
* `o`: enter insert mode in one (or given count) new lines below * `o`: enter insert mode in one (or given count) new lines below

View File

@ -222,6 +222,12 @@ Changes
repeat last insert mode change (*i*, *a*, or *c*, including the repeat last insert mode change (*i*, *a*, or *c*, including the
inserted text) inserted text)
*<a-d>*::
delete current selection (not yanking)
*<a-c>*::
delete current selection and enter insert mode (not yanking)
*I*:: *I*::
enter insert mode at current selection begin line start enter insert mode at current selection begin line start

View File

@ -559,19 +559,27 @@ void yank(Context& context, NormalParams params)
get_face("Information") }); get_face("Information") });
} }
template<bool yank>
void erase_selections(Context& context, NormalParams params) void erase_selections(Context& context, NormalParams params)
{ {
const char reg = params.reg ? params.reg : '"'; if (yank)
RegisterManager::instance()[reg].set(context, context.selections_content()); {
const char reg = params.reg ? params.reg : '"';
RegisterManager::instance()[reg].set(context, context.selections_content());
}
ScopedEdition edition(context); ScopedEdition edition(context);
context.selections().erase(); context.selections().erase();
context.selections().avoid_eol(); context.selections().avoid_eol();
} }
template<bool yank>
void change(Context& context, NormalParams params) void change(Context& context, NormalParams params)
{ {
const char reg = params.reg ? params.reg : '"'; if (yank)
RegisterManager::instance()[reg].set(context, context.selections_content()); {
const char reg = params.reg ? params.reg : '"';
RegisterManager::instance()[reg].set(context, context.selections_content());
}
enter_insert_mode<InsertMode::Replace>(context, params); enter_insert_mode<InsertMode::Replace>(context, params);
} }
@ -1901,8 +1909,10 @@ const HashMap<Key, NormalCmd> keymap{
{ {alt('T')}, {"extend to previous character", select_to_next_char<SelectFlags::Extend | SelectFlags::Reverse>} }, { {alt('T')}, {"extend to previous character", select_to_next_char<SelectFlags::Extend | SelectFlags::Reverse>} },
{ {alt('F')}, {"extend to previous character included", select_to_next_char<SelectFlags::Inclusive | SelectFlags::Extend | SelectFlags::Reverse>} }, { {alt('F')}, {"extend to previous character included", select_to_next_char<SelectFlags::Inclusive | SelectFlags::Extend | SelectFlags::Reverse>} },
{ {'d'}, {"erase selected text", erase_selections} }, { {'d'}, {"erase selected text", erase_selections<true>} },
{ {'c'}, {"change selected text", change} }, { {alt('d')}, {"erase selected text, without yanking", erase_selections<false>} },
{ {'c'}, {"change selected text", change<true>} },
{ {alt('c')}, {"change selected text, without yanking", change<false>} },
{ {'i'}, {"insert before selected text", enter_insert_mode<InsertMode::Insert>} }, { {'i'}, {"insert before selected text", enter_insert_mode<InsertMode::Insert>} },
{ {'I'}, {"insert at line begin", enter_insert_mode<InsertMode::InsertAtLineBegin>} }, { {'I'}, {"insert at line begin", enter_insert_mode<InsertMode::InsertAtLineBegin>} },
{ {'a'}, {"insert after selected text", enter_insert_mode<InsertMode::Append>} }, { {'a'}, {"insert after selected text", enter_insert_mode<InsertMode::Append>} },