Editor selects text that was typed at a tab-stop when shift-tabbing back to it

This commit is contained in:
Nathan Sobo
2012-06-26 17:55:40 -06:00
parent 65991c686a
commit 01993f1be2
4 changed files with 18 additions and 13 deletions

View File

@@ -59,21 +59,21 @@ describe "Snippets extension", ->
expect(buffer.lineForRow(2)).toBe "go here next:() and finally go here:()"
expect(buffer.lineForRow(3)).toBe "go here first:()"
expect(buffer.lineForRow(4)).toBe " if (items.length <= 1) return items;"
expect(editor.getCursorScreenPosition()).toEqual [3, 15]
expect(editor.getSelectedBufferRange()).toEqual [[3, 15], [3, 15]]
editor.trigger keydownEvent('tab', target: editor[0])
expect(editor.getCursorScreenPosition()).toEqual [2, 14]
expect(editor.getSelectedBufferRange()).toEqual [[2, 14], [2, 14]]
editor.insertText 'abc'
editor.trigger keydownEvent('tab', target: editor[0])
expect(editor.getCursorScreenPosition()).toEqual [2, 40]
expect(editor.getSelectedBufferRange()).toEqual [[2, 40], [2, 40]]
# tab backwards
editor.trigger keydownEvent('tab', shiftKey: true, target: editor[0])
expect(editor.getCursorScreenPosition()).toEqual [2, 17]
expect(editor.getSelectedBufferRange()).toEqual [[2, 14], [2, 17]] # should highlight text typed at tab stop
editor.trigger keydownEvent('tab', shiftKey: true, target: editor[0])
expect(editor.getCursorScreenPosition()).toEqual [3, 15]
expect(editor.getSelectedBufferRange()).toEqual [[3, 15], [3, 15]]
# shift-tab on first tab-stop does nothing
editor.trigger keydownEvent('tab', shiftKey: true, target: editor[0])

View File

@@ -7,7 +7,7 @@ class AnchorRange
constructor: (@editSession, bufferRange) ->
bufferRange = Range.fromObject(bufferRange)
@startAnchor = @editSession.addAnchorAtBufferPosition(bufferRange.start)
@startAnchor = @editSession.addAnchorAtBufferPosition(bufferRange.start, ignoreEqual: true)
@endAnchor = @editSession.addAnchorAtBufferPosition(bufferRange.end)
getBufferRange: ->
@@ -18,4 +18,4 @@ class AnchorRange
destroy: ->
@startAnchor.destroy()
@endAnchor.destroy()
@endAnchor.destroy()

View File

@@ -8,12 +8,17 @@ class Anchor
bufferPosition: null
screenPosition: null
constructor: (@editSession) ->
constructor: (@editSession, options = {}) ->
{ @ignoreEqual } = options
handleBufferChange: (e) ->
{ oldRange, newRange } = e
position = @getBufferPosition()
return if position.isLessThan(oldRange.end)
if @ignoreEqual
return if position.isLessThanOrEqual(oldRange.end)
else
return if position.isLessThan(oldRange.end)
newRow = newRange.end.row
newColumn = newRange.end.column

View File

@@ -237,13 +237,13 @@ class EditSession
getAnchors: ->
new Array(@anchors...)
addAnchor: ->
anchor = new Anchor(this)
addAnchor: (options) ->
anchor = new Anchor(this, options)
@anchors.push(anchor)
anchor
addAnchorAtBufferPosition: (bufferPosition) ->
anchor = @addAnchor()
addAnchorAtBufferPosition: (bufferPosition, options) ->
anchor = @addAnchor(options)
anchor.setBufferPosition(bufferPosition)
anchor