From: Andreas Kupries Date: Fri, 25 Jan 2013 21:12:52 +0000 (-0800) Subject: New feature: Extended character transpose (Ctrl+t) at end of the line. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=75abbdf96c241e888687dfcaa4f111ba67cfabd5;p=linenoise.git New feature: Extended character transpose (Ctrl+t) at end of the line. Bash is able to transpose characters with the cursor after the last character. It simply transposes the last two. Added this behavior to linenoise. --- diff --git a/linenoise.c b/linenoise.c index 21f62f5..92cb5ef 100644 --- a/linenoise.c +++ b/linenoise.c @@ -1122,9 +1122,11 @@ process_char: } break; case ctrl('T'): /* ctrl-t */ - if (current->pos > 0 && current->pos < current->chars) { - c = get_char(current, current->pos); - remove_char(current, current->pos); + if (current->pos > 0 && current->pos <= current->chars) { + /* If cursor is at end, transpose the previous two chars */ + int fixer = (current->pos == current->chars); + c = get_char(current, current->pos - fixer); + remove_char(current, current->pos - fixer); insert_char(current, current->pos - 1, c); refreshLine(current->prompt, current); }