Ejemplo n.º 1
0
        public static SwapInfo Swap(this TextDocument document, int xStart, int xLength, int yStart, int yLength)
        {
            if (xStart > yStart)
            {
                (xStart, yStart)   = (yStart, xStart);
                (xLength, yLength) = (yLength, xLength);
            }

            if (xStart + xLength > yStart)
            {
                throw new ArgumentException();
            }

            var xText = document.GetText(xStart, xLength);
            var yText = document.GetText(yStart, yLength);

            var intervalText = document.GetText(xStart + xLength, yStart - (xStart + xLength));

            var newTest = yText + intervalText + xText;

            var offsetChangeMap = new OffsetChangeMap()
            {
                new OffsetChangeMapEntry(yStart, yLength, xLength),
                new OffsetChangeMapEntry(xStart, xLength, yLength),
            };

            document.Replace(xStart, newTest.Length, newTest, offsetChangeMap);
            return(SwapInfo.CreateFrom(new SwapInfo.SwapNode(xStart, xText), new SwapInfo.SwapNode(yStart, yText)));
        }
Ejemplo n.º 2
0
 static public bool TryCreateSwapInfo(this DocumentChangeEventArgs e, out SwapInfo?info)
 {
     info = SwapInfo.CreateFrom(e);
     return(info != null);
 }
Ejemplo n.º 3
0
 static public SwapInfo?TryCreateSwapInfo(this DocumentChangeEventArgs e)
 {
     return(SwapInfo.CreateFrom(e));
 }