Cursor

Cursor for navigating and manipulating text

(defined in /src/Cursor.coffee:10)
class Cursor

Parameters

NameTypeDescription
textString Text to traverse
pos=0optional = 0String - foo
(defined in /src/Cursor.coffee:17)
constructor: (@text, @pos) ->
	@pos or= 0
	@_calculate_positions()

Returns

NameTypeDescription
(Returns)Booleanwhether the cursor is at the end of the text.
(defined in /src/Cursor.coffee:110)
atEOF : () -> return @pos == @text.length

Returns

NameTypeDescription
(Returns)Booleanwhether the cursor is at the start of the text.
(defined in /src/Cursor.coffee:115)
atSOF : () -> return @pos == 0

Parameters

NameTypeDescription
tobjType='char'optional = 'char'String The text object type to get
(defined in /src/Cursor.coffee:83)
cur: (tobjType) ->
	tobjType or= 'char'
	@positions[tobjType][@offsets[tobjType]] or null
(defined in /src/Cursor.coffee:41)
del: (tobj) ->
	@text = @text.substring(0, tobj.index) + @text.substring(tobj.index + tobj.length)
	@_calculate_positions()
	return @
(defined in /src/Cursor.coffee:48)
ins: (tobj) ->
	@text = @text.substring(0, tobj.index) + tobj.text + @text.substring(tobj.index)
	@_calculate_positions()
	return @

Parameters

NameTypeDescription
amountNumber Number of units to move (can be negative)
tobjType='char'optional = 'char'String Text object type

See Also:

(defined in /src/Cursor.coffee:66)
move : (amount, tobjType) ->
	@moveTo(@pos + amount, tobjType)

Parameters

NameTypeDescription
posNumber Position to move to
tobjType='char'optional = 'char'String Unit to measure movements
(defined in /src/Cursor.coffee:73)
moveTo : (pos, tobjType) ->
	tobjType or= 'char'
	if tobjType isnt 'char' then throw new Error("'moveTo' only implemented for 'char' at the moment.")
	# console.log "Moving to #{tobjType}##{pos}"
	@pos = pos
	@_calculate_offsets()
(defined in /src/Cursor.coffee:55)
sub: (oldObj) ->
	with : (newObj) =>
		@del(oldObj)
		@ins(newObj, oldObj.index)
		return @