mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
When ( [ { ' or " is inserted, insert the matching character after the cursor
This commit is contained in:
parent
87f4d8c6e9
commit
dc662ed071
@ -19,6 +19,26 @@ describe "LanguageMode", ->
|
||||
editSession.insertText '('
|
||||
expect(buffer.lineForRow(0)).toMatch /^\(\)/
|
||||
|
||||
describe "when [ is inserted", ->
|
||||
it "inserts a matching ] following the cursor", ->
|
||||
editSession.insertText '['
|
||||
expect(buffer.lineForRow(0)).toMatch /^\[\]/
|
||||
|
||||
describe "when { is inserted", ->
|
||||
it "inserts a matching ) following the cursor", ->
|
||||
editSession.insertText '{'
|
||||
expect(buffer.lineForRow(0)).toMatch /^\{\}/
|
||||
|
||||
describe "when \" is inserted", ->
|
||||
it "inserts a matching \" following the cursor", ->
|
||||
editSession.insertText '"'
|
||||
expect(buffer.lineForRow(0)).toMatch /^""/
|
||||
|
||||
describe "when ' is inserted", ->
|
||||
it "inserts a matching ' following the cursor", ->
|
||||
editSession.insertText "'"
|
||||
expect(buffer.lineForRow(0)).toMatch /^''/
|
||||
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false)
|
||||
|
@ -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) ->
|
||||
|
Loading…
Reference in New Issue
Block a user