diff --git a/Utils/Console/LineEditor.cc b/Utils/Console/LineEditor.cc index 95f1153b706f5fea45e4fe347b9929bfe77e153f..bf4d86936ca0d940b7a8c10c6db6d2dd2e027b29 100644 --- a/Utils/Console/LineEditor.cc +++ b/Utils/Console/LineEditor.cc @@ -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//////////////////////////////////////// diff --git a/Utils/Termlib/Editor.cc b/Utils/Termlib/Editor.cc index e8291a2e9f1530f9ed11f5ef331324638671353c..8d16f4db9d923eecec3450ce1aee9253417a7e42 100644 --- a/Utils/Termlib/Editor.cc +++ b/Utils/Termlib/Editor.cc @@ -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