Skip to content

Commit

Permalink
[ruby/reline] Remove one unnecessary nest for simplicity's sake
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta authored and matzbot committed Aug 31, 2021
1 parent 64373a3 commit 9b188ac
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/reline/line_editor.rb
Expand Up @@ -589,26 +589,7 @@ def add_dialog_proc(name, p, context = nil)
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,
Expand All @@ -620,6 +601,24 @@ def add_dialog_proc(name, p, context = nil)
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
Expand Down

0 comments on commit 9b188ac

Please sign in to comment.