summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-12-21 12:48:13 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-12-23 20:43:29 +0000
commita0d4a44dd55c7d910865a459a2c73738d98c32cf (patch)
treea26d03c8c275ad15b5cdbb9de0c8adc3acf5dfde /src/input_handler.cc
parentc0973075fafc7003be1028922bf99a2c48bcdcd6 (diff)
Fix prefix completion in prompt
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index c68c0c76..34e30f45 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -421,26 +421,40 @@ public:
if (candidates.empty())
return;
-
- bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
- String prefix = use_common_prefix ? common_prefix(candidates) : String();
+ }
+ bool did_prefix = false;
+ if (m_current_completion == -1 and
+ context().options()["complete_prefix"].get<bool>())
+ {
+ const String& line = m_line_editor.line();
+ CandidateList& candidates = m_completions.candidates;
+ String prefix = common_prefix(candidates);
if (m_completions.end - m_completions.start > prefix.length())
prefix = line.substr(m_completions.start,
m_completions.end - m_completions.start);
- auto it = find(candidates, prefix);
- if (it == candidates.end())
+ if (not prefix.empty())
{
- m_current_completion = use_common_prefix ? candidates.size() : 0;
- candidates.push_back(std::move(prefix));
+ auto it = find(candidates, prefix);
+ if (it == candidates.end())
+ {
+ m_current_completion = candidates.size();
+ candidates.push_back(prefix);
+ }
+ else
+ m_current_completion = it - candidates.begin();
+
+ CharCount start = line.char_count_to(m_completions.start);
+ did_prefix = prefix != line.substr(start, m_line_editor.cursor_pos() - start);
}
- else
- m_current_completion = use_common_prefix ? it - candidates.begin() : 0;
}
- else if (not reverse and ++m_current_completion >= candidates.size())
- m_current_completion = 0;
- else if (reverse and --m_current_completion < 0)
- m_current_completion = candidates.size()-1;
+ if (not did_prefix)
+ {
+ if (not reverse and ++m_current_completion >= candidates.size())
+ m_current_completion = 0;
+ else if (reverse and --m_current_completion < 0)
+ m_current_completion = candidates.size()-1;
+ }
const String& completion = candidates[m_current_completion];
if (context().has_ui())