mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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", ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user