Quotes only automatically close if they are opened after a non-word character.

This commit is contained in:
Corey Johnson
2012-10-29 13:12:16 -07:00
parent 51b2871e02
commit 40673549cb
3 changed files with 33 additions and 16 deletions

View File

@@ -24,12 +24,13 @@ class LanguageMode
return true if @editSession.hasMultipleCursors()
cursorBufferPosition = @editSession.getCursorBufferPosition()
previousCharachter = @editSession.getTextInBufferRange([cursorBufferPosition.add([0, -1]), cursorBufferPosition])
nextCharachter = @editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0,1])])
hasWordAfterCursor = /\w/.test(nextCharachter)
cursorInsideString = @getTokenizedBuffer().isBufferPositionInsideString(cursorBufferPosition)
hasWordBeforeCursor = /\w/.test(previousCharachter)
autoCompleteOpeningBracket = @isOpeningBracket(text) and not hasWordAfterCursor and not cursorInsideString
autoCompleteOpeningBracket = @isOpeningBracket(text) and not hasWordAfterCursor and not (@isQuote(text) and hasWordBeforeCursor)
skipOverExistingClosingBracket = false
if @isClosingBracket(text) and nextCharachter == text
if bracketAnchorRange = @bracketAnchorRanges.filter((anchorRange) -> anchorRange.getBufferRange().end.isEqual(cursorBufferPosition))[0]
@@ -50,6 +51,9 @@ class LanguageMode
getTokenizedBuffer: ->
@editSession.tokenizedBuffer
isQuote: (string) ->
/'|"/.test(string)
isOpeningBracket: (string) ->
@pairedCharacters[string]?

View File

@@ -116,10 +116,6 @@ class TokenizedBuffer
iterator(token, startOfToken, { stop }) if bufferRange.containsPoint(startOfToken)
return unless keepLooping
isBufferPositionInsideString: (bufferPosition) ->
if lastScope = _.last(@scopesForPosition(bufferPosition))
/^string\./.test(lastScope)
findOpeningBracket: (startBufferPosition) ->
range = [[0,0], startBufferPosition]
position = null