2020-05-06 06:09:15 -04:00
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Sanity-check the conversion and remove this comment.
|
2020-05-06 06:08:21 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
// Text document API for text
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:09:33 -04:00
|
|
|
let text
|
|
|
|
if (typeof WEB === 'undefined') {
|
|
|
|
text = require('./text')
|
|
|
|
}
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
text.api = {
|
2020-05-06 06:09:33 -04:00
|
|
|
provides: { text: true },
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
// The number of characters in the string
|
2020-05-06 06:09:33 -04:00
|
|
|
getLength() {
|
|
|
|
return this.snapshot.length
|
|
|
|
},
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
// Get the text contents of a document
|
2020-05-06 06:09:33 -04:00
|
|
|
getText() {
|
|
|
|
return this.snapshot
|
|
|
|
},
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
insert(pos, text, callback) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const op = [{ p: pos, i: text }]
|
|
|
|
|
|
|
|
this.submitOp(op, callback)
|
|
|
|
return op
|
2020-05-06 06:08:21 -04:00
|
|
|
},
|
2020-05-06 06:09:33 -04:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
del(pos, length, callback) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const op = [{ p: pos, d: this.snapshot.slice(pos, pos + length) }]
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:09:33 -04:00
|
|
|
this.submitOp(op, callback)
|
|
|
|
return op
|
2020-05-06 06:08:21 -04:00
|
|
|
},
|
2020-05-06 06:09:33 -04:00
|
|
|
|
2020-05-06 06:08:21 -04:00
|
|
|
_register() {
|
2020-05-06 06:09:33 -04:00
|
|
|
return this.on('remoteop', function (op) {
|
2021-07-13 07:04:42 -04:00
|
|
|
return Array.from(op).map(component =>
|
2020-05-06 06:09:33 -04:00
|
|
|
component.i !== undefined
|
|
|
|
? this.emit('insert', component.p, component.i)
|
|
|
|
: this.emit('delete', component.p, component.d)
|
|
|
|
)
|
|
|
|
})
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|