Skip to content

Commit 0e30a49

Browse files
committed
Forced newline insertion is not just cursor moving
1 parent c54d6a5 commit 0e30a49

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/reline/line_editor.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def reset_variables(prompt = '', encoding:)
195195
@searching_prompt = nil
196196
@first_char = true
197197
@add_newline_to_end_of_buffer = false
198-
@just_cursor_moving = false
198+
@just_cursor_moving = nil
199199
@cached_prompt_list = nil
200200
@prompt_cache_time = nil
201201
@eof = false
@@ -244,6 +244,7 @@ def multiline_off
244244
@buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: @encoding))
245245
@previous_line_index = @line_index
246246
@line_index += 1
247+
@just_cursor_moving = false
247248
end
248249

249250
private def calculate_height_by_width(width)
@@ -921,6 +922,7 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
921922
end
922923

923924
def input_key(key)
925+
@just_cursor_moving = nil
924926
if key.char.nil?
925927
if @first_char
926928
@line = nil
@@ -956,12 +958,16 @@ def input_key(key)
956958
unless completion_occurs
957959
@completion_state = CompletionState::NORMAL
958960
end
959-
unless Reline::IOGate.in_pasting?
961+
if not Reline::IOGate.in_pasting? and @just_cursor_moving.nil?
960962
if @previous_line_index and @buffer_of_lines[@previous_line_index] == @line
961963
@just_cursor_moving = true
962964
elsif @previous_line_index.nil? and @buffer_of_lines[@line_index] == @line
963965
@just_cursor_moving = true
966+
else
967+
@just_cursor_moving = false
964968
end
969+
else
970+
@just_cursor_moving = false
965971
end
966972
if @is_multiline and @auto_indent_proc and not simplified_rendering?
967973
process_auto_indent

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ def test_insert_after_clear
373373
EOC
374374
end
375375

376+
def test_foced_newline_insertion
377+
start_terminal(10, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
378+
#write("def a\nend\C-p\C-e\e\C-m 3")
379+
write("def a\nend\C-p\C-e\e\x0D")
380+
close
381+
assert_screen(<<~EOC)
382+
Multiline REPL.
383+
prompt> def a
384+
prompt>
385+
prompt> end
386+
EOC
387+
end
388+
376389
def test_multiline_incremental_search
377390
start_terminal(6, 25, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
378391
write("def a\n 8\nend\ndef b\n 3\nend\C-s8")

0 commit comments

Comments
 (0)