teletype-client-modified
Version:
I have modified the library developed by Atom to make it compatible with non-browser facility. I am using it only for experimentation purposes. I will remove this package post my experiment and raise a PR at Atom to finally merge this package so that this
60 lines (48 loc) • 1.41 kB
JavaScript
const assert = require('assert')
module.exports =
class Editor {
constructor () {
this.selectionsBySiteId = {}
}
dispose () {
this.disposed = true
}
isDisposed () {
return this.disposed
}
updateViewport (startRow, endRow) {
this.viewport = {startRow, endRow}
}
isScrollNeededToViewPosition (position) {
assert(position && position.row != null && position.column != null)
if (this.viewport) {
const {row} = position
return row < this.viewport.startRow || row > this.viewport.endRow
} else {
return false
}
}
getSelectionsForSiteId (siteId) {
assert.equal(typeof siteId, 'number', 'siteId must be a number!')
return this.selectionsBySiteId[siteId]
}
updateSelectionsForSiteId (siteId, selectionUpdates) {
assert.equal(typeof siteId, 'number', 'siteId must be a number!')
let selectionsForSite = this.selectionsBySiteId[siteId]
if (!selectionsForSite) {
selectionsForSite = {}
this.selectionsBySiteId[siteId] = selectionsForSite
}
for (const selectionId in selectionUpdates) {
const selectionUpdate = selectionUpdates[selectionId]
if (selectionUpdate) {
selectionsForSite[selectionId] = selectionUpdate
} else {
delete selectionsForSite[selectionId]
}
}
}
clearSelectionsForSiteId (siteId) {
delete this.selectionsBySiteId[siteId]
}
}