]> git.lizzy.rs Git - linenoise.git/commitdiff
New feature: Extended character transpose (Ctrl+t) at end of the line.
authorAndreas Kupries <akupries@shaw.ca>
Fri, 25 Jan 2013 21:12:52 +0000 (13:12 -0800)
committerSteve Bennett <steveb@workware.net.au>
Fri, 15 Feb 2013 02:51:08 +0000 (12:51 +1000)
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

index 21f62f5061b6250203062642b2d9224db3768eaf..92cb5ef1aca5c5df565b20bfdb5c87b6d3ba4101 100644 (file)
@@ -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);
             }