Skip to content

Commit

Permalink
Add *RangeListOptions methods at TextSublayerNode
Browse files Browse the repository at this point in the history
  • Loading branch information
yinm committed Jul 9, 2024
1 parent 83b67e7 commit 9bde140
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/componentStubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class TextSublayerNode {

private _fontName: FontName;
private _characters: string;
private _rangeListOptions: TextListOptions | PluginAPI["mixed"];

get fontName() {
return this._fontName || defaultFont;
Expand Down Expand Up @@ -265,6 +266,50 @@ export class TextSublayerNode {
}
return this._fontName || defaultFont;
}


getRangeListOptions(
start: number,
end: number
): TextListOptions | PluginAPI["mixed"] {
if (this.config.simulateErrors && start < 0) {
throw new Error(`Error: Expected "start" to have value >=0`);
}
if (this.config.simulateErrors && end < 0) {
throw new Error(`Error: Expected "end" to have value >=0`);
}
if (this.config.simulateErrors && end > this._characters.length) {
throw new Error(
`Error: Range outside of available characters. 'start' must be less than node.characters.length and 'end' must be less than or equal to node.characters.length`
);
}
if (this.config.simulateErrors && end === start) {
throw new Error(
`Error: Empty range selected. 'end' must be greater than 'start'`
);
}
return this._rangeListOptions || { type: "NONE" };
}

setRangeListOptions(start: number, end: number, value: TextListOptions) {
if (this.config.simulateErrors && start < 0) {
throw new Error(`Error: Expected "start" to have value >=0`);
}
if (this.config.simulateErrors && end < 0) {
throw new Error(`Error: Expected "end" to have value >=0`);
}
if (this.config.simulateErrors && end > this._characters.length) {
throw new Error(
`Error: Range outside of available characters. 'start' must be less than node.characters.length and 'end' must be less than or equal to node.characters.length`
);
}
if (this.config.simulateErrors && end === start) {
throw new Error(
`Error: Empty range selected. 'end' must be greater than 'start'`
);
}
this._rangeListOptions = value;
}
}

export class ShapeWithTextNodeStub {
Expand Down

0 comments on commit 9bde140

Please sign in to comment.