diff -r ae5b486f6882 -r 8f1a6f40d1b4 sources/interface.cpp --- a/sources/interface.cpp Tue Dec 16 00:17:15 2014 +0200 +++ b/sources/interface.cpp Tue Dec 16 00:52:39 2014 +0200 @@ -63,6 +63,7 @@ static IPAddress g_address; static String g_statusBarText; static StringList g_playerNames; +static String g_pasteBuffer; // ------------------------------------------------------------------------------------------------- // @@ -627,6 +628,23 @@ // ------------------------------------------------------------------------------------------------- // +static FUNCTION +interface_yank_and_delete (int a, int b) -> void +{ + if (a >= b) + return; + + if (g_cursor > a and g_cursor <= b) + g_cursor = a; + + String& input = mutable_current_input(); + g_pasteBuffer = input.mid (a, b); + input.remove (a, b - a); + g_needInputRender = true; +} + +// ------------------------------------------------------------------------------------------------- +// FUNCTION Interface::handle_input() -> void { @@ -763,32 +781,28 @@ case 'U' - 'A' + 1: // readline ^U - delete from start to cursor if (g_cursor > 0) { - mutable_current_input().remove (0, g_cursor); + interface_yank_and_delete (0, g_cursor); g_cursor = 0; - g_needInputRender = true; } break; case 'K' - 'A' + 1: // readline ^K - delete from cursor to end - if (g_cursor < current_input().length()) - { - String& input = mutable_current_input(); - input.remove (g_cursor, input.length() - g_cursor); - g_needInputRender = true; - } + interface_yank_and_delete (g_cursor, mutable_current_input().length()); break; case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current - { - int start = interface_find_previous_word(); + interface_yank_and_delete (interface_find_previous_word(), g_cursor); + break; - if (start != g_cursor) - { - mutable_current_input().remove (start, g_cursor - start); - g_cursor = start; - g_needInputRender = true; - } + case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text + if (not g_pasteBuffer.is_empty()) + { + mutable_current_input().insert (g_cursor, g_pasteBuffer); + g_cursor += g_pasteBuffer.length(); + g_needInputRender = true; } + else + print ("paste buffer is empty\n"); break; case '\n': @@ -865,8 +879,7 @@ case 'd': case 'D': // readline alt-d - delete from here till next word boundary - mutable_current_input().remove (g_cursor, interface_find_next_word() - g_cursor); - g_needInputRender = true; + interface_yank_and_delete (g_cursor, interface_find_next_word()); break; } }