UNPKG

devexpress-richedit

Version:

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

60 lines (59 loc) 2.07 kB
import { FixedInterval } from '@devexpress/utils/lib/intervals/fixed'; export class RunIterator { currentRun = null; currentChunk = null; currentSection = null; runs = []; chunks = []; sections = []; currentRunIndex = 0; currentChunkIndex = 0; currentSectionIndex = 0; indexForChunks = []; indexForSections = []; constructor(runs, chunks, sections, indexForChunks, indexForSections) { this.runs = runs; this.chunks = chunks; this.sections = sections; this.indexForChunks = indexForChunks; this.indexForSections = indexForSections; } moveNext() { this.currentRun = this.runs[this.currentRunIndex]; if (this.currentRun) { this.currentChunk = this.chunks[this.currentChunkIndex]; this.currentSection = this.sections[this.currentSectionIndex]; if (this.currentRunIndex == this.indexForChunks[this.currentChunkIndex]) this.currentChunkIndex++; if (this.currentRunIndex == this.indexForSections[this.currentSectionIndex]) this.currentSectionIndex++; this.currentRunIndex++; return true; } else { this.currentChunk = undefined; this.currentSection = undefined; return false; } } currentInterval() { if (this.currentRun) return new FixedInterval(this.currentChunk.startLogPosition.value + this.currentRun.startOffset, this.currentRun.getLength()); else return new FixedInterval(this.chunks[0].startLogPosition.value + this.runs[0].startOffset, this.runs[0].getLength()); } getFirstRun() { return this.runs[0]; } getLastRun() { return this.runs[this.runs.length - 1]; } getRunsCount() { return this.runs.length; } reset() { this.currentRunIndex = 0; this.currentChunkIndex = 0; this.currentSectionIndex = 0; } }