UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

74 lines 2.7 kB
define(["require", "exports", "./domutil"], function (require, exports, domutil_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Represents a selection as wed understands it. */ class WedSelection { /** * @param anchor The anchor point of the selection. The anchor is where the * selection started. It does not move when the user selects text. * * @param focus The focus point of the selection. It is the part of the * selection that moves when the user selects text. Omitting ``focus`` will * result in a collapsed selection. */ constructor(converter, anchor, focus) { this.converter = converter; this.anchor = anchor; this.focus = (focus === undefined) ? anchor : focus; } get range() { const rr = this.rangeInfo; if (rr === undefined) { return undefined; } return rr.range; } get rangeInfo() { return this.anchor.makeRange(this.focus); } get collapsed() { return this.anchor.equals(this.focus); } get wellFormed() { const range = this.range; if (range === undefined) { return false; } return domutil_1.isWellFormedRange(range); } asDataCarets() { const range = this.range; if (range === undefined) { return undefined; } const startCaret = this.converter.toDataLocation(range.startContainer, range.startOffset); const endCaret = this.converter.toDataLocation(range.endContainer, range.endOffset); if (startCaret === undefined || endCaret === undefined) { return undefined; } return [startCaret, endCaret]; } mustAsDataCarets() { const ret = this.asDataCarets(); if (ret === undefined) { throw new Error("cannot get the selection as data carets"); } return ret; } /** * @returns Whether the two objects are equal. They are equal if they are the * same object or if they have equal focuses (foci?) and equal anchors. */ equals(other) { if (other == null) { return false; } return this.focus.equals(other.focus) && this.anchor.equals(other.anchor); } } exports.WedSelection = WedSelection; }); // LocalWords: MPL foci //# sourceMappingURL=wed-selection.js.map