From e192bc73504d72eb2f9deaa159b929c2a90a2484 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 25 Jan 2012 09:47:53 -0800 Subject: [PATCH] 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. --- src/atom/cursor.coffee | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/atom/cursor.coffee b/src/atom/cursor.coffee index b6e1275dd..2af4ec0ac 100644 --- a/src/atom/cursor.coffee +++ b/src/atom/cursor.coffee @@ -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)