mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Do not insert matching bracket unless the following character is whitespace
This commit is contained in:
parent
1edd9973d2
commit
ed12f66b13
@ -14,6 +14,17 @@ describe "LanguageMode", ->
|
||||
{ buffer, languageMode } = editSession
|
||||
|
||||
describe "matching character insertion", ->
|
||||
beforeEach ->
|
||||
editSession.buffer.setText("")
|
||||
|
||||
describe "when there is non-whitespace after the cursor", ->
|
||||
it "does not insert a matching bracket", ->
|
||||
editSession.buffer.setText("ab")
|
||||
editSession.setCursorBufferPosition([0, 1])
|
||||
editSession.insertText("(")
|
||||
|
||||
expect(editSession.buffer.getText()).toBe "a(b"
|
||||
|
||||
describe "when there are multiple cursors", ->
|
||||
it "inserts ) at each cursor", ->
|
||||
editSession.buffer.setText("()\nab\n[]\n12")
|
||||
@ -51,14 +62,12 @@ describe "LanguageMode", ->
|
||||
expect(buffer.lineForRow(0)).toMatch /^''/
|
||||
|
||||
describe "when ) is inserted before a )", ->
|
||||
describe "when there is whitespace after the )", ->
|
||||
it "moves the cursor one column to the right instead of inserting a new )", ->
|
||||
editSession.buffer.setText("")
|
||||
editSession.insertText '() '
|
||||
editSession.setCursorBufferPosition([0, 1])
|
||||
editSession.insertText ')'
|
||||
expect(buffer.lineForRow(0)).toBe "() "
|
||||
expect(editSession.getCursorBufferPosition().column).toBe 2
|
||||
it "moves the cursor one column to the right instead of inserting a new )", ->
|
||||
editSession.insertText '() '
|
||||
editSession.setCursorBufferPosition([0, 1])
|
||||
editSession.insertText ')'
|
||||
expect(buffer.lineForRow(0)).toBe "() "
|
||||
expect(editSession.getCursorBufferPosition().column).toBe 2
|
||||
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
|
@ -20,12 +20,12 @@ class LanguageMode
|
||||
return true if @editSession.hasMultipleCursors()
|
||||
|
||||
cursorBufferPosition = @editSession.getCursorBufferPosition()
|
||||
nextCharachter = @editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0, 1])])
|
||||
nextCharacter = @editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0, 1])])
|
||||
|
||||
if @isCloseBracket(text) and text == nextCharachter
|
||||
if @isCloseBracket(text) and text == nextCharacter
|
||||
@editSession.moveCursorRight()
|
||||
false
|
||||
else if matchingCharacter = @matchingCharacters[text]
|
||||
else if /^\s*$/.test(nextCharacter) and matchingCharacter = @matchingCharacters[text]
|
||||
@editSession.insertText text + matchingCharacter
|
||||
@editSession.moveCursorLeft()
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user