1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-26 13:02:01 +03:00

Add a repeat last insert command, bound to .

This commit is contained in:
Maxime Coste 2011-12-05 14:28:45 +00:00
parent d1cc5da8a6
commit 23eafd4504

View File

@ -272,20 +272,22 @@ void print_status(const std::string& status)
addstr(status.c_str());
}
void do_insert(Window& window, IncrementalInserter::Mode mode)
struct InsertSequence
{
Kakoune::IncrementalInserter inserter(window, mode);
draw_window(window);
while(true)
{
const DisplayCoord& pos = window.cursor_position();
move(pos.line, pos.column);
IncrementalInserter::Mode mode;
std::string keys;
char c = getch();
InsertSequence() : mode(IncrementalInserter::Mode::Insert) {}
};
InsertSequence last_insert_sequence;
bool insert_char(IncrementalInserter& inserter, char c)
{
switch (c)
{
case 27:
return;
return false;
case 2:
c = getch();
@ -309,10 +311,38 @@ void do_insert(Window& window, IncrementalInserter::Mode mode)
default:
inserter.insert(std::string() + c);
}
return true;
}
void do_insert(Window& window, IncrementalInserter::Mode mode)
{
last_insert_sequence.mode = mode;
last_insert_sequence.keys.clear();
IncrementalInserter inserter(window, mode);
draw_window(window);
while(true)
{
char c = getch();
if (not insert_char(inserter, c))
return;
last_insert_sequence.keys += c;
draw_window(window);
}
}
void do_repeat_insert(Window& window, int count)
{
IncrementalInserter inserter(window, last_insert_sequence.mode);
for (char c : last_insert_sequence.keys)
{
insert_char(inserter, c);
}
draw_window(window);
}
template<bool append>
void do_go(Window& window, int count)
{
@ -651,6 +681,9 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 's', do_select_regex },
{ '.', do_repeat_insert },
{ '%', [](Window& window, int count) { window.select([](const BufferIterator& cursor)
{ return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } },