diff options
author | aycabta <aycabta@gmail.com> | 2019-06-20 15:56:10 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-06-20 16:00:30 +0900 |
commit | c4c47b792dc8360f2541a399e9fcf417d068eee3 (patch) | |
tree | 2267088d7dea35393224ba9d20b06f294789bd1c | |
parent | e4cafa393f8fd4aa207f20b1d122884b4de99cf1 (diff) | |
download | ruby-c4c47b792dc8360f2541a399e9fcf417d068eee3.tar.gz |
Disable auto indent when move cursor up or down
This commit suppresses a strange behavior below:
if true
1[cursor]
end
and press down key
if true
1
end
-rw-r--r-- | lib/reline/line_editor.rb | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 629d561686..f787fb08a5 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -784,27 +784,32 @@ class Reline::LineEditor @completion_state = CompletionState::NORMAL end if @is_multiline and @auto_indent_proc - if @previous_line_index - new_lines = whole_lines(index: @previous_line_index, line: @line) + process_auto_indent + end + end + + private def process_auto_indent + return if not @check_new_auto_indent and @previous_line_index # move cursor up or down + if @previous_line_index + new_lines = whole_lines(index: @previous_line_index, line: @line) + else + new_lines = whole_lines + end + new_indent = @auto_indent_proc.(new_lines, @line_index, @byte_pointer, @check_new_auto_indent) + if new_indent + md = @buffer_of_lines[@line_index].match(/\A */) + prev_indent = md[0].count(' ') + if @check_new_auto_indent + @buffer_of_lines[@line_index] = ' ' * new_indent + @buffer_of_lines[@line_index].gsub(/\A */, '') + @cursor = new_indent + @byte_pointer = new_indent else - new_lines = whole_lines + @line = ' ' * new_indent + @line.gsub(/\A */, '') + @cursor -= prev_indent - new_indent + @byte_pointer -= prev_indent - new_indent end - new_indent = @auto_indent_proc.(new_lines, @line_index, @byte_pointer, @check_new_auto_indent) - if new_indent - md = @buffer_of_lines[@line_index].match(/\A */) - prev_indent = md[0].count(' ') - if @check_new_auto_indent - @buffer_of_lines[@line_index] = ' ' * new_indent + @buffer_of_lines[@line_index].gsub(/\A */, '') - @cursor = new_indent - @byte_pointer = new_indent - else - @line = ' ' * new_indent + @line.gsub(/\A */, '') - @cursor -= prev_indent - new_indent - @byte_pointer -= prev_indent - new_indent - end - end - @check_new_auto_indent = false end + @check_new_auto_indent = false end def retrieve_completion_block |