Skip to content

Commit

Permalink
Fix a crash when completing empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 1, 2021
1 parent f9d3480 commit 8226ae7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/reline/line_editor.rb
Expand Up @@ -1295,8 +1295,10 @@ def editing_mode
end
end
completed = @completion_journey_data.list[@completion_journey_data.pointer]
@line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
new_line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
@line = new_line.nil? ? String.new(encoding: @encoding) : new_line
line_to_pointer = (@completion_journey_data.preposing + completed).split("\n").last
line_to_pointer = String.new(encoding: @encoding) if line_to_pointer.nil?
@cursor_max = calculate_width(@line)
@cursor = calculate_width(line_to_pointer)
@byte_pointer = line_to_pointer.bytesize
Expand Down
13 changes: 13 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Expand Up @@ -823,6 +823,19 @@ def test_completion_journey_2nd_line
EOC
end

def test_completion_journey_with_empty_line
write_inputrc <<~LINES
set editing-mode vi
LINES
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
write("\C-n\C-p")
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt>
EOC
end

def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content
Expand Down

0 comments on commit 8226ae7

Please sign in to comment.