From 75abbdf96c241e888687dfcaa4f111ba67cfabd5 Mon Sep 17 00:00:00 2001 From: Andreas Kupries Date: Fri, 25 Jan 2013 13:12:52 -0800 Subject: [PATCH] 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. --- linenoise.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); } -- 2.44.0