Skip to content

Commit

Permalink
🐛 fix crash when changing closing characters
Browse files Browse the repository at this point in the history
When trying to change a closing character at the beginning of a line,
the `getPreviousCharacters` check failed.

Related to #5
  • Loading branch information
mrwest808 committed Jan 5, 2017
1 parent b618b3b commit 85d5efa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bracket-padder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class BracketPadder
return match and match is character

getPreviousCharacters: (count, cursor) =>
return -1 unless cursor.column

return @editor.getTextInBufferRange([
cursor.traverse([0, -count]),
cursor,
Expand Down
16 changes: 16 additions & 0 deletions spec/bracket-padder-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ describe "bracket padding", ->
testPair '[', ']'
testPair '{', '}'

it 'doesn\'t crash when changing closing character on first column', ->
test = ->
editor.selectAll()
editor.delete()

editor.insertText('{')
editor.insertNewline()
editor.insertText('}')

editor.setCursorBufferPosition([1, 1])

editor.backspace()
editor.insertText(']')

expect(test).not.toThrow()

# it 'autocloses padded (), [], {} pairs', ->
# testPair = (opening, closing) ->
# editor.selectAll()
Expand Down

0 comments on commit 85d5efa

Please sign in to comment.