diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 18:49:42 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 18:49:42 +0900 |
commit | 12e06d32f55dff7f35c66842e5d6901857132060 (patch) | |
tree | 43fc156ca329ee04ebbbd9dd7c90a5d619d9f657 | |
parent | ee861e43f70d827abd1f8d26b2e97920237348b4 (diff) | |
download | ruby-12e06d32f55dff7f35c66842e5d6901857132060.tar.gz |
Use lstrip instead of gsub which can match only once
-rw-r--r-- | lib/reline/config.rb | 2 | ||||
-rw-r--r-- | lib/reline/line_editor.rb | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 760777997e..5c10d7fa91 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -123,7 +123,7 @@ class Reline::Config no += 1 - line = line.chomp.gsub(/^\s*/, '') + line = line.chomp.lstrip if line[0, 1] == '$' handle_directive(line[1..-1], file, no) next diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index bc795b8a3d..62965d0662 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -800,11 +800,11 @@ class Reline::LineEditor md = new_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 */, '') + @buffer_of_lines[@line_index] = ' ' * new_indent + @buffer_of_lines[@line_index].lstrip @cursor = new_indent @byte_pointer = new_indent else - @line = ' ' * new_indent + @line.gsub(/\A */, '') + @line = ' ' * new_indent + @line.lstrip @cursor += new_indent - prev_indent @byte_pointer += new_indent - prev_indent end @@ -1893,7 +1893,7 @@ class Reline::LineEditor if @is_multiline and @buffer_of_lines.size > @line_index + 1 @cursor = calculate_width(@line) @byte_pointer = @line.bytesize - @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).gsub(/\A +/, '') + @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).lstrip @cursor_max = calculate_width(@line) @buffer_of_lines[@line_index] = @line @rerender_all = true |