Exemple #1
0
        public static void Right(EditorViewController controller)
        {
            // Pull out some useful variables.
            IDisplayContext displayContext = controller.DisplayContext;
            LineBuffer      lineBuffer     = displayContext.LineBuffer;

            // Move the character position based on line context.
            TextPosition      position          = displayContext.Caret.Position;
            LinePosition      linePosition      = position.LinePosition;
            int               lineIndex         = linePosition.GetLineIndex(lineBuffer);
            int               lineLength        = lineBuffer.GetLineLength(lineIndex);
            CharacterPosition characterPosition = position.CharacterPosition;
            int               characterIndex    = position.GetCharacterIndex(lineBuffer);

            if (characterIndex == lineLength)
            {
                if (lineIndex < lineBuffer.LineCount - 1)
                {
                    linePosition      = new LinePosition(lineIndex + 1);
                    characterPosition = CharacterPosition.Begin;
                }
            }
            else
            {
                characterPosition = new CharacterPosition(characterIndex + 1);
            }

            // Cause the text editor to redraw itself.
            var caretPosition = new TextPosition(linePosition, characterPosition);

            displayContext.ScrollToCaret(caretPosition);
        }