mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
cursor has an @editor method instead of referring to @parentView a lot
Punt on making a field since @parentView is null when Cursor.initialize is called.
This commit is contained in:
@@ -6,12 +6,15 @@ class Cursor extends Template
|
||||
@pre class: 'cursor', style: 'position: absolute;', => @raw ' '
|
||||
|
||||
viewProperties:
|
||||
editor: ->
|
||||
@parentView
|
||||
|
||||
setBuffer: (@buffer) ->
|
||||
@buffer.on 'insert', (e) =>
|
||||
@setY(@getY() + e.string.length)
|
||||
|
||||
setPosition: (point) ->
|
||||
@point = @parentView.clipPosition(point)
|
||||
@point = @editor().clipPosition(point)
|
||||
@goalY = null
|
||||
@updateAbsolutePosition()
|
||||
|
||||
@@ -37,7 +40,7 @@ class Cursor extends Template
|
||||
moveDown: ->
|
||||
{ x, y } = @getPosition()
|
||||
y = @goalY if @goalY?
|
||||
if x < @parentView.buffer.numLines() - 1
|
||||
if x < @editor().buffer.numLines() - 1
|
||||
@setPosition({x: x + 1, y: y})
|
||||
else
|
||||
@moveToLineEnd()
|
||||
@@ -46,7 +49,7 @@ class Cursor extends Template
|
||||
|
||||
moveToLineEnd: ->
|
||||
{ x } = @getPosition()
|
||||
@setPosition({ x, y: @parentView.buffer.getLine(x).length })
|
||||
@setPosition({ x, y: @editor().buffer.getLine(x).length })
|
||||
|
||||
moveToLineStart: ->
|
||||
{ x } = @getPosition()
|
||||
@@ -54,9 +57,9 @@ class Cursor extends Template
|
||||
|
||||
moveRight: ->
|
||||
{ x, y } = @getPosition()
|
||||
if y < @parentView.buffer.getLine(x).length
|
||||
if y < @editor().buffer.getLine(x).length
|
||||
y++
|
||||
else if x < @parentView.buffer.numLines() - 1
|
||||
else if x < @editor().buffer.numLines() - 1
|
||||
x++
|
||||
y = 0
|
||||
@setPosition({x, y})
|
||||
@@ -67,24 +70,24 @@ class Cursor extends Template
|
||||
y--
|
||||
else if x > 0
|
||||
x--
|
||||
y = @parentView.buffer.getLine(x).length
|
||||
y = @editor().buffer.getLine(x).length
|
||||
|
||||
@setPosition({x, y})
|
||||
|
||||
updateAbsolutePosition: ->
|
||||
position = @parentView.pixelPositionFromPoint(@point)
|
||||
position = @editor().pixelPositionFromPoint(@point)
|
||||
@css(position)
|
||||
|
||||
linesInView = @parentView.height() / @height()
|
||||
linesInView = @editor().height() / @height()
|
||||
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
scrollMargin = Math.min(@parentView.scrollMargin, maxScrollMargin)
|
||||
scrollMargin = Math.min(@editor().scrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * @height()
|
||||
desiredTop = position.top - margin
|
||||
desiredBottom = position.top + @height() + margin
|
||||
|
||||
if desiredBottom > @parentView.scrollBottom()
|
||||
@parentView.scrollBottom(desiredBottom)
|
||||
else if desiredTop < @parentView.scrollTop()
|
||||
@parentView.scrollTop(desiredTop)
|
||||
if desiredBottom > @editor().scrollBottom()
|
||||
@editor().scrollBottom(desiredBottom)
|
||||
else if desiredTop < @editor().scrollTop()
|
||||
@editor().scrollTop(desiredTop)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user