mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Quotes only automatically close if they are opened after a non-word character.
This commit is contained in:
@@ -145,17 +145,34 @@ describe "LanguageMode", ->
|
||||
expect(buffer.lineForRow(0)).toBe '"ok"'
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [0, 4]
|
||||
|
||||
describe "when the cursor is inside a string", ->
|
||||
it "does not automatically insert closing single or double quote", ->
|
||||
editSession.buffer.setText("'aa'")
|
||||
editSession.setCursorBufferPosition([0, 3])
|
||||
editSession.insertText '"'
|
||||
expect(buffer.lineForRow(0)).toBe "'aa\"'"
|
||||
describe "when inserting a quote", ->
|
||||
describe "when a word charachter is before the cursor", ->
|
||||
it "does not automatically insert closing quote", ->
|
||||
editSession.buffer.setText("abc")
|
||||
editSession.setCursorBufferPosition([0, 3])
|
||||
editSession.insertText '"'
|
||||
expect(buffer.lineForRow(0)).toBe "abc\""
|
||||
|
||||
editSession.buffer.setText('"aa"')
|
||||
editSession.setCursorBufferPosition([0, 3])
|
||||
editSession.insertText "'"
|
||||
expect(buffer.lineForRow(0)).toBe '"aa\'"'
|
||||
editSession.buffer.setText("abc")
|
||||
editSession.setCursorBufferPosition([0, 3])
|
||||
editSession.insertText '\''
|
||||
expect(buffer.lineForRow(0)).toBe "abc\'"
|
||||
|
||||
describe "when a non word charachter is before the cursor", ->
|
||||
it "automatically insert closing quote", ->
|
||||
editSession.buffer.setText("ab@")
|
||||
editSession.setCursorBufferPosition([0, 3])
|
||||
editSession.insertText '"'
|
||||
expect(buffer.lineForRow(0)).toBe "ab@\"\""
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [0, 4]
|
||||
|
||||
describe "when the cursor is on an empty line", ->
|
||||
it "automatically insert closing quote", ->
|
||||
editSession.buffer.setText("")
|
||||
editSession.setCursorBufferPosition([0, 0])
|
||||
editSession.insertText '"'
|
||||
expect(buffer.lineForRow(0)).toBe "\"\""
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [0, 1]
|
||||
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
|
||||
@@ -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]?
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user