diff --git a/src/editor/position.ts b/src/editor/position.ts index 821ad331c4..3f24581695 100644 --- a/src/editor/position.ts +++ b/src/editor/position.ts @@ -24,7 +24,7 @@ export interface IPosition { } type Callback = (part: Part, startIdx: number, endIdx: number) => void; -type Predicate = (index: number, offset: number, part: Part) => boolean; +export type Predicate = (index: number, offset: number, part: Part) => boolean; export default class DocumentPosition implements IPosition { constructor(public readonly index: number, public readonly offset: number) { diff --git a/src/editor/range.ts b/src/editor/range.ts index 456509a855..27f59f34a9 100644 --- a/src/editor/range.ts +++ b/src/editor/range.ts @@ -15,7 +15,8 @@ limitations under the License. */ import EditorModel from "./model"; -import DocumentPosition from "./position"; +import DocumentPosition, {Predicate} from "./position"; +import {Part} from "./parts"; export default class Range { private _start: DocumentPosition; @@ -27,14 +28,14 @@ export default class Range { this._end = bIsLarger ? positionB : positionA; } - moveStart(delta) { + moveStart(delta: number) { this._start = this._start.forwardsWhile(this.model, () => { delta -= 1; return delta >= 0; }); } - expandBackwardsWhile(predicate) { + expandBackwardsWhile(predicate: Predicate) { this._start = this._start.backwardsWhile(this.model, predicate); } @@ -53,7 +54,7 @@ export default class Range { * @param {Part[]} parts the parts to replace the range with * @return {Number} the net amount of characters added, can be negative. */ - replace(parts) { + replace(parts: Part[]) { const newLength = parts.reduce((sum, part) => sum + part.text.length, 0); let oldLength = 0; this._start.iteratePartsBetween(this._end, this.model, (part, startIdx, endIdx) => {