Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion dialog position when completed part is word wrapped #692

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,20 @@ def get_screen_size
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)
Expand Down
31 changes: 30 additions & 1 deletion test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,36 @@ def test_autocomplete_target_is_wrapped
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
Expand Down
Loading