UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

53 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EditorSlices = void 0; const Slice_1 = require("../slice/Slice"); const forEachRange = (selection, callback) => { const slices = []; for (const cursor of selection) { const slice = callback(cursor); slices.push(slice); } return slices; }; class EditorSlices { constructor(txt, slices) { this.txt = txt; this.slices = slices; } /** * @todo Rename to `insMany`. */ insStack(type, data, selection) { const { slices, txt } = this; selection || (selection = txt.editor.cursors()); return forEachRange(selection, (range) => slices.insStack(range.range(), type, data)); } insOne(type, data, selection) { const { slices, txt } = this; selection || (selection = txt.editor.cursors()); return forEachRange(selection, (range) => slices.insOne(range.range(), type, data)); } insErase(type, data, selection) { const { slices, txt } = this; selection || (selection = txt.editor.cursors()); return forEachRange(selection, (range) => slices.insErase(range.range(), type, data)); } insMarker(type, data, selection) { const { slices, txt } = this; const editor = txt.editor; selection || (selection = txt.editor.cursors()); return forEachRange(selection, (range) => { editor.collapseCursor(range); const after = range.start.clone(); after.refAfter(); const marker = slices.insMarkerAfter(after.id, type, data); return marker; }); } del(sliceOrId) { this.slices.del(sliceOrId instanceof Slice_1.Slice ? sliceOrId.id : sliceOrId); } } exports.EditorSlices = EditorSlices; //# sourceMappingURL=EditorSlices.js.map