diff --git a/src/app/anchor.coffee b/src/app/anchor.coffee index ab78f9a0d..689216e6e 100644 --- a/src/app/anchor.coffee +++ b/src/app/anchor.coffee @@ -6,14 +6,7 @@ class Anchor bufferPosition: null screenPosition: null - constructor: (editor, screenPosition) -> - @editor = editor - - if screenPosition - @setScreenPosition(screenPosition) - else - @bufferPosition = new Point(0,0) - @screenPosition = new Point(0,0) + constructor: (@editSession) -> handleBufferChange: (e) -> { oldRange, newRange } = e @@ -33,10 +26,11 @@ class Anchor getBufferPosition: -> @bufferPosition - setBufferPosition: (position, options) -> + setBufferPosition: (position, options={}) -> @bufferPosition = Point.fromObject(position) - screenPosition = @editor.screenPositionForBufferPosition(@bufferPosition, options) - @setScreenPosition(screenPosition, clip: false, assignBufferPosition: false) + clip = options.clip ? true + @bufferPosition = @editSession.clipBufferPosition(@bufferPosition) if clip + @refreshScreenPosition(options) getScreenPosition: -> @screenPosition @@ -46,8 +40,13 @@ class Anchor clip = options.clip ? true assignBufferPosition = options.assignBufferPosition ? true - @screenPosition = @editor.clipScreenPosition(@screenPosition, options) if clip - @bufferPosition = @editor.bufferPositionForScreenPosition(@screenPosition, options) if assignBufferPosition + @screenPosition = @editSession.clipScreenPosition(@screenPosition, options) if clip + @bufferPosition = @editSession.bufferPositionForScreenPosition(@screenPosition, options) if assignBufferPosition Object.freeze @screenPosition Object.freeze @bufferPosition + + refreshScreenPosition: (options) -> + screenPosition = @editSession.screenPositionForBufferPosition(@bufferPosition, options) + @setScreenPosition(screenPosition, clip: false, assignBufferPosition: false) + diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index f63df9fa0..70e8ae3f1 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -1,6 +1,6 @@ Point = require 'point' Range = require 'range' -Anchor = require 'new-anchor' +Anchor = require 'anchor' EventEmitter = require 'event-emitter' _ = require 'underscore' diff --git a/src/app/new-anchor.coffee b/src/app/new-anchor.coffee deleted file mode 100644 index 689216e6e..000000000 --- a/src/app/new-anchor.coffee +++ /dev/null @@ -1,52 +0,0 @@ -Point = require 'point' - -module.exports = -class Anchor - editor: null - bufferPosition: null - screenPosition: null - - constructor: (@editSession) -> - - handleBufferChange: (e) -> - { oldRange, newRange } = e - position = @getBufferPosition() - return if position.isLessThan(oldRange.end) - - newRow = newRange.end.row - newColumn = newRange.end.column - if position.row == oldRange.end.row - newColumn += position.column - oldRange.end.column - else - newColumn = position.column - newRow += position.row - oldRange.end.row - - @setBufferPosition [newRow, newColumn] - - getBufferPosition: -> - @bufferPosition - - setBufferPosition: (position, options={}) -> - @bufferPosition = Point.fromObject(position) - clip = options.clip ? true - @bufferPosition = @editSession.clipBufferPosition(@bufferPosition) if clip - @refreshScreenPosition(options) - - getScreenPosition: -> - @screenPosition - - setScreenPosition: (position, options={}) -> - @screenPosition = Point.fromObject(position) - clip = options.clip ? true - assignBufferPosition = options.assignBufferPosition ? true - - @screenPosition = @editSession.clipScreenPosition(@screenPosition, options) if clip - @bufferPosition = @editSession.bufferPositionForScreenPosition(@screenPosition, options) if assignBufferPosition - - Object.freeze @screenPosition - Object.freeze @bufferPosition - - refreshScreenPosition: (options) -> - screenPosition = @editSession.screenPositionForBufferPosition(@bufferPosition, options) - @setScreenPosition(screenPosition, clip: false, assignBufferPosition: false) - diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 3520e2e67..ae36e2ca7 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -1,5 +1,5 @@ Range = require 'range' -Anchor = require 'new-anchor' +Anchor = require 'anchor' EventEmitter = require 'event-emitter' AceOutdentAdaptor = require 'ace-outdent-adaptor' _ = require 'underscore'