diff options
| author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-05-01 01:51:21 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-04-30 16:51:25 +0000 |
| commit | 614187f8c284ef9adfca8a6fa91a0ae58889eff2 (patch) | |
| tree | 7487f3b1b9e1406b70ccd5d2675915b693d39c37 | |
| parent | d7ba0fec492823f5191a34be5fe4b8e0b5641f07 (diff) | |
[ruby/reline] Fix completion dialog position when completed part is
wordwrapped
(https://github.com/ruby/reline/pull/692)
https://github.com/ruby/reline/commit/2d9acd16fe
| -rw-r--r-- | lib/reline.rb | 13 | ||||
| -rw-r--r-- | test/reline/yamatanooroti/test_rendering.rb | 31 |
2 files changed, 38 insertions, 6 deletions
diff --git a/lib/reline.rb b/lib/reline.rb index f0060f5c9c..0a266b9c58 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -225,17 +225,20 @@ module Reline journey_data = completion_journey_data return unless journey_data - target = journey_data.list[journey_data.pointer] + target = journey_data.list.first + completed = journey_data.list[journey_data.pointer] result = journey_data.list.drop(1) pointer = journey_data.pointer - 1 - return if target.empty? || (result == [target] && pointer < 0) + return if completed.empty? || (result == [completed] && pointer < 0) target_width = Reline::Unicode.calculate_width(target) - x = cursor_pos.x - target_width - if x < 0 - x = screen_width + x + completed_width = Reline::Unicode.calculate_width(completed) + if cursor_pos.x <= completed_width - target_width + # When target is rendered on the line above cursor position + x = screen_width - completed_width y = -1 else + x = [cursor_pos.x - completed_width, 0].max y = 0 end cursor_pos_to_render = Reline::CursorPos.new(x, y) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index aa6fbe0dbd..74798c338f 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -1185,7 +1185,36 @@ begin assert_screen(<<~'EOC') Multiline REPL. prompt> St - r String + r + String + Struct + EOC + end + + def test_autocomplete_target_at_end_of_line + start_terminal(20, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.') + write(' ') + write('Str') + write("\C-i") + close + assert_screen(<<~'EOC') + Multiline REPL. + prompt> Str + ing String + Struct + EOC + end + + def test_autocomplete_completed_input_is_wrapped + start_terminal(20, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.') + write(' ') + write('Str') + write("\C-i") + close + assert_screen(<<~'EOC') + Multiline REPL. + prompt> Stri + ng String Struct EOC end |
