From aeea1c610c5a6e5a8062166919cc5affece8f55d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 16 Sep 2011 09:17:55 +0000 Subject: [PATCH] complete_filename: accept cursor_position as additional parameter --- src/completion.cc | 12 +++++++----- src/completion.hh | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) 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