diff options
author | aycabta <aycabta@gmail.com> | 2020-11-20 17:13:15 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2020-12-05 02:58:59 +0900 |
commit | b763c5cdf09fab247a7ca9526bb27a63cf03a81d (patch) | |
tree | fcba1053e8e24d0c2fb37322c7496a564a979435 /lib/reline/line_editor.rb | |
parent | a297565a4e873b9de079510bca011dc3bb2fdf78 (diff) | |
download | ruby-b763c5cdf09fab247a7ca9526bb27a63cf03a81d.tar.gz |
[ruby/reline] Stop rerendering if the cursor is only moved
https://github.com/ruby/reline/commit/30e8eaf855
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 543df2b113..fc7e576f26 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -59,6 +59,8 @@ class Reline::LineEditor def simplified_rendering? if finished? false + elsif @just_cursor_moving and not @rerender_all + true else not @rerender_all and not finished? and Reline::IOGate.in_pasting? end @@ -188,6 +190,7 @@ class Reline::LineEditor @searching_prompt = nil @first_char = true @add_newline_to_end_of_buffer = false + @just_cursor_moving = false @eof = false @continuous_insertion_buffer = String.new(encoding: @encoding) reset_line @@ -335,6 +338,10 @@ class Reline::LineEditor if @add_newline_to_end_of_buffer rerender_added_newline @add_newline_to_end_of_buffer = false + elsif @just_cursor_moving and not @rerender_all + just_move_cursor + @just_cursor_moving = false + return elsif @previous_line_index or new_highest_in_this != @highest_in_this rerender_changed_current_line @previous_line_index = nil @@ -382,6 +389,25 @@ class Reline::LineEditor @previous_line_index = nil end + def just_move_cursor + prompt, prompt_width, prompt_list = check_multiline_prompt(@buffer_of_lines, prompt) + move_cursor_up(@started_from) + new_first_line_started_from = + if @line_index.zero? + 0 + else + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt) + end + @line = @buffer_of_lines[@line_index] + move_cursor_down(new_first_line_started_from - @first_line_started_from) + @first_line_started_from = new_first_line_started_from + calculate_nearest_cursor + @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 + move_cursor_down(@started_from) + Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @previous_line_index = nil + end + private def rerender_changed_current_line if @previous_line_index new_lines = whole_lines(index: @previous_line_index, line: @line) @@ -923,6 +949,13 @@ class Reline::LineEditor unless completion_occurs @completion_state = CompletionState::NORMAL end + unless Reline::IOGate.in_pasting? + if @previous_line_index and @buffer_of_lines[@previous_line_index] == @line + @just_cursor_moving = true + elsif @previous_line_index.nil? and @buffer_of_lines[@line_index] == @line + @just_cursor_moving = true + end + end if @is_multiline and @auto_indent_proc and not simplified_rendering? process_auto_indent end |