UNPKG

devexpress-richedit

Version:

DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.

26 lines (25 loc) 1.03 kB
import { FixedInterval } from '@devexpress/utils/lib/intervals/fixed'; export class IntervalUtils { static subtractIntervals(a, b) { const result = []; let bIndex = 0; for (const interval of a) { let currentFrom = interval.start; const currentTo = interval.end; for (; bIndex < b.length && b[bIndex].start < currentTo; bIndex++) { if (b[bIndex].end <= currentFrom) continue; if (b[bIndex].start > currentFrom) result.push(FixedInterval.fromPositions(currentFrom, Math.min(b[bIndex].start, currentTo))); currentFrom = Math.max(currentFrom, b[bIndex].end); if (currentFrom >= currentTo) { bIndex++; break; } } if (currentFrom < currentTo) result.push(FixedInterval.fromPositions(currentFrom, currentTo)); } return result; } }