mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
X and Y were inverted
This commit is contained in:
@@ -24,17 +24,17 @@ class Buffer
|
||||
getLine: (n) ->
|
||||
@lines[n]
|
||||
|
||||
insert: ({x, y}, string) ->
|
||||
line = @getLine(x)
|
||||
before = line.substring(0, y)
|
||||
after = line.substring(y)
|
||||
@lines[x] = before + string + after
|
||||
insert: ({row, col}, string) ->
|
||||
line = @getLine(row)
|
||||
before = line.substring(0, col)
|
||||
after = line.substring(col)
|
||||
@lines[row] = before + string + after
|
||||
|
||||
@trigger 'insert'
|
||||
string: string
|
||||
range:
|
||||
start: {x, y}
|
||||
end: {x, y}
|
||||
start: {row, col}
|
||||
end: {row, col}
|
||||
|
||||
numLines: ->
|
||||
@getLines().length
|
||||
|
||||
@@ -13,68 +13,68 @@ class Cursor extends Template
|
||||
|
||||
setBuffer: (@buffer) ->
|
||||
@buffer.on 'insert', (e) =>
|
||||
@setY(@getY() + e.string.length)
|
||||
@setColumn(@getColumn() + e.string.length)
|
||||
|
||||
setPosition: (point) ->
|
||||
@point = @editor.clipPosition(point)
|
||||
@goalY = null
|
||||
@goalColumn = null
|
||||
@updateAbsolutePosition()
|
||||
|
||||
getPosition: -> @point
|
||||
|
||||
setY: (y) ->
|
||||
{ x } = @getPosition()
|
||||
@setPosition {x, y}
|
||||
setColumn: (col) ->
|
||||
{ row } = @getPosition()
|
||||
@setPosition {row, col}
|
||||
|
||||
getY: ->
|
||||
@getPosition().y
|
||||
getColumn: ->
|
||||
@getPosition().col
|
||||
|
||||
moveUp: ->
|
||||
{ x, y } = @getPosition()
|
||||
y = @goalY if @goalY?
|
||||
if x > 0
|
||||
@setPosition({x: x - 1, y: y})
|
||||
{ row, col } = @getPosition()
|
||||
col = @goalColumn if @goalColumn?
|
||||
if row > 0
|
||||
@setPosition({row: row - 1, col: col})
|
||||
else
|
||||
@moveToLineStart()
|
||||
|
||||
@goalY = y
|
||||
@goalColumn = col
|
||||
|
||||
moveDown: ->
|
||||
{ x, y } = @getPosition()
|
||||
y = @goalY if @goalY?
|
||||
if x < @editor.buffer.numLines() - 1
|
||||
@setPosition({x: x + 1, y: y})
|
||||
{ row, col } = @getPosition()
|
||||
col = @goalColumn if @goalColumn?
|
||||
if row < @editor.buffer.numLines() - 1
|
||||
@setPosition({row: row + 1, col: col})
|
||||
else
|
||||
@moveToLineEnd()
|
||||
|
||||
@goalY = y
|
||||
@goalColumn = col
|
||||
|
||||
moveToLineEnd: ->
|
||||
{ x } = @getPosition()
|
||||
@setPosition({ x, y: @editor.buffer.getLine(x).length })
|
||||
{ row } = @getPosition()
|
||||
@setPosition({ row, col: @editor.buffer.getLine(row).length })
|
||||
|
||||
moveToLineStart: ->
|
||||
{ x } = @getPosition()
|
||||
@setPosition({ x, y: 0 })
|
||||
{ row } = @getPosition()
|
||||
@setPosition({ row, col: 0 })
|
||||
|
||||
moveRight: ->
|
||||
{ x, y } = @getPosition()
|
||||
if y < @editor.buffer.getLine(x).length
|
||||
y++
|
||||
else if x < @editor.buffer.numLines() - 1
|
||||
x++
|
||||
y = 0
|
||||
@setPosition({x, y})
|
||||
{ row, col } = @getPosition()
|
||||
if col < @editor.buffer.getLine(row).length
|
||||
col++
|
||||
else if row < @editor.buffer.numLines() - 1
|
||||
row++
|
||||
col = 0
|
||||
@setPosition({row, col})
|
||||
|
||||
moveLeft: ->
|
||||
{ x, y } = @getPosition()
|
||||
if y > 0
|
||||
y--
|
||||
else if x > 0
|
||||
x--
|
||||
y = @editor.buffer.getLine(x).length
|
||||
{ row, col } = @getPosition()
|
||||
if col > 0
|
||||
col--
|
||||
else if row > 0
|
||||
row--
|
||||
col = @editor.buffer.getLine(row).length
|
||||
|
||||
@setPosition({x, y})
|
||||
@setPosition({row, col})
|
||||
|
||||
updateAbsolutePosition: ->
|
||||
position = @editor.pixelPositionFromPoint(@point)
|
||||
|
||||
@@ -59,18 +59,18 @@ class Editor extends Template
|
||||
@lines.append $$.pre -> @raw(' ')
|
||||
else
|
||||
@lines.append $$.pre(line)
|
||||
@setPosition(x: 0, y: 0)
|
||||
@setPosition(row: 0, col: 0)
|
||||
@cursor.setBuffer(@buffer)
|
||||
@buffer.on 'insert', (e) =>
|
||||
{x} = e.range.start
|
||||
@lines.find('pre').eq(x).replaceWith $$.pre(@buffer.getLine(x))
|
||||
{row} = e.range.start
|
||||
@lines.find('pre').eq(row).replaceWith $$.pre(@buffer.getLine(row))
|
||||
|
||||
clipPosition: ({x, y}) ->
|
||||
line = @buffer.getLine(x)
|
||||
{ x: x, y: Math.min(line.length, y) }
|
||||
clipPosition: ({row, col}) ->
|
||||
line = @buffer.getLine(row)
|
||||
{ row: row, col: Math.min(line.length, col) }
|
||||
|
||||
pixelPositionFromPoint: ({x, y}) ->
|
||||
{ top: x * @lineHeight, left: y * @charWidth }
|
||||
pixelPositionFromPoint: ({row, col}) ->
|
||||
{ top: row * @lineHeight, left: col * @charWidth }
|
||||
|
||||
calculateDimensions: ->
|
||||
fragment = $('<pre style="position: absolute; visibility: hidden;">x</pre>')
|
||||
@@ -86,7 +86,7 @@ class Editor extends Template
|
||||
else
|
||||
@scrollTop() + @height()
|
||||
|
||||
getCurrentLine: -> @buffer.getLine(@getPosition().x)
|
||||
getCurrentLine: -> @buffer.getLine(@getPosition().row)
|
||||
|
||||
moveUp: -> @cursor.moveUp()
|
||||
moveDown: -> @cursor.moveDown()
|
||||
@@ -94,4 +94,4 @@ class Editor extends Template
|
||||
moveLeft: -> @cursor.moveLeft()
|
||||
setPosition: (point) -> @cursor.setPosition(point)
|
||||
getPosition: -> @cursor.getPosition()
|
||||
setY: (y)-> @cursor.setY y
|
||||
setColumn: (column)-> @cursor.setColumn column
|
||||
|
||||
Reference in New Issue
Block a user