Outdent and indent use bufferRow and screenRow in the appropriate places

This commit is contained in:
Corey Johnson
2012-03-07 15:22:41 -08:00
parent dc815f67ad
commit ac77b7af87
2 changed files with 50 additions and 23 deletions

View File

@@ -504,25 +504,48 @@ describe "Editor", ->
beforeEach ->
editor.autoIndent = true
describe "when newline is inserted", ->
it "indents cursor based on the indentation of previous line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\n")
expect(editor.buffer.lineForRow(5)).toEqual(" ")
describe "when line renders on one screen line", ->
describe "when newline is inserted", ->
it "indents cursor based on the indentation of previous buffer line", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n")
expect(editor.buffer.lineForRow(2)).toEqual(" ")
it "indents cursor based on the indentation of previous line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\nvar thisIsCool")
expect(editor.buffer.lineForRow(5)).toEqual(" var thisIsCool")
it "indents cursor based on the indentation of previous buffer line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\nvar thisIsCool")
expect(editor.buffer.lineForRow(5)).toEqual(" var thisIsCool")
describe "when text that closes a scope entered", ->
it "outdents the text", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n")
expect(editor.buffer.lineForRow(2)).toEqual(" ")
editor.insertText("}")
expect(editor.buffer.lineForRow(2)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 3
describe "when line spans multiple screen lines", ->
beforeEach ->
editor.attachToDom()
editor.setSoftWrap(true)
setEditorWidthInChars(editor, 50)
describe "when newline is inserted", ->
it "indents cursor based on the indentation of previous buffer line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\n")
expect(editor.buffer.lineForRow(5)).toEqual(" ")
describe "when text that closes a scope entered", ->
it "outdents the text", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\n")
expect(editor.buffer.lineForRow(5)).toEqual(" ")
editor.insertText("}")
expect(editor.buffer.lineForRow(5)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 5
describe "when text that closes a scope entered", ->
it "outdents the text", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n")
expect(editor.buffer.lineForRow(2)).toEqual(" ")
editor.insertText("}")
expect(editor.buffer.lineForRow(2)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 3
describe "selection", ->
selection = null

View File

@@ -292,6 +292,7 @@ class Editor extends View
getSelection: -> @selection
getCurrentLine: -> @buffer.lineForRow(@getCursorRow())
getCurrentBufferLine: -> @buffer.lineForRow(@getCursorBufferRow())
getSelectedText: -> @selection.getText()
moveCursorUp: -> @cursor.moveUp()
moveCursorDown: -> @cursor.moveDown()
@@ -303,6 +304,7 @@ class Editor extends View
getCursorBufferPosition: -> @cursor.getBufferPosition()
setCursorRow: (row) -> @cursor.setRow(row)
getCursorRow: -> @cursor.getRow()
getCursorBufferRow: -> @getCursorBufferPosition().row
setCursorColumn: (column) -> @cursor.setColumn(column)
getCursorColumn: -> @cursor.getColumn()
@@ -324,19 +326,21 @@ class Editor extends View
autoIndentText: (text) ->
if @autoIndent
state = @renderer.lineForRow(@getCursorRow()).state
row = @getCursorScreenPosition().row
state = @renderer.lineForRow(row).state
if text[0] == "\n"
indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), atom.tabText)
indent = @buffer.mode.getNextLineIndent(state, @getCurrentBufferLine(), atom.tabText)
text = text[0] + indent + text[1..]
else if @buffer.mode.checkOutdent(state, @getCurrentLine(), text)
else if @buffer.mode.checkOutdent(state, @getCurrentBufferLine(), text)
shouldOutdent = true
{text, shouldOutdent}
autoOutdentText: ->
state = @renderer.lineForRow(@getCursorRow()).state
@buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer, this), @getCursorRow())
screenRow = @getCursorScreenPosition().row
bufferRow = @getCursorBufferPosition().row
state = @renderer.lineForRow(screenRow).state
@buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer, this), bufferRow)
cutSelection: -> @selection.cut()
copySelection: -> @selection.copy()