Auto-outdent maintains proper cursor positon.

This commit is contained in:
Corey Johnson 2012-03-06 16:34:43 -08:00
parent fe07e45ebc
commit 0737529f07
3 changed files with 7 additions and 2 deletions

View File

@ -463,6 +463,8 @@ describe "Editor", ->
editor.insertText("}")
expect(editor.buffer.getLine(2)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 3
describe "selection", ->
selection = null

View File

@ -2,7 +2,7 @@ Range = require 'range'
module.exports =
class AceOutdentAdaptor
constructor: (@buffer) ->
constructor: (@buffer, @editor) ->
getLine: (row) ->
@buffer.getLine(row)
@ -13,6 +13,9 @@ class AceOutdentAdaptor
# Does not actually replace text, just line at range.start outdents one level
replace: (range, text) ->
{row, column} = @editor.getCursorBufferPosition()
start = range.start
end = {row: range.start.row, column: range.start.column + atom.tabText.length}
@buffer.change(new Range(start, end), "")
@editor.setCursorBufferPosition({row, column: column - atom.tabText.length})

View File

@ -324,7 +324,7 @@ class Editor extends View
autoOutdentText: ->
state = @lineWrapper.lineForScreenRow(@getCursorRow()).state
@buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer), @getCursorRow())
@buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer, this), @getCursorRow())
cutSelection: -> @selection.cut()
copySelection: -> @selection.copy()