Completions: complete_filename correctly support directories

This commit is contained in:
Maxime Coste 2011-12-22 13:44:04 +00:00
parent 6fa5d809ef
commit aa1c4d64f9

View File

@ -14,11 +14,13 @@ CandidateList complete_filename(const std::string& prefix,
std::string real_prefix = prefix.substr(0, cursor_pos); std::string real_prefix = prefix.substr(0, cursor_pos);
size_t dir_end = real_prefix.find_last_of('/'); size_t dir_end = real_prefix.find_last_of('/');
std::string dirname = "./"; std::string dirname = "./";
std::string dirprefix;
std::string fileprefix = real_prefix; std::string fileprefix = real_prefix;
if (dir_end != std::string::npos) if (dir_end != std::string::npos)
{ {
dirname = real_prefix.substr(0, dir_end + 1); dirname = real_prefix.substr(0, dir_end + 1);
dirprefix = dirname;
fileprefix = real_prefix.substr(dir_end + 1, std::string::npos); fileprefix = real_prefix.substr(dir_end + 1, std::string::npos);
} }
@ -29,7 +31,12 @@ CandidateList complete_filename(const std::string& prefix,
{ {
std::string filename = entry->d_name; std::string filename = entry->d_name;
if (filename.substr(0, fileprefix.length()) == fileprefix) if (filename.substr(0, fileprefix.length()) == fileprefix)
result.push_back(filename); {
std::string name = dirprefix + filename;
if (entry->d_type == DT_DIR)
name += '/';
result.push_back(name);
}
} }
return result; return result;
} }