mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
32 lines
713 B
CoffeeScript
32 lines
713 B
CoffeeScript
# Text document API for text
|
|
|
|
text = require './text' if typeof WEB is 'undefined'
|
|
|
|
text.api =
|
|
provides: {text:true}
|
|
|
|
# The number of characters in the string
|
|
getLength: -> @snapshot.length
|
|
|
|
# Get the text contents of a document
|
|
getText: -> @snapshot
|
|
|
|
insert: (pos, text, callback) ->
|
|
op = [{p:pos, i:text}]
|
|
|
|
@submitOp op, callback
|
|
op
|
|
|
|
del: (pos, length, callback) ->
|
|
op = [{p:pos, d:@snapshot[pos...(pos + length)]}]
|
|
|
|
@submitOp op, callback
|
|
op
|
|
|
|
_register: ->
|
|
@on 'remoteop', (op) ->
|
|
for component in op
|
|
if component.i != undefined
|
|
@emit 'insert', component.p, component.i
|
|
else
|
|
@emit 'delete', component.p, component.d
|