mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Editor selects text that was typed at a tab-stop when shift-tabbing back to it
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user