summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-09-12 19:09:27 +0200
committerMaxime Coste <frrrwww@gmail.com>2012-09-12 19:09:27 +0200
commit6f6f10c83d78ceca047fdb9b6b35906feca06927 (patch)
tree292fe706d7e7551bcbe54dd0da0edb096f5c08fa /src
parentec579900609053ec828c68543fd72c2111dfde88 (diff)
simplify tab completion code in Client::InsertMode
Diffstat (limited to 'src')
-rw-r--r--src/client.cc23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/client.cc b/src/client.cc
index c9b0eafe..b7562ada 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -226,11 +226,12 @@ public:
+ m_result.substr(m_cursor_pos, String::npos);
m_cursor_pos += reg.length();
}
- else if (key == Key(Key::Modifiers::Control, 'i') or // tab
+ else if (key == Key(Key::Modifiers::Control, 'i') or // tab completion
key == Key::BackTab)
{
const bool reverse = (key == Key::BackTab);
- const CandidateList& candidates = m_completions.candidates;
+ CandidateList& candidates = m_completions.candidates;
+ // first try, we need to ask our completer for completions
if (m_current_completion == -1)
{
m_completions = m_completer(context, m_result, m_cursor_pos);
@@ -239,19 +240,17 @@ public:
m_client.menu_hide();
m_client.menu_show(candidates);
- m_completion_prefix = m_result.substr(m_completions.start,
- m_completions.end - m_completions.start);
- m_completion_count = contains(candidates, m_completion_prefix) ?
- (int)candidates.size() : (int)candidates.size() + 1;
+ String prefix = m_result.substr(m_completions.start,
+ m_completions.end - m_completions.start);
+ if (not contains(candidates, prefix))
+ candidates.push_back(std::move(prefix));
}
- if (not reverse and ++m_current_completion >= m_completion_count)
+ if (not reverse and ++m_current_completion >= candidates.size())
m_current_completion = 0;
if (reverse and --m_current_completion < 0)
- m_current_completion = m_completion_count-1;
-
- String completion = (m_current_completion == candidates.size()) ?
- m_completion_prefix : candidates[m_current_completion];
+ m_current_completion = candidates.size()-1;
+ const String& completion = candidates[m_current_completion];
m_client.menu_select(m_current_completion);
m_result = m_result.substr(0, m_completions.start) + completion;
m_cursor_pos = m_completions.start + completion.length();
@@ -272,9 +271,7 @@ private:
const String m_prompt;
CharCount m_cursor_pos = 0;
Completions m_completions;
- int m_completion_count = 0;
int m_current_completion = -1;
- String m_completion_prefix;
String m_result;
String m_saved_result;