summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortompng <tomoyapenguin@gmail.com>2023-01-23 00:00:04 +0900
committergit <svn-admin@ruby-lang.org>2023-02-06 14:23:59 +0000
commit91f353b1c3c81f101e0421f8a000f414aecad2dc (patch)
treeed9ec37ebfe72d228dc6d700f0ad2950cd7f939a
parent440b9d2c6f5d405db086c14cc37b3d22b3586b5c (diff)
[ruby/reline] Fix line rendering when newline is added at the end of the buffer
https://github.com/ruby/reline/commit/7d61b3df9a
-rw-r--r--lib/reline/line_editor.rb17
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb13
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index b942a00844..16e99e087a 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -468,7 +468,7 @@ class Reline::LineEditor
rendered = false
if @add_newline_to_end_of_buffer
clear_dialog_with_content
- rerender_added_newline(prompt, prompt_width)
+ rerender_added_newline(prompt, prompt_width, prompt_list)
@add_newline_to_end_of_buffer = false
else
if @just_cursor_moving and not @rerender_all
@@ -969,11 +969,19 @@ class Reline::LineEditor
end
end
- private def rerender_added_newline(prompt, prompt_width)
- scroll_down(1)
+ private def rerender_added_newline(prompt, prompt_width, prompt_list)
@buffer_of_lines[@previous_line_index] = @line
@line = @buffer_of_lines[@line_index]
- unless @in_pasting
+ @previous_line_index = nil
+ if @in_pasting
+ scroll_down(1)
+ else
+ lines = whole_lines
+ prev_line_prompt = @prompt_proc ? prompt_list[@line_index - 1] : prompt
+ prev_line_prompt_width = @prompt_proc ? calculate_width(prev_line_prompt, true) : prompt_width
+ prev_line = modify_lines(lines)[@line_index - 1]
+ render_partial(prev_line_prompt, prev_line_prompt_width, prev_line, @first_line_started_from + @started_from, with_control: false)
+ scroll_down(1)
render_partial(prompt, prompt_width, @line, @first_line_started_from + @started_from + 1, with_control: false)
end
@cursor = @cursor_max = calculate_width(@line)
@@ -982,7 +990,6 @@ class Reline::LineEditor
@highest_in_this = calculate_height_by_width(prompt_width + @cursor_max)
@first_line_started_from += @started_from + 1
@started_from = calculate_height_by_width(prompt_width + @cursor) - 1
- @previous_line_index = nil
end
def just_move_cursor
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 71d3bcf0bb..1e46701664 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -690,6 +690,19 @@ begin
EOC
end
+ def test_newline_after_wrong_indent
+ start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
+ write "if 1\n aa"
+ write "\n"
+ close
+ assert_screen(<<~EOC)
+ Multiline REPL.
+ prompt> if 1
+ prompt> aa
+ prompt>
+ EOC
+ end
+
def test_suppress_auto_indent_just_after_pasted
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
write("def hoge\n [[\n 3]]\ned")