UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

55 lines (47 loc) 1.52 kB
import isArrayEqual from '../util/isArrayEqual' import PropertyAnnotation from './PropertyAnnotation' /* A Marker is a temporary annotation used by the application to mark or hightlight certain things, such as spell-errors, selections, etc. Note: we extend PropertyAnnotation to inherit the same API. */ export default class Marker extends PropertyAnnotation { _initialize (doc, props) { this.document = doc this.type = props.type if (!props.type) { throw new Error("'type' is mandatory") } if (!props.start) { throw new Error("'start' is mandatory") } if (!props.end) { throw new Error("'end' is mandatory") } Object.keys(props).forEach(key => { this._set(key, props[key]) }) } // TODO: we should use the Coordinate comparison API here containsSelection (sel) { if (sel.isNull()) return false if (sel.isPropertySelection()) { return (isArrayEqual(this.start.path, sel.start.path) && this.start.offset <= sel.start.offset && this.end.offset >= sel.end.offset) } else { console.warn('Marker.contains() does not support other selection types.') } } get type () { return this._type } set type (type) { this._type = type } // TODO find out how to get rid of these // HACK: while having the same interface, Markers should still be treated differently, e.g. not go into the AnnotationIndex get _isPropertyAnnotation () { return false } get _isMarker () { return true } }