summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-25 20:28:26 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-25 20:28:26 +1100
commit59c883d02f4841bdc0e0028bd77886d3f07a3a68 (patch)
treeaa0d6ac67974a3eb52d545bba51479fef0e3354c /src
parent6d3fe30bf67b01e3a49fac634e888ea19af90d8f (diff)
Avoid visiting the same directory multiple times in insert filename completion
Diffstat (limited to 'src')
-rw-r--r--src/insert_completer.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index f5e65774..542a1b8a 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -239,16 +239,17 @@ InsertCompletion complete_filename(const SelectionList& sels,
}
else
{
+ Vector<String> visited_dirs;
for (auto dir : options["path"].get<StringList>())
{
+ dir = real_path(parse_filename(dir, (buffer.flags() & Buffer::Flags::File) ?
+ split_path(buffer.name()).first : StringView{}));
+
if (not dir.empty() and dir.back() != '/')
dir += '/';
- if (dir.substr(0, 2_byte) == "%/")
- {
- if (not (buffer.flags() & Buffer::Flags::File))
- continue;
- dir = split_path(buffer.name()).first.str() + '/' + dir.substr(2_byte);
- }
+
+ if (contains(visited_dirs, dir))
+ continue;
for (auto& filename : Kakoune::complete_filename(dir + prefix,
options["ignored_files"].get<Regex>()))
@@ -256,6 +257,8 @@ InsertCompletion complete_filename(const SelectionList& sels,
StringView candidate = filename.substr(dir.length());
candidates.push_back({ candidate.str(), "", candidate.str() });
}
+
+ visited_dirs.push_back(std::move(dir));
}
}
if (candidates.empty())