When an identical closing bracket is inserted, don't insert a new character and move cursor to the right.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-01 09:33:42 -07:00
parent dc50959af1
commit 97b492edfc
2 changed files with 30 additions and 1 deletions

View File

@@ -17,7 +17,13 @@ class LanguageMode
@aceAdaptor = new AceAdaptor(@editSession)
_.adviseBefore @editSession, 'insertText', (text) =>
if matchingCharacter = @matchingCharacters[text]
cursorBufferPosition = @editSession.getCursorBufferPosition()
nextCharachter = @editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0, 1])])
if @isCloseBracket(text) and text == nextCharachter
@editSession.moveCursorRight()
false
else if matchingCharacter = @matchingCharacters[text]
@editSession.insertText text + matchingCharacter
@editSession.moveCursorLeft()
false
@@ -35,6 +41,19 @@ class LanguageMode
else 'text'
new (require("ace/mode/#{modeName}").Mode)
isOpenBracket: (string) ->
@pairedCharacters[string]?
isCloseBracket: (string) ->
@getInvertedPairedCharacters()[string]?
getInvertedPairedCharacters: ->
return @invertedPairedCharacters if @invertedPairedCharacters
@invertedPairedCharacters = {}
for open, close of @matchingCharacters
@invertedPairedCharacters[close] = open
@invertedPairedCharacters
toggleLineCommentsInRange: (range) ->
range = Range.fromObject(range)
@aceMode.toggleCommentLines(@tokenizedBuffer.stateForRow(range.start.row), @aceAdaptor, range.start.row, range.end.row)