Skip to content

Commit 3e3c89d

Browse files
committed
Update cursor correctly when just cursor moving
This fixes #236 and #239.
1 parent 064664c commit 3e3c89d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/reline/line_editor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def just_move_cursor
471471
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
472472
end
473473
first_line_diff = new_first_line_started_from - @first_line_started_from
474-
new_cursor, _, new_started_from, _ = calculate_nearest_cursor(@line, @cursor, @started_from, @byte_pointer, false)
474+
new_cursor, new_cursor_max, new_started_from, new_byte_pointer = calculate_nearest_cursor(@buffer_of_lines[@line_index], @cursor, @started_from, @byte_pointer, false)
475475
new_started_from = calculate_height_by_width(prompt_width + new_cursor) - 1
476476
calculate_scroll_partial_screen(@highest_in_all, new_first_line_started_from + new_started_from)
477477
@previous_line_index = nil
@@ -485,6 +485,8 @@ def just_move_cursor
485485
@first_line_started_from = new_first_line_started_from
486486
@started_from = new_started_from
487487
@cursor = new_cursor
488+
@cursor_max = new_cursor_max
489+
@byte_pointer = new_byte_pointer
488490
move_cursor_down(first_line_diff + @started_from)
489491
Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
490492
false

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,24 @@ def each_top_level_statement
620620
EOC
621621
end
622622

623+
def test_update_cursor_correctly_when_just_cursor_moving
624+
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
625+
puts %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}.inspect
626+
write("def hoge\n 01234678")
627+
write("\C-p")
628+
write("\C-b")
629+
write("\C-n")
630+
write('5')
631+
write("\C-e")
632+
write('9')
633+
close
634+
assert_screen(<<~EOC)
635+
Multiline REPL.
636+
prompt> def hoge
637+
prompt> 0123456789
638+
EOC
639+
end
640+
623641
private def write_inputrc(content)
624642
File.open(@inputrc_file, 'w') do |f|
625643
f.write content

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy