Removed a bug when inserting a char in the middle of the pattern.
authorFrancois Fleuret <francois@fleuret.org>
Mon, 6 Apr 2009 19:31:43 +0000 (21:31 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Mon, 6 Apr 2009 19:31:43 +0000 (21:31 +0200)
selector.cc

index b84bd79..c936029 100644 (file)
@@ -755,18 +755,15 @@ int main(int argc, char **argv) {
     if(key >= ' ' && key <= '~') { // Insert character
       int c = cursor_position;
       char t = pattern[c], u;
-      if(t) {
-        while(t) {
-          c++;
-          u = pattern[c];
-          pattern[c] = t;
-          t = u;
-        }
-        pattern[cursor_position++] = key;
-      } else {
-        pattern[cursor_position++] = key;
-        pattern[cursor_position] = '\0';
+      while(t) {
+        c++;
+        u = pattern[c];
+        pattern[c] = t;
+        t = u;
       }
+      c++;
+      pattern[c] = '\0';
+      pattern[cursor_position++] = key;
     }
 
     else if(key == KEY_BACKSPACE || key == '\b' || key == '\7f') {