mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Outdent and indent use bufferRow and screenRow in the appropriate places
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user