Skip to content

Commit 30e8eaf

Browse files
committed
Stop rerendering if the cursor is only moved
1 parent 5365ba9 commit 30e8eaf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/reline/line_editor.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def initialize(config, encoding)
5959
def simplified_rendering?
6060
if finished?
6161
false
62+
elsif @just_cursor_moving and not @rerender_all
63+
true
6264
else
6365
not @rerender_all and not finished? and Reline::IOGate.in_pasting?
6466
end
@@ -188,6 +190,7 @@ def reset_variables(prompt = '', encoding:)
188190
@searching_prompt = nil
189191
@first_char = true
190192
@add_newline_to_end_of_buffer = false
193+
@just_cursor_moving = false
191194
@eof = false
192195
@continuous_insertion_buffer = String.new(encoding: @encoding)
193196
reset_line
@@ -335,6 +338,10 @@ def rerender
335338
if @add_newline_to_end_of_buffer
336339
rerender_added_newline
337340
@add_newline_to_end_of_buffer = false
341+
elsif @just_cursor_moving and not @rerender_all
342+
just_move_cursor
343+
@just_cursor_moving = false
344+
return
338345
elsif @previous_line_index or new_highest_in_this != @highest_in_this
339346
rerender_changed_current_line
340347
@previous_line_index = nil
@@ -382,6 +389,25 @@ def rerender
382389
@previous_line_index = nil
383390
end
384391

392+
def just_move_cursor
393+
prompt, prompt_width, prompt_list = check_multiline_prompt(@buffer_of_lines, prompt)
394+
move_cursor_up(@started_from)
395+
new_first_line_started_from =
396+
if @line_index.zero?
397+
0
398+
else
399+
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
400+
end
401+
@line = @buffer_of_lines[@line_index]
402+
move_cursor_down(new_first_line_started_from - @first_line_started_from)
403+
@first_line_started_from = new_first_line_started_from
404+
calculate_nearest_cursor
405+
@started_from = calculate_height_by_width(prompt_width + @cursor) - 1
406+
move_cursor_down(@started_from)
407+
Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
408+
@previous_line_index = nil
409+
end
410+
385411
private def rerender_changed_current_line
386412
if @previous_line_index
387413
new_lines = whole_lines(index: @previous_line_index, line: @line)
@@ -923,6 +949,13 @@ def input_key(key)
923949
unless completion_occurs
924950
@completion_state = CompletionState::NORMAL
925951
end
952+
unless Reline::IOGate.in_pasting?
953+
if @previous_line_index and @buffer_of_lines[@previous_line_index] == @line
954+
@just_cursor_moving = true
955+
elsif @previous_line_index.nil? and @buffer_of_lines[@line_index] == @line
956+
@just_cursor_moving = true
957+
end
958+
end
926959
if @is_multiline and @auto_indent_proc and not simplified_rendering?
927960
process_auto_indent
928961
end

0 commit comments

Comments
 (0)