Fix prefix completion in prompt
This commit is contained in:
parent
c0973075fa
commit
a0d4a44dd5
|
@ -421,26 +421,40 @@ public:
|
||||||
|
|
||||||
if (candidates.empty())
|
if (candidates.empty())
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
|
bool did_prefix = false;
|
||||||
String prefix = use_common_prefix ? common_prefix(candidates) : String();
|
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())
|
if (m_completions.end - m_completions.start > prefix.length())
|
||||||
prefix = line.substr(m_completions.start,
|
prefix = line.substr(m_completions.start,
|
||||||
m_completions.end - m_completions.start);
|
m_completions.end - m_completions.start);
|
||||||
|
|
||||||
auto it = find(candidates, prefix);
|
if (not prefix.empty())
|
||||||
if (it == candidates.end())
|
|
||||||
{
|
{
|
||||||
m_current_completion = use_common_prefix ? candidates.size() : 0;
|
auto it = find(candidates, prefix);
|
||||||
candidates.push_back(std::move(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())
|
if (not did_prefix)
|
||||||
m_current_completion = 0;
|
{
|
||||||
else if (reverse and --m_current_completion < 0)
|
if (not reverse and ++m_current_completion >= candidates.size())
|
||||||
m_current_completion = candidates.size()-1;
|
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];
|
const String& completion = candidates[m_current_completion];
|
||||||
if (context().has_ui())
|
if (context().has_ui())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user