Example #1
0
        /// <summary>
        /// Calculate index of the location
        /// where the caret should move to after pressing "up" key.
        /// </summary>
        public static int Calc_Up(IViewInternal view)
        {
            Point    pt;
            int      newIndex;
            Document doc = view.Document;

            // get screen location of the caret
            pt = view.GetVirPosFromIndex(doc.CaretIndex);

            // calculate next location
            pt.X     = view.GetDesiredColumn();
            pt.Y    -= view.LineSpacing;
            newIndex = view.GetIndexFromVirPos(pt);
            if (newIndex < 0)
            {
                return(doc.CaretIndex);                // don't move
            }

            // In line selection mode,
            // moving caret across the line which contains the anchor position
            // should select the line and a line above.
            // To select a line above, calculate index of the char at one more line above.
            if (doc.SelectionMode == TextDataType.Line &&
                newIndex == doc.AnchorIndex &&
                view.IsLineHeadIndex(newIndex))
            {
                pt.Y -= view.LineSpacing;
                if (0 <= pt.Y)
                {
                    newIndex = view.GetIndexFromVirPos(pt);
                }
            }

            return(newIndex);
        }
Example #2
0
        /// <summary>
        /// Calculate index of the location
        /// where the caret should move to after pressing "down" key.
        /// </summary>
        public static int Calc_Down(IViewInternal view)
        {
            Point    pt;
            int      newIndex;
            Document doc = view.Document;

            // get screen location of the caret
            pt = view.GetVirPosFromIndex(doc.CaretIndex);

            // calculate next location
            pt.X  = view.GetDesiredColumn();
            pt.Y += view.LineSpacing;

            /* NOT NEEDED because View.GetIndexFromVirPos handles this case.
             * if( view.Height - view.LineSpacing < pt.Y )
             * {
             *      return doc.CaretIndex; // no lines below. don't move.
             * }*/
            newIndex = view.GetIndexFromVirPos(pt);

            // In line selection mode,
            // moving caret across the line which contains the anchor position
            // should select the line and a line below.
            // To select a line below, calculate index of the char at one more line below.
            if (doc.SelectionMode == TextDataType.Line &&
                view.IsLineHeadIndex(newIndex))
            {
                Point pt2             = new Point(pt.X, pt.Y + view.LineSpacing);
                int   skippedNewIndex = view.GetIndexFromVirPos(pt2);
                if (skippedNewIndex == doc.AnchorIndex)
                {
                    newIndex = skippedNewIndex;
                }
            }

            return(newIndex);
        }