[ruby/reline] Remove unnecessary variables, lower_space

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.

https://github.com/ruby/reline/commit/a575cef6a3
This commit is contained in:
aycabta 2021-12-08 01:44:18 +09:00 committed by git
parent 446a11f2c1
commit 8411e8449b
2 changed files with 22 additions and 3 deletions

View File

@ -706,19 +706,18 @@ class Reline::LineEditor
dialog.scrollbar_pos = nil dialog.scrollbar_pos = nil
end end
upper_space = @first_line_started_from - @started_from 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.column = dialog_render_info.pos.x
dialog.width += @block_elem_width if dialog.scrollbar_pos dialog.width += @block_elem_width if dialog.scrollbar_pos
diff = (dialog.column + dialog.width) - (@screen_size.last) diff = (dialog.column + dialog.width) - (@screen_size.last)
if diff > 0 if diff > 0
dialog.column -= diff dialog.column -= diff
end 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 dialog.vertical_offset = dialog_render_info.pos.y + 1
elsif upper_space >= height elsif upper_space >= height
dialog.vertical_offset = dialog_render_info.pos.y - height dialog.vertical_offset = dialog_render_info.pos.y - height
else 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) scroll_down(height + dialog_render_info.pos.y)
move_cursor_up(height + dialog_render_info.pos.y) move_cursor_up(height + dialog_render_info.pos.y)
end end

View File

@ -1197,6 +1197,26 @@ begin
EOC EOC
end 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) def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f| File.open(@inputrc_file, 'w') do |f|
f.write content f.write content