mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
When an identical closing bracket is inserted, don't insert a new character and move cursor to the right.
This commit is contained in:
parent
dc50959af1
commit
97b492edfc
@ -39,6 +39,16 @@ describe "LanguageMode", ->
|
||||
editSession.insertText "'"
|
||||
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
|
||||
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user