1728
private async _readSelectedText(uri: URI, range: { readonly start: { readonly line: number; readonly character: number }; readonly end: { readonly line: number; readonly character: number } }): Promise<string> {
1729
const content = await this._fileService.readFile(uri);
1731
>
// AHP carries the resource range; the public SDK can carry the selected text too.
1732
>
// This reads the resource URI, so unsaved editor changes are not included.
1733
>
const lines = splitLinesIncludeSeparators(text);
1734
>
const start = this._getOffsetAt(lines, range.start);
1735
>
const end = this._getOffsetAt(lines, range.end);
1736
>
return text.substring(start, Math.max(start, end));
1737
}
1738
1739
private _getOffsetAt(lines: readonly string[], position: { readonly line: number; readonly character: number }): number {
1741
>
let offset = 0;
1742
>
for (let i = 0; i < line; i++) {
1743
>
offset += lines[i].length;
1744
>
}
1745
>
const lineText = lines[line].replace(/\r\n|\r|\n$/, '');
1746
>
return offset + Math.max(0, Math.min(position.character, lineText.length));
1747
>
}
1748
1749
/**