Change behavior to confirm multiline termination
Always checks termination if you press Enter at last line.
This commit is contained in:
parent
c210c68d39
commit
da3fabc976
@ -100,7 +100,6 @@ class Reline::LineEditor
|
|||||||
@finished = false
|
@finished = false
|
||||||
@cleared = false
|
@cleared = false
|
||||||
@rerender_all = false
|
@rerender_all = false
|
||||||
@is_confirm_multiline_termination = false
|
|
||||||
@history_pointer = nil
|
@history_pointer = nil
|
||||||
@kill_ring = Reline::KillRing.new
|
@kill_ring = Reline::KillRing.new
|
||||||
@vi_clipboard = ''
|
@vi_clipboard = ''
|
||||||
@ -386,9 +385,12 @@ class Reline::LineEditor
|
|||||||
move_cursor_down(@first_line_started_from)
|
move_cursor_down(@first_line_started_from)
|
||||||
@rerender_all = false
|
@rerender_all = false
|
||||||
end
|
end
|
||||||
render_partial(prompt, prompt_width, @line) if !@is_multiline or !finished?
|
if !@is_multiline
|
||||||
if @is_multiline and finished?
|
render_partial(prompt, prompt_width, @line)
|
||||||
scroll_down(1) unless @buffer_of_lines.last.empty?
|
elsif !finished?
|
||||||
|
render_partial(prompt, prompt_width, @line)
|
||||||
|
else
|
||||||
|
scroll_down(1) unless whole_lines.last.empty?
|
||||||
Reline::IOGate.move_cursor_column(0)
|
Reline::IOGate.move_cursor_column(0)
|
||||||
Reline::IOGate.erase_after_cursor
|
Reline::IOGate.erase_after_cursor
|
||||||
end
|
end
|
||||||
@ -433,11 +435,9 @@ class Reline::LineEditor
|
|||||||
Reline::IOGate.erase_after_cursor
|
Reline::IOGate.erase_after_cursor
|
||||||
if with_control
|
if with_control
|
||||||
if finished?
|
if finished?
|
||||||
@output.puts
|
|
||||||
else
|
|
||||||
move_cursor_up((height - 1) - @started_from)
|
move_cursor_up((height - 1) - @started_from)
|
||||||
Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
|
|
||||||
end
|
end
|
||||||
|
Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
|
||||||
end
|
end
|
||||||
height
|
height
|
||||||
end
|
end
|
||||||
@ -699,15 +699,19 @@ class Reline::LineEditor
|
|||||||
unless completion_occurs
|
unless completion_occurs
|
||||||
@completion_state = CompletionState::NORMAL
|
@completion_state = CompletionState::NORMAL
|
||||||
end
|
end
|
||||||
if @is_confirm_multiline_termination and @confirm_multiline_termination_proc
|
end
|
||||||
@is_confirm_multiline_termination = false
|
|
||||||
temp_buffer = @buffer_of_lines.dup
|
def confirm_multiline_termination
|
||||||
if @previous_line_index and @line_index == (@buffer_of_lines.size - 1)
|
temp_buffer = @buffer_of_lines.dup
|
||||||
temp_buffer[@previous_line_index] = @line
|
if @previous_line_index and @line_index == (@buffer_of_lines.size - 1)
|
||||||
end
|
temp_buffer[@previous_line_index] = @line
|
||||||
if temp_buffer.any?{ |l| l.chomp != '' }
|
else
|
||||||
finish if @confirm_multiline_termination_proc.(temp_buffer.join("\n"))
|
temp_buffer[@line_index] = @line
|
||||||
end
|
end
|
||||||
|
if temp_buffer.any?{ |l| l.chomp != '' }
|
||||||
|
@confirm_multiline_termination_proc.(temp_buffer.join("\n") + "\n")
|
||||||
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -768,13 +772,17 @@ class Reline::LineEditor
|
|||||||
@cursor_max = calculate_width(@line)
|
@cursor_max = calculate_width(@line)
|
||||||
end
|
end
|
||||||
|
|
||||||
def whole_buffer
|
def whole_lines
|
||||||
temp_lines = @buffer_of_lines.dup
|
temp_lines = @buffer_of_lines.dup
|
||||||
temp_lines[@line_index] = @line
|
temp_lines[@line_index] = @line
|
||||||
|
temp_lines
|
||||||
|
end
|
||||||
|
|
||||||
|
def whole_buffer
|
||||||
if @buffer_of_lines.size == 1 and @line.nil?
|
if @buffer_of_lines.size == 1 and @line.nil?
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
temp_lines.join("\n")
|
whole_lines.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1077,26 +1085,27 @@ class Reline::LineEditor
|
|||||||
if @is_multiline
|
if @is_multiline
|
||||||
if @config.editing_mode_is?(:vi_command)
|
if @config.editing_mode_is?(:vi_command)
|
||||||
if @line_index < (@buffer_of_lines.size - 1)
|
if @line_index < (@buffer_of_lines.size - 1)
|
||||||
ed_next_history(key)
|
ed_next_history(key) # means cursor down
|
||||||
else
|
else
|
||||||
@is_confirm_multiline_termination = true
|
finish if confirm_multiline_termination
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
next_line = @line.byteslice(@byte_pointer, @line.bytesize - @byte_pointer)
|
if @line_index == (@buffer_of_lines.size - 1) and confirm_multiline_termination
|
||||||
cursor_line = @line.byteslice(0, @byte_pointer)
|
finish
|
||||||
insert_new_line(cursor_line, next_line)
|
else
|
||||||
@cursor = 0
|
next_line = @line.byteslice(@byte_pointer, @line.bytesize - @byte_pointer)
|
||||||
if @line_index == (@buffer_of_lines.size - 1)
|
cursor_line = @line.byteslice(0, @byte_pointer)
|
||||||
@is_confirm_multiline_termination = true
|
insert_new_line(cursor_line, next_line)
|
||||||
|
@cursor = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return
|
else
|
||||||
|
if @history_pointer
|
||||||
|
Reline::HISTORY[@history_pointer] = @line
|
||||||
|
@history_pointer = nil
|
||||||
|
end
|
||||||
|
finish
|
||||||
end
|
end
|
||||||
if @history_pointer
|
|
||||||
Reline::HISTORY[@history_pointer] = @line
|
|
||||||
@history_pointer = nil
|
|
||||||
end
|
|
||||||
finish
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def em_delete_prev_char(key)
|
private def em_delete_prev_char(key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user