1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] Remove one unnecessary nest for simplicity's sake

https://github.com/ruby/reline/commit/f4bda85a7c
This commit is contained in:
aycabta 2021-08-31 20:48:58 +09:00 committed by git
parent 64373a3c58
commit 9b188ac238

View file

@ -589,26 +589,7 @@ class Reline::LineEditor
end
dialog.set_cursor_pos(cursor_column, @first_line_started_from + @started_from)
dialog_render_info = dialog.call
old_dialog = dialog.clone
if dialog_render_info and dialog_render_info.contents and not dialog_render_info.contents.empty?
dialog.width = dialog_render_info.width if dialog_render_info.width
height = dialog_render_info.height || DIALOG_HEIGHT
pointer = dialog_render_info.pointer
dialog.contents = dialog_render_info.contents
if dialog.contents.size > height
if dialog_render_info.pointer
if dialog_render_info.pointer < 0
dialog.scroll_top = 0
elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
dialog.scroll_top = dialog_render_info.pointer - (height - 1)
elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
dialog.scroll_top = dialog_render_info.pointer
end
pointer = dialog_render_info.pointer - dialog.scroll_top
end
dialog.contents = dialog.contents[dialog.scroll_top, height]
end
else
if dialog_render_info.nil? or dialog_render_info.contents.nil? or dialog_render_info.contents.empty?
dialog.lines_backup = {
lines: modify_lines(whole_lines),
line_index: @line_index,
@ -620,6 +601,24 @@ class Reline::LineEditor
dialog.contents = nil
return
end
old_dialog = dialog.clone
dialog.width = dialog_render_info.width if dialog_render_info.width
height = dialog_render_info.height || DIALOG_HEIGHT
pointer = dialog_render_info.pointer
dialog.contents = dialog_render_info.contents
if dialog.contents.size > height
if dialog_render_info.pointer
if dialog_render_info.pointer < 0
dialog.scroll_top = 0
elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
dialog.scroll_top = dialog_render_info.pointer - (height - 1)
elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
dialog.scroll_top = dialog_render_info.pointer
end
pointer = dialog_render_info.pointer - dialog.scroll_top
end
dialog.contents = dialog.contents[dialog.scroll_top, height]
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