mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Ensure editor and cursor methods explain if they act on buffer or screen lines
This commit is contained in:
@@ -265,7 +265,7 @@ describe "Editor", ->
|
||||
expect(editor.getCursorScreenPosition().column).not.toBe 6
|
||||
|
||||
# clear the goal column by explicitly setting the cursor position
|
||||
editor.setCursorColumn(6)
|
||||
editor.setCursorScreenColumn(6)
|
||||
expect(editor.getCursorScreenPosition().column).toBe 6
|
||||
|
||||
editor.moveCursorDown()
|
||||
@@ -705,13 +705,13 @@ describe "Editor", ->
|
||||
it "inserts the typed character at the cursor position, both in the buffer and the pre element", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: 6)
|
||||
|
||||
expect(editor.getCurrentLine().charAt(6)).not.toBe 'q'
|
||||
expect(editor.getCurrentBufferLine().charAt(6)).not.toBe 'q'
|
||||
|
||||
editor.hiddenInput.textInput 'q'
|
||||
|
||||
expect(editor.getCurrentLine().charAt(6)).toBe 'q'
|
||||
expect(editor.getCurrentBufferLine().charAt(6)).toBe 'q'
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 7)
|
||||
expect(editor.lines.find('.line:eq(1)')).toHaveText editor.getCurrentLine()
|
||||
expect(editor.lines.find('.line:eq(1)')).toHaveText editor.getCurrentBufferLine()
|
||||
|
||||
describe "when there is a selection", ->
|
||||
it "replaces the selected text with the typed text", ->
|
||||
|
||||
@@ -35,21 +35,34 @@ class Cursor extends View
|
||||
refreshScreenPosition: ->
|
||||
@setBufferPosition(@bufferPosition)
|
||||
|
||||
getBufferPosition: -> _.clone(@bufferPosition)
|
||||
getScreenPosition: -> _.clone(@screenPosition)
|
||||
getBufferPosition: ->
|
||||
_.clone(@bufferPosition)
|
||||
|
||||
getColumn: ->
|
||||
getScreenPosition: ->
|
||||
_.clone(@screenPosition)
|
||||
|
||||
getBufferColumn: ->
|
||||
@getBufferPosition().column
|
||||
|
||||
setBufferColumn: (column) ->
|
||||
{ row } = @getBufferPosition()
|
||||
@setBufferPosition {row, column}
|
||||
|
||||
getScreenColumn: ->
|
||||
@getScreenPosition().column
|
||||
|
||||
setColumn: (column) ->
|
||||
setScreenColumn: (column) ->
|
||||
{ row } = @getScreenPosition()
|
||||
@setScreenPosition {row, column}
|
||||
|
||||
getRow: ->
|
||||
getScreenRow: ->
|
||||
@getScreenPosition().row
|
||||
|
||||
getBufferRow: ->
|
||||
@getBufferPosition().row
|
||||
|
||||
isOnEOL: ->
|
||||
@getColumn() == @editor.getCurrentLine().length
|
||||
@getScreenColumn() == @editor.getCurrentScreenLine().length
|
||||
|
||||
moveUp: ->
|
||||
{ row, column } = @getScreenPosition()
|
||||
@@ -87,8 +100,8 @@ class Cursor extends View
|
||||
@setScreenPosition({row, column})
|
||||
|
||||
moveLeftUntilMatch: (regex) ->
|
||||
row = @getRow()
|
||||
column = @getColumn()
|
||||
row = @getScreenRow()
|
||||
column = @getScreenColumn()
|
||||
offset = 0
|
||||
|
||||
matchBackwards = =>
|
||||
|
||||
@@ -285,40 +285,39 @@ class Editor extends View
|
||||
@lineHeight = fragment.outerHeight()
|
||||
fragment.remove()
|
||||
|
||||
getCursor: -> @cursor
|
||||
getSelection: -> @selection
|
||||
|
||||
getCurrentLine: -> @buffer.lineForRow(@getCursorRow())
|
||||
getCurrentBufferLine: -> @buffer.lineForRow(@getCursorBufferRow())
|
||||
getSelectedText: -> @selection.getText()
|
||||
getCursor: -> @cursor
|
||||
moveCursorUp: -> @cursor.moveUp()
|
||||
moveCursorDown: -> @cursor.moveDown()
|
||||
moveCursorRight: -> @cursor.moveRight()
|
||||
moveCursorLeft: -> @cursor.moveLeft()
|
||||
|
||||
getCurrentScreenLine: -> @buffer.lineForRow(@getCursorScreenRow())
|
||||
getCurrentBufferLine: -> @buffer.lineForRow(@getCursorBufferRow())
|
||||
setCursorScreenPosition: (position) -> @cursor.setScreenPosition(position)
|
||||
getCursorScreenPosition: -> @cursor.getScreenPosition()
|
||||
setCursorBufferPosition: (position) -> @cursor.setBufferPosition(position)
|
||||
getCursorBufferPosition: -> @cursor.getBufferPosition()
|
||||
setCursorRow: (row) -> @cursor.setRow(row)
|
||||
getCursorRow: -> @cursor.getRow()
|
||||
getCursorBufferRow: -> @getCursorBufferPosition().row
|
||||
setCursorColumn: (column) -> @cursor.setColumn(column)
|
||||
getCursorColumn: -> @cursor.getColumn()
|
||||
setCursorScreenRow: (row) -> @cursor.setScreenRow(row)
|
||||
getCursorScreenRow: -> @cursor.getScreenRow()
|
||||
getCursorBufferRow: -> @cursor.getBufferRow()
|
||||
setCursorScreenColumn: (column) -> @cursor.setScreenColumn(column)
|
||||
getCursorScreenColumn: -> @cursor.getScreenColumn()
|
||||
setCursorBufferColumn: (column) -> @cursor.setBufferColumn(column)
|
||||
getCursorBufferColumn: -> @cursor.getBufferColumn()
|
||||
|
||||
getSelection: -> @selection
|
||||
getSelectedText: -> @selection.getText()
|
||||
selectRight: -> @selection.selectRight()
|
||||
selectLeft: -> @selection.selectLeft()
|
||||
selectUp: -> @selection.selectUp()
|
||||
selectDown: -> @selection.selectDown()
|
||||
selectToScreenPosition: (position) ->
|
||||
@selection.selectToScreenPosition(position)
|
||||
selectToBufferPosition: (position) ->
|
||||
@selection.selectToBufferPosition(position)
|
||||
selectToScreenPosition: (position) -> @selection.selectToScreenPosition(position)
|
||||
selectToBufferPosition: (position) -> @selection.selectToBufferPosition(position)
|
||||
|
||||
insertText: (text) ->
|
||||
{ text, shouldOutdent } = @autoIndentText(text)
|
||||
|
||||
@selection.insertText(text)
|
||||
|
||||
@autoOutdentText() if shouldOutdent
|
||||
|
||||
autoIndentText: (text) ->
|
||||
|
||||
@@ -100,8 +100,8 @@ class Selection extends View
|
||||
@anchor = { getScreenPosition: -> cursorPosition }
|
||||
|
||||
selectWord: ->
|
||||
row = @cursor.getRow()
|
||||
column = @cursor.getColumn()
|
||||
row = @cursor.getScreenRow()
|
||||
column = @cursor.getScreenColumn()
|
||||
|
||||
{ row, column } = @cursor.getBufferPosition()
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ class VimMode
|
||||
@opStack = []
|
||||
|
||||
moveCursorBeforeNewline: =>
|
||||
if not @editor.selection.modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentLine().length > 0
|
||||
@editor.setCursorColumn(@editor.getCurrentLine().length - 1)
|
||||
if not @editor.selection.modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentBufferLine().length > 0
|
||||
@editor.setCursorBufferColumn(@editor.getCurrentBufferLine().length - 1)
|
||||
|
||||
numericPrefix: (e) ->
|
||||
num = parseInt(e.keyEvent.keystroke)
|
||||
|
||||
@@ -4,7 +4,7 @@ class Command
|
||||
|
||||
class DeleteRight extends Command
|
||||
execute: ->
|
||||
@editor.delete() unless @editor.getCurrentLine().length == 0
|
||||
@editor.delete() unless @editor.getCurrentBufferLine().length == 0
|
||||
|
||||
module.exports = { DeleteRight }
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class MoveToNextParagraph extends Motion
|
||||
row = null
|
||||
column = 0
|
||||
|
||||
startRow = @editor.getCursorRow() + 1
|
||||
startRow = @editor.getCursorBufferRow() + 1
|
||||
for r in [startRow..@editor.buffer.lastRow()]
|
||||
if @editor.buffer.lineForRow(r).length == 0
|
||||
row = r
|
||||
|
||||
@@ -43,8 +43,8 @@ class Delete
|
||||
@motion.select()
|
||||
@editor.getSelection().delete()
|
||||
else
|
||||
@editor.buffer.deleteRow(@editor.getCursorRow())
|
||||
@editor.setCursorScreenPosition([@editor.getCursorRow(), 0])
|
||||
@editor.buffer.deleteRow(@editor.getCursorBufferRow())
|
||||
@editor.setCursorScreenPosition([@editor.getCursorScreenRow(), 0])
|
||||
|
||||
compose: (motion) ->
|
||||
if not motion.select
|
||||
|
||||
Reference in New Issue
Block a user