summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-10-14 23:29:17 +0900
committeraycabta <aycabta@gmail.com>2020-12-05 02:58:58 +0900
commit4af2e4111b0e351464a62c73e4ea0ef8b27c43f5 (patch)
tree9be60f1bc46f855afbada50700188a5e9037e4f1
parente16e481385743666443e162141116b46416cb10d (diff)
downloadruby-4af2e4111b0e351464a62c73e4ea0ef8b27c43f5.tar.gz
[ruby/reline] Deduplicate completed items
https://github.com/ruby/reline/commit/2dabf0c786
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--test/reline/test_key_actor_emacs.rb30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 9bdccae9c9..e5ecc8bbcb 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -565,7 +565,7 @@ class Reline::LineEditor
else
i&.start_with?(target)
end
- }
+ }.uniq
if is_menu
menu(target, list)
return nil
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index a1e4015999..7bb5ac3141 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -1281,6 +1281,36 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_equal(%w{foo_foo foo_bar foo_baz}, @line_editor.instance_variable_get(:@menu_info).list)
end
+ def test_completion_duplicated_list
+ @line_editor.completion_proc = proc { |word|
+ %w{
+ foo_foo
+ foo_foo
+ foo_bar
+ }.map { |i|
+ i.encode(@encoding)
+ }
+ }
+ input_keys('foo_')
+ assert_byte_pointer_size('foo_')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('foo_')
+ assert_equal(nil, @line_editor.instance_variable_get(:@menu_info))
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('foo_')
+ assert_equal(nil, @line_editor.instance_variable_get(:@menu_info))
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('foo_')
+ assert_equal(%w{foo_foo foo_bar}, @line_editor.instance_variable_get(:@menu_info).list)
+ end
+
def test_completion
@line_editor.completion_proc = proc { |word|
%w{