diff --git a/src/completion.cc b/src/completion.cc index a1eed12a..d4e5f04a 100644 --- a/src/completion.cc +++ b/src/completion.cc @@ -7,16 +7,18 @@ namespace Kakoune { -CandidateList complete_filename(const std::string& prefix) +CandidateList complete_filename(const std::string& prefix, + size_t cursor_pos) { - size_t dir_end = prefix.find_last_of('/'); + std::string real_prefix = prefix.substr(0, cursor_pos); + size_t dir_end = real_prefix.find_last_of('/'); std::string dirname = "./"; - std::string fileprefix = prefix; + std::string fileprefix = real_prefix; if (dir_end != std::string::npos) { - dirname = prefix.substr(0, dir_end + 1); - fileprefix = prefix.substr(dir_end + 1, std::string::npos); + dirname = real_prefix.substr(0, dir_end + 1); + fileprefix = real_prefix.substr(dir_end + 1, std::string::npos); } auto dir = auto_raii(opendir(dirname.c_str()), closedir); diff --git a/src/completion.hh b/src/completion.hh index 2607879f..da110638 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -22,7 +22,8 @@ struct Completions : start(start), end(end) {} }; -CandidateList complete_filename(const std::string& prefix); +CandidateList complete_filename(const std::string& prefix, + size_t cursor_pos = std::string::npos); } #endif // completion_hh_INCLUDED