Make Cursor and Selection models for automatic id assignment

This commit is contained in:
Nathan Sobo
2014-04-15 10:40:07 -06:00
parent 66f3f2d883
commit 93388c2048
2 changed files with 8 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
{Point, Range} = require 'text-buffer'
{Emitter} = require 'emissary'
{Model} = require 'theorist'
_ = require 'underscore-plus'
# Public: The `Cursor` class represents the little blinking line identifying
@@ -8,9 +8,7 @@ _ = require 'underscore-plus'
# Cursors belong to {Editor}s and have some metadata attached in the form
# of a {Marker}.
module.exports =
class Cursor
Emitter.includeInto(this)
class Cursor extends Model
screenPosition: null
bufferPosition: null
goalColumn: null
@@ -18,7 +16,8 @@ class Cursor
needsAutoscroll: null
# Instantiated by an {Editor}
constructor: ({@editor, @marker}) ->
constructor: ({@editor, @marker, id}) ->
@assignId(id)
@updateVisibility()
@marker.on 'changed', (e) =>
@updateVisibility()

View File

@@ -1,12 +1,10 @@
{Point, Range} = require 'text-buffer'
{Emitter} = require 'emissary'
{Model} = require 'theorist'
{pick} = require 'underscore-plus'
# Public: Represents a selection in the {Editor}.
module.exports =
class Selection
Emitter.includeInto(this)
class Selection extends Model
cursor: null
marker: null
editor: null
@@ -14,7 +12,8 @@ class Selection
wordwise: false
needsAutoscroll: null
constructor: ({@cursor, @marker, @editor}) ->
constructor: ({@cursor, @marker, @editor, id}) ->
@assignId(id)
@cursor.selection = this
@marker.on 'changed', => @screenRangeChanged()
@marker.on 'destroyed', =>