Skip to content

Commit

Permalink
Enter newline if cursor position is middle of input (#802)
Browse files Browse the repository at this point in the history
* Enter newline if cursor position is middle of input

* Add ed_force_submit to allow input confirmation on non-final lines
  • Loading branch information
ima1zumi authored Jan 6, 2025
1 parent f09e7b1 commit 8ef534e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
18 changes: 8 additions & 10 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1673,24 +1673,22 @@ def finish
finish
end
else
if @line_index == (@buffer_of_lines.size - 1)
if confirm_multiline_termination
finish
else
key_newline(key)
end
else
# should check confirm_multiline_termination to finish?
@line_index = @buffer_of_lines.size - 1
@byte_pointer = current_line.bytesize
if @line_index == @buffer_of_lines.size - 1 && confirm_multiline_termination
finish
else
key_newline(key)
end
end
else
finish
end
end

private def ed_force_submit(_key)
process_insert(force: true)
finish
end

private def em_delete_prev_char(key, arg: 1)
arg.times do
if @byte_pointer == 0 and @line_index > 0
Expand Down
21 changes: 19 additions & 2 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,30 @@ def test_autowrap_in_the_middle_of_a_line
close
end

def test_terminate_in_the_middle_of_lines
def test_newline_in_the_middle_of_lines
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\n 1\n 2\n 3\n 4\nend\n")
write("\C-p\C-p\C-p\C-e\n")
assert_screen(<<~EOC)
prompt> def hoge
prompt> 1
prompt> 2
prompt> 3
prompt> 4
prompt>
EOC
close
end

def test_ed_force_submit_in_the_middle_of_lines
write_inputrc <<~LINES
"\\C-a": ed_force_submit
LINES
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\nend")
write("\C-p\C-a")
assert_screen(<<~EOC)
Multiline REPL.
prompt> def hoge
prompt> end
=> :hoge
prompt>
Expand Down

0 comments on commit 8ef534e

Please sign in to comment.