When ( [ { ' or " is inserted, insert the matching character after the cursor

This commit is contained in:
Nathan Sobo
2012-07-27 13:08:43 -06:00
parent 87f4d8c6e9
commit dc662ed071
2 changed files with 31 additions and 4 deletions

View File

@@ -4,15 +4,22 @@ _ = require 'underscore'
module.exports =
class LanguageMode
matchingCharacters:
'(': ')'
'[': ']'
'{': '}'
'"': '"'
"'": "'"
constructor: (@editSession) ->
@buffer = @editSession.buffer
@aceMode = @requireAceMode()
@aceAdaptor = new AceAdaptor(@editSession)
_.adviseBefore @editSession, 'insertText', (text) ->
if text == '('
@insertText '()'
@moveCursorLeft()
_.adviseBefore @editSession, 'insertText', (text) =>
if matchingCharacter = @matchingCharacters[text]
@editSession.insertText text + matchingCharacter
@editSession.moveCursorLeft()
false
requireAceMode: (fileExtension) ->