Support getting back to original prefix with tab/shift-tab in prompts
Fixes #124
This commit is contained in:
parent
b02883a112
commit
b0d72ebce0
|
@ -765,7 +765,8 @@ public:
|
||||||
if (candidates.empty())
|
if (candidates.empty())
|
||||||
{
|
{
|
||||||
refresh_completions(CompletionFlags::None);
|
refresh_completions(CompletionFlags::None);
|
||||||
if (candidates.size() > 1)
|
if ((not m_prefix_in_completions and candidates.size() > 1) or
|
||||||
|
candidates.size() > 2)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,7 +787,8 @@ public:
|
||||||
|
|
||||||
// when we have only one completion candidate, make next tab complete
|
// when we have only one completion candidate, make next tab complete
|
||||||
// from the new content.
|
// from the new content.
|
||||||
if (candidates.size() == 1)
|
if (candidates.size() == 1 or
|
||||||
|
(m_prefix_in_completions and candidates.size() == 2))
|
||||||
{
|
{
|
||||||
m_current_completion = -1;
|
m_current_completion = -1;
|
||||||
candidates.clear();
|
candidates.clear();
|
||||||
|
@ -845,6 +847,15 @@ private:
|
||||||
for (auto& candidate : m_completions.candidates)
|
for (auto& candidate : m_completions.candidates)
|
||||||
items.push_back({ candidate, {} });
|
items.push_back({ candidate, {} });
|
||||||
context().client().menu_show(items, {}, MenuStyle::Prompt);
|
context().client().menu_show(items, {}, MenuStyle::Prompt);
|
||||||
|
|
||||||
|
auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start);
|
||||||
|
if (not contains(m_completions.candidates, prefix))
|
||||||
|
{
|
||||||
|
m_completions.candidates.push_back(prefix.str());
|
||||||
|
m_prefix_in_completions = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_prefix_in_completions = false;
|
||||||
}
|
}
|
||||||
} catch (runtime_error&) {}
|
} catch (runtime_error&) {}
|
||||||
}
|
}
|
||||||
|
@ -876,6 +887,7 @@ private:
|
||||||
Face m_prompt_face;
|
Face m_prompt_face;
|
||||||
Completions m_completions;
|
Completions m_completions;
|
||||||
int m_current_completion = -1;
|
int m_current_completion = -1;
|
||||||
|
bool m_prefix_in_completions = false;
|
||||||
String m_prefix;
|
String m_prefix;
|
||||||
LineEditor m_line_editor;
|
LineEditor m_line_editor;
|
||||||
bool m_autoshowcompl;
|
bool m_autoshowcompl;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user