diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 0a5e2c45b6..3d1478d8ce 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -368,6 +368,7 @@ class RubyLex is_first_printable_of_line = true spaces_of_nest = [] spaces_at_line_head = 0 + open_brace_on_line = 0 @tokens.each_with_index do |t, index| case t[1] when :on_ignored_nl, :on_nl, :on_comment @@ -375,6 +376,7 @@ class RubyLex spaces_at_line_head = 0 is_first_spaces_of_line = true is_first_printable_of_line = true + open_brace_on_line = 0 next when :on_sp spaces_at_line_head = t[2].count(' ') if is_first_spaces_of_line @@ -383,7 +385,8 @@ class RubyLex end case t[1] when :on_lbracket, :on_lbrace, :on_lparen - spaces_of_nest.push(spaces_at_line_head) + spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2) + open_brace_on_line += 1 when :on_rbracket, :on_rbrace, :on_rparen if is_first_printable_of_line corresponding_token_depth = spaces_of_nest.pop diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index ae25b1d501..65fc7d431a 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -93,5 +93,24 @@ module TestIRB assert_indenting(lines, row.new_line_spaces, true) end end + + def test_multiple_braces_in_a_line + input_with_correct_indents = [ + Row.new(%q([[[), nil, 6), + Row.new(%q( ]), 4, 4), + Row.new(%q( ]), 2, 2), + Row.new(%q(]), 0, 0), + Row.new(%q([<