From 59b8b99577ce38bc2b3cad330c1108eeb4faa447 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 12 Nov 2022 12:37:35 +0100 Subject: Accept "cd dir/" again instead of using a subdirectory Commit 69053d962 (Use menu behavior when completing change-directory, 2022-07-19) made ":cd dir/" actually run ":cd dir/first-subdir", which can be surprising. This is usually irrelevant because you rarely type the trailing slash. However it does happen after correcting an error with `` and friends. For for example, :cd d/f results in :cd dir/ We should probably fix user expectations here. Do this by adding "dir/" as valid completion. This requires us to allow empty candidates in "RankedMatch" but there's no harm in that. This means we need to filter out empty completions from shell-script-candidates elsewhere. Alternative fix: we could revert 69053d962. This would remove the convenient menu behavior but that wouldn't be a huge deal. Fixes #4775 --- src/file.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/file.cc') diff --git a/src/file.cc b/src/file.cc index ee358be0..c7092209 100644 --- a/src/file.cc +++ b/src/file.cc @@ -518,6 +518,14 @@ CandidateList complete_filename(StringView prefix, const Regex& ignored_regex, if (RankedMatch match{file, fileprefix}) matches.push_back(match); } + // Hack: when completing directories, also echo back the query if it + // is a valid directory. This enables menu completion to select the + // directory instead of a child. + if (only_dirs and not dirname.empty() and dirname.back() == '/' and fileprefix.empty() + and /* exists on disk */ not files.empty()) + { + matches.push_back(RankedMatch{fileprefix, fileprefix}); + } std::sort(matches.begin(), matches.end()); const bool expand = (flags & FilenameFlags::Expand); return candidates(matches, expand ? parsed_dirname : dirname); -- cgit v1.2.3