src/vs/base/common/strings.ts/prevCharLength
export function prevCharLength(str: string, offset: number): number {
	const graphemeBreakTree = GraphemeBreakTree.getInstance();
	const initialOffset = offset;

	const initialCodePoint = getPrevCodePoint(str, offset);
	offset -= (initialCodePoint >= Constants.UNICODE_SUPPLEMENTARY_PLANE_BEGIN ? 2 : 1);

	let graphemeBreakType = graphemeBreakTree.getGraphemeBreakType(initialCodePoint);
	while (offset > 0) {
		const prevCodePoint = getPrevCodePoint(str, offset);
		const prevGraphemeBreakType = graphemeBreakTree.getGraphemeBreakType(prevCodePoint);
		if (breakBetweenGraphemeBreakType(prevGraphemeBreakType, graphemeBreakType)) {
			break;
		}
		offset -= (prevCodePoint >= Constants.UNICODE_SUPPLEMENTARY_PLANE_BEGIN ? 2 : 1);
		graphemeBreakType = prevGraphemeBreakType;
	}

	return (initialOffset - offset);
}