improve types
This commit is contained in:
parent
8139aeb073
commit
51f0f5718a
15 changed files with 196 additions and 186 deletions
|
@ -32,23 +32,23 @@ export default class Range {
|
|||
this._end = bIsLarger ? positionB : positionA;
|
||||
}
|
||||
|
||||
moveStart(delta: number) {
|
||||
public moveStart(delta: number): void {
|
||||
this._start = this._start.forwardsWhile(this.model, () => {
|
||||
delta -= 1;
|
||||
return delta >= 0;
|
||||
});
|
||||
}
|
||||
|
||||
trim() {
|
||||
public trim(): void {
|
||||
this._start = this._start.forwardsWhile(this.model, whitespacePredicate);
|
||||
this._end = this._end.backwardsWhile(this.model, whitespacePredicate);
|
||||
}
|
||||
|
||||
expandBackwardsWhile(predicate: Predicate) {
|
||||
public expandBackwardsWhile(predicate: Predicate): void {
|
||||
this._start = this._start.backwardsWhile(this.model, predicate);
|
||||
}
|
||||
|
||||
get text() {
|
||||
public get text(): string {
|
||||
let text = "";
|
||||
this._start.iteratePartsBetween(this._end, this.model, (part, startIdx, endIdx) => {
|
||||
const t = part.text.substring(startIdx, endIdx);
|
||||
|
@ -63,7 +63,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: Part[]) {
|
||||
public replace(parts: Part[]): number {
|
||||
const newLength = parts.reduce((sum, part) => sum + part.text.length, 0);
|
||||
let oldLength = 0;
|
||||
this._start.iteratePartsBetween(this._end, this.model, (part, startIdx, endIdx) => {
|
||||
|
@ -77,8 +77,8 @@ export default class Range {
|
|||
* Returns a copy of the (partial) parts within the range.
|
||||
* For partial parts, only the text is adjusted to the part that intersects with the range.
|
||||
*/
|
||||
get parts() {
|
||||
const parts = [];
|
||||
public get parts(): Part[] {
|
||||
const parts: Part[] = [];
|
||||
this._start.iteratePartsBetween(this._end, this.model, (part, startIdx, endIdx) => {
|
||||
const serializedPart = part.serialize();
|
||||
serializedPart.text = part.text.substring(startIdx, endIdx);
|
||||
|
@ -88,7 +88,7 @@ export default class Range {
|
|||
return parts;
|
||||
}
|
||||
|
||||
get length() {
|
||||
public get length(): number {
|
||||
let len = 0;
|
||||
this._start.iteratePartsBetween(this._end, this.model, (part, startIdx, endIdx) => {
|
||||
len += endIdx - startIdx;
|
||||
|
@ -96,11 +96,11 @@ export default class Range {
|
|||
return len;
|
||||
}
|
||||
|
||||
get start() {
|
||||
public get start(): DocumentPosition {
|
||||
return this._start;
|
||||
}
|
||||
|
||||
get end() {
|
||||
public get end(): DocumentPosition {
|
||||
return this._end;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue