This class implements enough of the EnvDTE.TextPoint and EnvDTE.EditPoint intefaces to allow regression testing
Inheritance: EnvDTE.TextPoint, EnvDTE.EditPoint
Example #1
0
        public void OnInsert(
            TestTextPoint startPoint,
            string st)
        {
            int startLine             = startPoint.mLineNum;
            int startChar             = startPoint.mCharPosition;
            int charsPushedOnNextLine = 0; // chars after last carriage return
            int linesPushedDown       = 0; // number carriage returns

            if (st[0] == '\n')
            {
                string temp = GetLine(startLine).Substring(startChar);
                SetLine(startLine, GetLine(startLine).Substring(0, startChar));
                mLines.Insert(startLine, st.Substring(1) + temp);

                linesPushedDown       = 1;
                charsPushedOnNextLine = st.Length - 1;
            }
            else if (st[0] == '\r')
            {
                string temp = GetLine(startLine).Substring(startChar);
                SetLine(startLine, GetLine(startLine).Substring(0, startChar));
                mLines.Insert(startLine, st.Substring(2) + temp);

                linesPushedDown       = 1;
                charsPushedOnNextLine = st.Length - 2;
            }
            else
            {
                SetLine(startLine, GetLine(startPoint.mLineNum).Insert(startChar, st));
                charsPushedOnNextLine = st.Length + startChar;
            }

            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.mCharPosition >= startChar))
                    {
                        curPoint.mLineNum     += linesPushedDown;
                        curPoint.mCharPosition = (curPoint.mCharPosition - startChar) +
                                                 charsPushedOnNextLine;
                    }
                    else if (curPoint.mLineNum > startLine)
                    {
                        curPoint.mLineNum += linesPushedDown;
                    }
                    i++;
                }
                else
                {
                    mCurrentPoints.RemoveAt(i);
                }
            }
        }
Example #2
0
 public EnvDTE.EditPoint CreateEditPoint(EnvDTE.TextPoint tp)
 {
     EnvDTE.EditPoint ret;
     if (tp == null)
     {
         ret = new TestTextPoint(this, 1, 1);
     }
     else
     {
         ret = new TestTextPoint(this, tp.Line, tp.LineCharOffset);
     }
     mCurrentPoints.Add(new WeakReference(ret));
     return(ret);
 }
        public string GetText(object obj)
        {
            // FIXME: this function is not implemented to handle multiple lines!!!!

            if (obj is int)
            {
                int val = (int)obj;

                if ((val == -1) && (mCharPosition == 0))
                {
                    // ugly hack!
                    return("\r\n");
                }

                return(mParent.GetLine(mLineNum).Substring(mCharPosition, val));
            }
            else if (obj is TestTextPoint)
            {
                TestTextPoint end = (TestTextPoint)obj;
                return(mParent.GetLine(mLineNum).Substring(mCharPosition, end.mCharPosition - mCharPosition));
            }

            return("");
        }
Example #4
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 OnInsert(
            TestTextPoint startPoint,
            string st)
        {
            int startLine = startPoint.mLineNum;
            int startChar = startPoint.mCharPosition;
            int charsPushedOnNextLine=0;// chars after last carriage return
            int linesPushedDown=0;// number carriage returns

            if (st[0] == '\n')
            {
                string temp = GetLine(startLine).Substring(startChar);
                SetLine(startLine,GetLine(startLine).Substring(0,startChar));
                mLines.Insert(startLine,st.Substring(1) + temp);

                linesPushedDown = 1;
                charsPushedOnNextLine = st.Length-1;
            }
            else if (st[0] == '\r')
            {
                string temp = GetLine(startLine).Substring(startChar);
                SetLine(startLine,GetLine(startLine).Substring(0,startChar));
                mLines.Insert(startLine,st.Substring(2) + temp);

                linesPushedDown = 1;
                charsPushedOnNextLine = st.Length-2;
            }
            else
            {
                SetLine(startLine, GetLine(startPoint.mLineNum).Insert(startChar,st));
                charsPushedOnNextLine = st.Length+startChar;
            }

            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.mCharPosition >= startChar))
                    {
                        curPoint.mLineNum += linesPushedDown;
                        curPoint.mCharPosition = (curPoint.mCharPosition - startChar) +
                                                 charsPushedOnNextLine;
                    }
                    else if (curPoint.mLineNum > startLine)
                    {
                        curPoint.mLineNum += linesPushedDown;
                    }
                    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);
                }
            }
        }
 public EnvDTE.EditPoint CreateEditPoint(EnvDTE.TextPoint tp)
 {
     EnvDTE.EditPoint ret;
     if (tp == null)
     {
         ret = new TestTextPoint(this,1,1);
     }
     else
     {
         ret = new TestTextPoint(this,tp.Line, tp.LineCharOffset);
     }
     mCurrentPoints.Add(new WeakReference(ret));
     return ret;
 }