src/vs/editor/common/modelLineProjectionData.ts/ModelLineProjectionData/normalizeOffsetInInputWithInjectionsAroundInjections
class ModelLineProjectionData:	private normalizeOffsetInInputWithInjectionsAroundInjections(offsetInInputWithInjections: number, affinity: PositionAffinity): number {
		const injectedText = this.getInjectedTextAtOffset(offsetInInputWithInjections);
		if (!injectedText) {
			return offsetInInputWithInjections;
		}

		if (affinity === PositionAffinity.None) {
			if (offsetInInputWithInjections === injectedText.offsetInInputWithInjections + injectedText.length
				&& hasRightCursorStop(this.injectionOptions![injectedText.injectedTextIndex].cursorStops)) {
				return injectedText.offsetInInputWithInjections + injectedText.length;
			} else {
				let result = injectedText.offsetInInputWithInjections;
				if (hasLeftCursorStop(this.injectionOptions![injectedText.injectedTextIndex].cursorStops)) {
					return result;
				}

				let index = injectedText.injectedTextIndex - 1;
				while (index >= 0 && this.injectionOffsets![index] === this.injectionOffsets![injectedText.injectedTextIndex]) {
					if (hasRightCursorStop(this.injectionOptions![index].cursorStops)) {
						break;
					}
					result -= this.injectionOptions![index].content.length;
					if (hasLeftCursorStop(this.injectionOptions![index].cursorStops)) {
						break;
					}
					index--;
				}

				return result;
			}
		} else if (affinity === PositionAffinity.Right || affinity === PositionAffinity.RightOfInjectedText) {
			let result = injectedText.offsetInInputWithInjections + injectedText.length;
			let index = injectedText.injectedTextIndex;
			// traverse all injected text that touch each other
			while (index + 1 < this.injectionOffsets!.length && this.injectionOffsets![index + 1] === this.injectionOffsets![index]) {
				result += this.injectionOptions![index + 1].content.length;
				index++;
			}
			return result;
		} else if (affinity === PositionAffinity.Left || affinity === PositionAffinity.LeftOfInjectedText) {
			// affinity is left
			let result = injectedText.offsetInInputWithInjections;
			let index = injectedText.injectedTextIndex;
			// traverse all injected text that touch each other
			while (index - 1 >= 0 && this.injectionOffsets![index - 1] === this.injectionOffsets![index]) {
				result -= this.injectionOptions![index - 1].content.length;
				index--;
			}
			return result;
		}

		assertNever(affinity);
	}