WIP: Set cursor position correctly after inserting a hard tab.

Tests pass but still some issues on repeated tab insertion.
This commit is contained in:
Nathan Sobo
2012-04-06 13:03:30 -06:00
parent ce91d50c29
commit 9da86982a8
8 changed files with 21 additions and 16 deletions

View File

@@ -1658,6 +1658,8 @@ describe "Editor", ->
expect(buffer.lineForRow(0)).not.toMatch(/^\t/)
editor.trigger 'tab'
expect(buffer.lineForRow(0)).toMatch(/^\t/)
expect(editor.getCursorBufferPosition()).toEqual [0, 1]
expect(editor.getCursorScreenPosition()).toEqual [0, editor.tabText.length]
describe "undo/redo", ->
it "undoes/redoes the last change", ->

View File

@@ -33,19 +33,21 @@ class Anchor
getBufferPosition: ->
@bufferPosition
setBufferPosition: (position) ->
screenPosition = @editor.screenPositionForBufferPosition(position)
@setScreenPosition(screenPosition, clip: false)
setBufferPosition: (position, options) ->
@bufferPosition = Point.fromObject(position)
screenPosition = @editor.screenPositionForBufferPosition(@bufferPosition, options)
@setScreenPosition(screenPosition, clip: false, assignBufferPosition: false)
getScreenPosition: ->
@screenPosition
setScreenPosition: (position, options={}) ->
position = Point.fromObject(position)
@screenPosition = Point.fromObject(position)
clip = options.clip ? true
assignBufferPosition = options.assignBufferPosition ? true
@screenPosition = if clip then @editor.clipScreenPosition(position, options) else position
@bufferPosition = @editor.bufferPositionForScreenPosition(position, options)
@screenPosition = @editor.clipScreenPosition(@screenPosition, options) if clip
@bufferPosition = @editor.bufferPositionForScreenPosition(position, options) if assignBufferPosition
Object.freeze @screenPosition
Object.freeze @bufferPosition

View File

@@ -126,6 +126,7 @@ class Buffer
@lines[oldRange.start.row..oldRange.end.row] = newTextLines
@trigger 'change', { oldRange, newRange, oldText, newText }
newRange
startUndoBatch: (selectedBufferRanges) ->
@undoManager.startUndoBatch(selectedBufferRanges)

View File

@@ -33,8 +33,8 @@ class Cursor extends View
getBufferPosition: ->
@anchor.getBufferPosition()
setBufferPosition: (bufferPosition) ->
@anchor.setBufferPosition(bufferPosition)
setBufferPosition: (bufferPosition, options={}) ->
@anchor.setBufferPosition(bufferPosition, options)
@refreshScreenPosition()
@clearSelection()

View File

@@ -330,8 +330,8 @@ class Editor extends View
screenPositionFromPixelPosition: ({top, left}) ->
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
screenPositionForBufferPosition: (position) ->
@renderer.screenPositionForBufferPosition(position)
screenPositionForBufferPosition: (position, options) ->
@renderer.screenPositionForBufferPosition(position, options)
bufferPositionForScreenPosition: (position, options) ->
@renderer.bufferPositionForScreenPosition(position, options)

View File

@@ -54,8 +54,8 @@ class LineMap
lastScreenRow: ->
@screenLineCount() - 1
screenPositionForBufferPosition: (bufferPosition) ->
@translatePosition('bufferDelta', 'screenDelta', bufferPosition)
screenPositionForBufferPosition: (bufferPosition, options) ->
@translatePosition('bufferDelta', 'screenDelta', bufferPosition, options)
bufferPositionForScreenPosition: (screenPosition, options) ->
@translatePosition('screenDelta', 'bufferDelta', screenPosition, options)

View File

@@ -100,8 +100,8 @@ class Renderer
lineCount: ->
@lineMap.screenLineCount()
screenPositionForBufferPosition: (position) ->
@lineMap.screenPositionForBufferPosition(position)
screenPositionForBufferPosition: (position, options) ->
@lineMap.screenPositionForBufferPosition(position, options)
bufferPositionForScreenPosition: (position, options) ->
@lineMap.bufferPositionForScreenPosition(position, options)

View File

@@ -100,9 +100,9 @@ class Selection extends View
insertText: (text) ->
{ text, shouldOutdent } = @autoIndentText(text)
@editor.buffer.change(@getBufferRange(), text)
newBufferRange = @editor.buffer.change(@getBufferRange(), text)
@cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true)
@autoOutdentText() if shouldOutdent
@cursor.setScreenPosition(@getScreenRange().end)
@clearSelection()
autoIndentText: (text) ->