Skip to content

Commit

Permalink
Remove unnecessary variables, lower_space
Browse files Browse the repository at this point in the history
The number of lines below the cursor position was known by
"@rest_height" alone, but the problem was caused by adding
"lower_space". Remove "lower_space" as it is unnecessary.
  • Loading branch information
aycabta committed Dec 7, 2021
1 parent ad67f02 commit a575cef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,18 @@ def add_dialog_proc(name, p, context = nil)
dialog.scrollbar_pos = nil
end
upper_space = @first_line_started_from - @started_from
lower_space = @highest_in_all - @first_line_started_from - @started_from - 1
dialog.column = dialog_render_info.pos.x
dialog.width += @block_elem_width if dialog.scrollbar_pos
diff = (dialog.column + dialog.width) - (@screen_size.last)
if diff > 0
dialog.column -= diff
end
if (lower_space + @rest_height - dialog_render_info.pos.y) >= height
if (@rest_height - dialog_render_info.pos.y) >= height
dialog.vertical_offset = dialog_render_info.pos.y + 1
elsif upper_space >= height
dialog.vertical_offset = dialog_render_info.pos.y - height
else
if (lower_space + @rest_height - dialog_render_info.pos.y) < height
if (@rest_height - dialog_render_info.pos.y) < height
scroll_down(height + dialog_render_info.pos.y)
move_cursor_up(height + dialog_render_info.pos.y)
end
Expand Down
20 changes: 20 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,26 @@ def test_autocomplete_old_dialog_width_greater_than_dialog_width
EOC
end

def test_bottom
start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write("\n\n\n\n\n\n")
write("def hoge\n\n\n\n\n\n\nend\C-p\C-p\C-p\C-e")
write(" S")
close
assert_screen(<<~'EOC')
prompt> def hoge
prompt>
prompt>
prompt>
prompt> S
prompt> String
prompt> Struct
prompt> enSymbol
ScriptError
Signal
EOC
end

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

0 comments on commit a575cef

Please sign in to comment.