Utils/Console: Better directory name completion
g0dil [Fri, 9 Jan 2009 08:54:07 +0000 (08:54 +0000)]
Utils/Termlib: Fix completiion semantics

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1050 270642c3-0616-0410-b53a-bc976706d245

Utils/Console/LineEditor.cc
Utils/Termlib/Editor.cc

index 95f1153..bf4d869 100644 (file)
@@ -144,11 +144,8 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
     ParseCommandInfo::TokensRange path (cmd.commandPath());
     if (path.empty()) {
         DirectoryNode::ChildrenRange cs (client().cwd().children());
-        for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i) {
-            completions.push_back(i->first);
-            if (i->second->isDirectory())
-                completions.push_back(i->first + "/");
-        }
+        for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i)
+            completions.push_back(i->first + (i->second->isDirectory() ? "/" : ""));
         return;
     }
     
@@ -169,17 +166,21 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
             basePath += "../";
         }
         else if (*i == WordToken(".")) 
-            ;
+            basePath += "./";
         else {
             if (dir->hasChild(i->value())) {
-                dir = & dir->getDirectory(i->value());
+                try {
+                    dir = & dir->getDirectory(i->value());
+                }
+                catch (std::bad_cast &) {
+                    return;
+                }
                 basePath += i->value() + "/";
-            } else {
+            } 
+            else {
                 DirectoryNode::ChildrenRange cs (dir->completions(i->value()));
                 if (has_one_elt(cs)) {
                     GenericNode * node (cs.begin()->second.get());
-                    if (node->isLink())
-                        node = & static_cast<LinkNode*>(node)->follow();
                     if (!node->isDirectory())
                         return;
                     dir = static_cast<DirectoryNode*>(node);
@@ -191,11 +192,8 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
         }
 
     DirectoryNode::ChildrenRange cs (dir->completions(i->value()));
-    for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j) {
-        completions.push_back(basePath + j->first);
-        if (j->second->isDirectory())
-            completions.push_back(basePath + j->first + "/");
-    }
+    for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j)
+        completions.push_back(basePath + j->first + (j->second->isDirectory() ? "/" : ""));
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
index e8291a2..8d16f4d 100644 (file)
@@ -663,18 +663,9 @@ prefix_ void senf::term::bindings::complete(LineEditor & editor, Completer compl
         didComplete = true;
     }
 
-    // If completion is already unique, make sure completion is followed by a space and place cursor
-    // after that space
-    if (completions.size() == 1u) {
-        if (text.size() <= commonStart || text[commonStart] != ' ')
-            text.insert(commonStart, " ");
-        editor.set(text, commonStart + 1);
-        return;
-    }
-
-    // Otherwise place cursor directly after the partial completion
+    // Otherwise place cursor directly after the (possibly partial) completion
     editor.set(text, commonStart);
-    if (didComplete)
+    if (didComplete || completions.size() == 1)
         return;
 
     // Text was not changed, show list of possible completions