File tree 2 files changed +14
-4
lines changed 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -216,8 +216,8 @@ def down
216
216
217
217
# n is 1-indexed selection
218
218
# n == 0 if "Done" was selected in @multiple mode
219
- sig { params ( n : Integer ) . void }
220
- def select_n ( n )
219
+ sig { params ( n : Integer , final : T :: Boolean ) . void }
220
+ def select_n ( n , final : false )
221
221
if @multiple
222
222
if n == 0
223
223
@answer = [ ]
@@ -230,7 +230,7 @@ def select_n(n)
230
230
end
231
231
elsif n == 0
232
232
# Ignore pressing "0" when not in multiple mode
233
- elsif should_enter_select_mode? ( n )
233
+ elsif ! final && should_enter_select_mode? ( n )
234
234
# When we have more than 9 options, we need to enter select mode
235
235
# to avoid pre-selecting (e.g) 1 when the user wanted 10.
236
236
# This also applies to 2 and 20+ options, 3/30+, etc.
@@ -302,7 +302,7 @@ def select_current
302
302
# Prevent selection of invisible options
303
303
return unless presented_options . any? { |_ , num | num == @active }
304
304
305
- select_n ( @active )
305
+ select_n ( @active , final : true )
306
306
end
307
307
308
308
sig { void }
Original file line number Diff line number Diff line change @@ -37,6 +37,16 @@ def test_interactive_options_with_more_than_9_options_doesnt_enter_select_mode_w
37
37
assert_output_includes ( 'You chose: 2' )
38
38
end
39
39
40
+ def test_interactive_options_with_more_than_9_options_allows_enter
41
+ run_in_process ( <<~RUBY )
42
+ options = ("a".."j").map { |o| o + " was selected"}
43
+ CLI::UI::Prompt.ask('question', options: options)
44
+ RUBY
45
+
46
+ write ( "\n " ) # Choose option 1
47
+ assert_output_includes ( 'a was selected' )
48
+ end
49
+
40
50
# ^C is not handled; raises Interrupt, which may be handled by caller.
41
51
def test_confirm_sigint
42
52
jruby_skip ( 'SIGINT shuts down the JVM instead of raising Interrupt' )
You can’t perform that action at this time.
0 commit comments