CreateEditPoint() public method

public CreateEditPoint ( ) : EnvDTE.EditPoint
return EnvDTE.EditPoint
Example #1
0
        public void OnDelete(
            TestTextPoint startPoint,
            object obj)
        {
            TestTextPoint endPoint;

            if (obj is int)
            {
                endPoint = (TestTextPoint)startPoint.CreateEditPoint();
                endPoint.CharRight((int)obj);
            }
            else if (obj is TestTextPoint)
            {
                endPoint = (TestTextPoint)obj;
            }
            else
            {
                throw new System.ArgumentException("Invalid argument");
            }
            if (!endPoint.GreaterThan(startPoint))
            {
                if (endPoint.EqualTo(startPoint))
                {
                    return;
                }
                else
                {
                    throw new System.ArgumentException("Invalid argument");
                }
            }

            if (startPoint.mLineNum == endPoint.mLineNum)
            {
                SetLine(startPoint.mLineNum, GetLine(startPoint.mLineNum).Remove(startPoint.mCharPosition,
                                                                                 endPoint.mCharPosition - startPoint.mCharPosition));
            }
            else
            {
                SetLine(startPoint.mLineNum, GetLine(startPoint.mLineNum).Remove(startPoint.mCharPosition,
                                                                                 startPoint.LineLength - startPoint.mCharPosition) +
                        GetLine(endPoint.mLineNum).Remove(0, endPoint.mCharPosition));
                mLines.RemoveRange((startPoint.mLineNum - 1) + 1, endPoint.mLineNum - startPoint.mLineNum);
            }

            int startLine = startPoint.mLineNum;
            int startChar = startPoint.mCharPosition;
            int endLine   = endPoint.mLineNum;
            int endChar   = endPoint.mCharPosition;

            for (int i = 0; i < mCurrentPoints.Count;)
            {
                WeakReference wr = (WeakReference)mCurrentPoints[i];
                if (wr.IsAlive)
                {
                    TestTextPoint curPoint = (TestTextPoint)wr.Target;
                    if (((curPoint.mLineNum > startLine) ||
                         ((curPoint.mLineNum == startLine) && (curPoint.mCharPosition >= startChar))) &&
                        ((curPoint.mLineNum < endLine) ||
                         ((curPoint.mLineNum == endLine) && (curPoint.mCharPosition <= endChar))))
                    {
                        // point in range of deletion
                        curPoint.mLineNum      = startLine;
                        curPoint.mCharPosition = startChar;
                    }
                    else if ((curPoint.mLineNum == endLine) &&
                             (curPoint.mCharPosition >= endChar))
                    {
                        // point on line after deletion
                        curPoint.mLineNum      = startLine;
                        curPoint.mCharPosition = startChar + (curPoint.mCharPosition - endChar);
                    }
                    else if (curPoint.mLineNum > endLine)
                    {
                        // line after deletion
                        curPoint.mLineNum -= endLine - startLine;
                    }
                    i++;
                }
                else
                {
                    mCurrentPoints.RemoveAt(i);
                }
            }
        }
        public void OnDelete(
            TestTextPoint startPoint,
            object obj)
        {
            TestTextPoint endPoint;
            if (obj is int)
            {
                endPoint = (TestTextPoint) startPoint.CreateEditPoint();
                endPoint.CharRight((int)obj);
            }
            else if (obj is TestTextPoint)
            {
                endPoint = (TestTextPoint) obj;
            }
            else
            {
                throw new System.ArgumentException("Invalid argument");
            }
            if (!endPoint.GreaterThan(startPoint))
            {
                if (endPoint.EqualTo(startPoint))
                {
                    return;
                }
                else
                {
                    throw new System.ArgumentException("Invalid argument");
                }
            }

            if (startPoint.mLineNum == endPoint.mLineNum)
            {
                SetLine(startPoint.mLineNum, GetLine(startPoint.mLineNum).Remove(startPoint.mCharPosition,
                        endPoint.mCharPosition - startPoint.mCharPosition));
            }
            else
            {
                SetLine(startPoint.mLineNum, GetLine(startPoint.mLineNum).Remove(startPoint.mCharPosition,
                                                                           startPoint.LineLength - startPoint.mCharPosition) +
                                           GetLine(endPoint.mLineNum).Remove(0,endPoint.mCharPosition));
                mLines.RemoveRange((startPoint.mLineNum-1)+1,endPoint.mLineNum - startPoint.mLineNum);
            }

            int startLine = startPoint.mLineNum;
            int startChar = startPoint.mCharPosition;
            int endLine = endPoint.mLineNum;
            int endChar = endPoint.mCharPosition;

            for (int i=0; i < mCurrentPoints.Count; )
            {
                WeakReference wr = (WeakReference) mCurrentPoints[i];
                if (wr.IsAlive)
                {
                    TestTextPoint curPoint = (TestTextPoint) wr.Target;
                    if (((curPoint.mLineNum > startLine) ||
                         ((curPoint.mLineNum == startLine) && (curPoint.mCharPosition >= startChar) )) &&
                        ((curPoint.mLineNum < endLine) ||
                         ((curPoint.mLineNum == endLine) && (curPoint.mCharPosition <= endChar) )))
                    {
                        // point in range of deletion
                        curPoint.mLineNum = startLine;
                        curPoint.mCharPosition = startChar;
                    }
                    else if ((curPoint.mLineNum == endLine) &&
                        (curPoint.mCharPosition >= endChar))
                    {
                        // point on line after deletion
                        curPoint.mLineNum = startLine;
                        curPoint.mCharPosition = startChar + (curPoint.mCharPosition - endChar);
                    }
                    else if (curPoint.mLineNum > endLine)
                    {
                        // line after deletion
                        curPoint.mLineNum -= endLine - startLine;
                    }
                    i++;
                }
                else
                {
                    mCurrentPoints.RemoveAt(i);
                }
            }
        }