Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter newline if cursor position is middle of input #802

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading