Cursor for navigating and manipulating text
class Cursor
Whether the cursor is at the end of the text.
Name | Type | Description |
---|---|---|
(Returns) | Boolean | whether the cursor is at the end of the text. |
atEOF : () -> return @pos == @text.length
whether the cursor is at the start of the text.
Name | Type | Description |
---|---|---|
(Returns) | Boolean | whether the cursor is at the start of the text. |
atSOF : () -> return @pos == 0
Get the text object at the current cursor position
Name | Type | Description |
---|---|---|
tobjType='char' optional = 'char' | String | The text object type to get |
cur: (tobjType) -> tobjType or= 'char' @positions[tobjType][@offsets[tobjType]] or null
Delete a text object
del: (tobj) -> @text = @text.substring(0, tobj.index) + @text.substring(tobj.index + tobj.length) @_calculate_positions() return @
Insert a text object
ins: (tobj) -> @text = @text.substring(0, tobj.index) + tobj.text + @text.substring(tobj.index) @_calculate_positions() return @
Move the current position relative to the current position.
Move the current position to an absolute position
Name | Type | Description |
---|---|---|
pos | Number | Position to move to |
tobjType='char' optional = 'char' | String | Unit to measure movements |
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()
Replace a text object
sub: (oldObj) -> with : (newObj) => @del(oldObj) @ins(newObj, oldObj.index) return @