summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-10-20 21:05:49 +1100
committerMaxime Coste <mawww@kakoune.org>2020-10-20 21:43:34 +1100
commit354cfd3b8f3a93145b6f1b248bb1d047336d2e48 (patch)
tree1e1e46af2cead61b09cf33a661e0a9d838c68329 /src/input_handler.cc
parent4d22b405d658ca2111889bfb303fdcbf778e7cd2 (diff)
Disable auto-insertion of menu completion when no text was entered
This avoids a frustrating behaviour where Kakoune autoinserts the first command name when hitting <space> after a ; in a command line. It also fixes the empty prompt case that was auto-completed instead of executing the default command.
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index ea3efb81..f4376ae2 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -771,11 +771,16 @@ public:
{
const String& line = m_line_editor.line();
+ auto can_auto_insert_completion = [&] {
+ const bool has_completions = not m_completions.candidates.empty();
+ const bool completion_selected = m_current_completion != -1;
+ const bool text_entered = m_completions.start != line.byte_count_to(m_line_editor.cursor_pos());
+ return has_completions and not completion_selected and text_entered;
+ };
+
if (key == Key::Return)
{
- if ((m_completions.flags & Completions::Flags::Menu) and
- m_current_completion == -1 and
- not m_completions.candidates.empty())
+ if ((m_completions.flags & Completions::Flags::Menu) and can_auto_insert_completion())
{
const String& completion = m_completions.candidates.front();
m_line_editor.insert_from(line.char_count_to(m_completions.start),
@@ -976,7 +981,7 @@ public:
{
try
{
- m_line_editor.reset(expand(m_line_editor.line(), context()), m_empty_text);
+ m_line_editor.reset(expand(line, context()), m_empty_text);
}
catch (std::runtime_error& error)
{
@@ -993,12 +998,10 @@ public:
{
if (key == ' ' and
(m_completions.flags & Completions::Flags::Menu) and
- not (m_completions.flags & Completions::Flags::Quoted) and
- m_current_completion == -1 and not m_completions.candidates.empty())
- {
+ not (m_completions.flags & Completions::Flags::Quoted) and // if token is quoted, this space does not end it
+ can_auto_insert_completion())
m_line_editor.insert_from(line.char_count_to(m_completions.start),
m_completions.candidates.front());
- }
m_line_editor.handle_key(key);
clear_completions();