mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] Ensure that scrollbar is only rerendered when the position is changed
f629853eae
This commit is contained in:
parent
3c77f00965
commit
0ef3d574a0
1 changed files with 21 additions and 16 deletions
|
@ -559,7 +559,7 @@ class Reline::LineEditor
|
||||||
|
|
||||||
class Dialog
|
class Dialog
|
||||||
attr_reader :name, :contents, :width
|
attr_reader :name, :contents, :width
|
||||||
attr_accessor :scroll_top, :column, :vertical_offset, :lines_backup, :trap_key
|
attr_accessor :scroll_top, :scrollbar_pos, :column, :vertical_offset, :lines_backup, :trap_key
|
||||||
|
|
||||||
def initialize(name, config, proc_scope)
|
def initialize(name, config, proc_scope)
|
||||||
@name = name
|
@name = name
|
||||||
|
@ -663,6 +663,15 @@ class Reline::LineEditor
|
||||||
end
|
end
|
||||||
dialog.contents = dialog.contents[dialog.scroll_top, height]
|
dialog.contents = dialog.contents[dialog.scroll_top, height]
|
||||||
end
|
end
|
||||||
|
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
|
||||||
|
bar_max_height = height * 2
|
||||||
|
moving_distance = (dialog_render_info.contents.size - height) * 2
|
||||||
|
position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance)
|
||||||
|
bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
|
||||||
|
dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i
|
||||||
|
else
|
||||||
|
dialog.scrollbar_pos = nil
|
||||||
|
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
|
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
|
||||||
|
@ -682,17 +691,11 @@ class Reline::LineEditor
|
||||||
dialog.vertical_offset = dialog_render_info.pos.y + 1
|
dialog.vertical_offset = dialog_render_info.pos.y + 1
|
||||||
end
|
end
|
||||||
Reline::IOGate.hide_cursor
|
Reline::IOGate.hide_cursor
|
||||||
|
block_elem_size = calculate_width('█')
|
||||||
|
dialog.width += block_elem_size if dialog.scrollbar_pos
|
||||||
reset_dialog(dialog, old_dialog)
|
reset_dialog(dialog, old_dialog)
|
||||||
move_cursor_down(dialog.vertical_offset)
|
move_cursor_down(dialog.vertical_offset)
|
||||||
Reline::IOGate.move_cursor_column(dialog.column)
|
Reline::IOGate.move_cursor_column(dialog.column)
|
||||||
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
|
|
||||||
bar_max_height = height * 2
|
|
||||||
moving_distance = (dialog_render_info.contents.size - height) * 2
|
|
||||||
position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance)
|
|
||||||
bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
|
|
||||||
position = ((bar_max_height - bar_height) * position_ratio).floor.to_i
|
|
||||||
end
|
|
||||||
block_elem_size = calculate_width('█')
|
|
||||||
dialog.contents.each_with_index do |item, i|
|
dialog.contents.each_with_index do |item, i|
|
||||||
if i == pointer
|
if i == pointer
|
||||||
bg_color = '45'
|
bg_color = '45'
|
||||||
|
@ -703,16 +706,16 @@ class Reline::LineEditor
|
||||||
bg_color = '46'
|
bg_color = '46'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, dialog.width), dialog.width)
|
str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, dialog.width - block_elem_size), dialog.width - block_elem_size)
|
||||||
@output.write "\e[#{bg_color}m#{str}"
|
@output.write "\e[#{bg_color}m#{str}"
|
||||||
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
|
if dialog.scrollbar_pos and dialog.scrollbar_pos != old_dialog.scrollbar_pos
|
||||||
@output.write "\e[37m"
|
@output.write "\e[37m"
|
||||||
if position <= (i * 2) and (i * 2 + block_elem_size) < (position + bar_height)
|
if dialog.scrollbar_pos <= (i * 2) and (i * 2 + block_elem_size) < (dialog.scrollbar_pos + bar_height)
|
||||||
@output.write '█'
|
@output.write '█'
|
||||||
elsif position <= (i * 2) and (i * 2) < (position + bar_height)
|
elsif dialog.scrollbar_pos <= (i * 2) and (i * 2) < (dialog.scrollbar_pos + bar_height)
|
||||||
@output.write '▀'
|
@output.write '▀'
|
||||||
str += ''
|
str += ''
|
||||||
elsif position <= (i * 2 + block_elem_size) and (i * 2) < (position + bar_height)
|
elsif dialog.scrollbar_pos <= (i * 2 + block_elem_size) and (i * 2) < (dialog.scrollbar_pos + bar_height)
|
||||||
@output.write '▄'
|
@output.write '▄'
|
||||||
else
|
else
|
||||||
@output.write ' ' * block_elem_size
|
@output.write ' ' * block_elem_size
|
||||||
|
@ -723,7 +726,6 @@ class Reline::LineEditor
|
||||||
Reline::IOGate.move_cursor_column(dialog.column)
|
Reline::IOGate.move_cursor_column(dialog.column)
|
||||||
move_cursor_down(1) if i < (dialog.contents.size - 1)
|
move_cursor_down(1) if i < (dialog.contents.size - 1)
|
||||||
end
|
end
|
||||||
dialog.width += block_elem_size if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
|
|
||||||
Reline::IOGate.move_cursor_column(cursor_column)
|
Reline::IOGate.move_cursor_column(cursor_column)
|
||||||
move_cursor_up(dialog.vertical_offset + dialog.contents.size - 1)
|
move_cursor_up(dialog.vertical_offset + dialog.contents.size - 1)
|
||||||
Reline::IOGate.show_cursor
|
Reline::IOGate.show_cursor
|
||||||
|
@ -808,7 +810,10 @@ class Reline::LineEditor
|
||||||
end
|
end
|
||||||
move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
|
move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
|
||||||
end
|
end
|
||||||
if (old_dialog.column + old_dialog.width) > (dialog.column + dialog.width)
|
old_dialog_scrollbar = old_dialog.scrollbar_pos.nil? ? 0 : calculate_width('█')
|
||||||
|
dialog_scrollbar = dialog.scrollbar_pos.nil? ? 0 : calculate_width('█')
|
||||||
|
if (old_dialog.column + old_dialog.width - old_dialog_scrollbar) > (dialog.column + dialog.width - dialog_scrollbar)
|
||||||
|
$stderr.puts "RIGHT #{old_dialog.column} #{old_dialog.width} #{old_dialog_scrollbar} #{dialog.column} #{dialog.width} #{dialog_scrollbar}"
|
||||||
# rerender right
|
# rerender right
|
||||||
move_cursor_down(old_dialog.vertical_offset + y_diff)
|
move_cursor_down(old_dialog.vertical_offset + y_diff)
|
||||||
width = (old_dialog.column + old_dialog.width) - (dialog.column + dialog.width)
|
width = (old_dialog.column + old_dialog.width) - (dialog.column + dialog.width)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue