public DeletePreviousCharacterAction(TextCaret caret)
            {
                Debug.Assert(caret.GetPreviousPosition().IsValid, "Caret previous position not valid");

                caret        = caret.GetPreviousPosition();
                CursorHandle = new DocumentCursorHandle(caret);
                OriginalText = caret.CharacterAfter.Text;
            }
            public SelectionBox(TextCaret caret, Label parent) : base(parent)
            {
                text       = parent.TextBoard;
                this.caret = caret;

                Start          = -Vector2I.One;
                highlightBoard = new MatBoard();
                highlightList  = new List <HighlightBox>();
            }
Example #3
0
        /// <summary> Constructor. </summary>
        protected ConvertTextBlockToTextBlockAction(TextCaret caret)
        {
            _handle = new DocumentCursorHandle(caret);

            var block = caret.Block;

            _originalDescriptor = block.DescriptorHandle;
            _originalProperties = block.SerializeProperties();
        }
        private static MeasuredRectangle MeasureBackward(TextCaret caret, ITextCaretMeasurer measurer)
        {
            if (caret.IsAtBlockStart || caret.Block?.Tag == null)
            {
                return(MeasuredRectangle.Invalid);
            }

            return(measurer.MeasureTextPosition(caret.GetPreviousPosition()));
        }
        private static MeasuredRectangle MeasureForward(TextCaret caret, ITextCaretMeasurer measurer)
        {
            if (caret.IsAtBlockEnd || caret.Block?.Tag == null)
            {
                Debug.Assert(!caret.IsAtBlockEnd, "This usually indicates an error");
                return(MeasuredRectangle.Invalid);
            }

            return(measurer.MeasureTextPosition(caret));
        }
        /// <summary> Get the character before the current cursor position. </summary>
        public static TextUnit GetCharacterBefore(this TextCaret caret)
        {
            if (caret.IsAtBlockStart)
            {
                return(TextUnit.Default);
            }

            caret = caret.GetPreviousPosition();
            return(caret.CharacterAfter);
        }
        public UndoRedoManager(CodeViewer viewer, EditingController editingController)
        {
            Viewer            = viewer;
            EditingController = editingController;
            Caret             = Viewer.Caret;
            Doc              = Viewer.Document;
            Operations       = new Stack <UndoRedoOperation>();
            UndoneOperations = new Stack <UndoRedoOperation>();

            StartNewUndoRedoOperation();
        }
        public static bool TryMoveBackward(ref TextCaret caret)
        {
            TextCaret maybe = caret.GetPreviousPosition();

            if (maybe.IsValid)
            {
                caret = maybe;
                return(true);
            }

            return(false);
        }
        public static TextCaret MoveCursorBackwardBy(this TextCaret cursor, int index)
        {
            int i = index;

            while (i > 0)
            {
                cursor = cursor.GetPreviousPosition();
                i     -= 1;
            }

            return(cursor);
        }
Example #10
0
        public void GetCol_method()
        {
            string sLine = "\t\tab\tx";
            int    iChar;
            int    iTabSize = 4;

            iChar = TextCaret.GetCol(sLine, 0, iTabSize);
            Assert.AreEqual(iChar, 0);
            iChar = TextCaret.GetCol(sLine, 1, iTabSize);
            Assert.AreEqual(iChar, 4);
            iChar = TextCaret.GetCol(sLine, 2, iTabSize);
            Assert.AreEqual(iChar, 8);
            iChar = TextCaret.GetCol(sLine, 3, iTabSize);
            Assert.AreEqual(iChar, 9);
            iChar = TextCaret.GetCol(sLine, 5, iTabSize);
            Assert.AreEqual(iChar, 12);
            iChar = TextCaret.GetCol(sLine, 777, iTabSize);
            Assert.AreEqual(iChar, 13);
        }
Example #11
0
        private void Initialize(string content)
        {
            var index = content.IndexOf("|");

            content = content.Replace("|", "");

            _block = new ParagraphBlock();
            _caret = _block.Content.GetCaretAtStart();
            _caret.InsertText(content);
            _caret = _block.Content.GetCaretAtStart();

            if (index > 0)
            {
                _caret = _caret.MoveCursorForwardBy(index);
            }

            _collection = new AddableBlockCollection()
            {
                _block
            };
        }
        /// <summary>
        ///   Get the bounds of the given caret position.
        /// </summary>
        public static MeasuredRectangle Measure(TextCaret caret, ITextCaretMeasurer measurer)
        {
            bool isAtBlockStart = caret.IsAtBlockStart;
            bool isAtBlockEnd   = caret.IsAtBlockEnd;

            if (isAtBlockStart && isAtBlockEnd)
            {
                // if it's empty, there is no character to measure
                return(measurer.MeasureSelectionBounds().FlattenLeft());
            }

            // we want to measure the next character unless the previous character was
            // a space (as the text will most likely appear on the next line anyways)
            // TODO account for more whitespace
            bool shouldMeasureNext = isAtBlockStart ||
                                     (!isAtBlockEnd && caret.GetPreviousPosition().CharacterAfter.Text == " ");

            return(shouldMeasureNext
        ? MeasureForward(caret, measurer).FlattenLeft()
        : MeasureBackward(caret, measurer).FlattenRight());
        }
        private double UpdateMovementMode(CaretMovementMode movementMode, TextCaret caret)
        {
            switch (movementMode.CurrentMode)
            {
            case CaretMovementMode.Mode.None:
                var position = TextCaretMeasurerHelper.Measure(caret).Left;
                movementMode.SetModeToPosition(position);
                return(position);

            case CaretMovementMode.Mode.Position:
                return(movementMode.Position);

            case CaretMovementMode.Mode.Home:
                return(0);

            case CaretMovementMode.Mode.End:
                return(double.MaxValue);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary> Breaks the block into two at the given location. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="caret"> The caret at which the block should be split. </param>
        /// <returns>
        ///  A caret pointing to the beginning of the block that follows the block that was split.  Will
        ///  be TextCaret.Invalid if the block could not be split.
        /// </returns>
        public static TextCaret TryBreakBlock(TextCaret caret)
        {
            if (!caret.IsValid)
            {
                throw new ArgumentException("invalid caret", nameof(caret));
            }

            if (!CanBreak(caret))
            {
                return(TextCaret.Invalid);
            }

            var targetBlock     = caret.Block;
            var blockCollection = targetBlock.Parent;

            if (caret.IsAtBlockEnd)
            {
                var secondaryBlock = (TextBlock)CreateSimilarBlock(targetBlock);
                blockCollection.InsertBlockAfter(targetBlock, secondaryBlock);
                return(secondaryBlock.Content.GetCaretAtEnd());
            }

            if (caret.IsAtBlockStart)
            {
                blockCollection.InsertBlockBefore(targetBlock, CreateSimilarBlock(targetBlock));
                return(targetBlock.Content.GetCaretAtStart());
            }

            var textBlockContent = caret.Content;
            var extractedContent = textBlockContent.ExtractContent(caret, textBlockContent.GetCaretAtEnd());

            var newTextBlock = (TextBlock)CreateSimilarBlock(targetBlock);

            newTextBlock.Content = extractedContent;
            blockCollection.InsertBlockAfter(targetBlock, newTextBlock);

            return(newTextBlock.Content.GetCaretAtStart());
        }
        public TextBox(HudParentBase parent) : base(parent)
        {
            MouseInput = new MouseInputElement(this)
            {
                ShareCursor = true
            };
            textInput = new TextInput(AddChar, RemoveLastChar, TextInputFilter);

            caret = new TextCaret(this)
            {
                Visible = false
            };
            selectionBox = new SelectionBox(caret, this)
            {
                Color = new Color(255, 255, 255, 140)
            };

            warningToolTip = new ToolTip()
            {
                text    = "Open Chat to Enable Text Editing",
                bgColor = ToolTip.orangeWarningBG
            };

            caret.CaretMoved            += CaretMoved;
            MouseInput.GainedInputFocus += GainFocus;
            MouseInput.LostInputFocus   += LoseFocus;

            ShareCursor        = true;
            EnableEditing      = true;
            EnableHighlighting = true;
            UseCursor          = true;

            MoveToEndOnGainFocus      = false;
            ClearSelectionOnLoseFocus = true;

            Size = new Vector2(60f, 200f);
        }
Example #16
0
 public DeleteNextCharacterAction(TextCaret caret)
 {
     _cursorHandle = new DocumentCursorHandle(caret);
     _originalText = caret.CharacterAfter.Text;
 }
 /// <summary> Creates a cursor handle from the given content cursor. </summary>
 public static DocumentCursorHandle ToHandle(this TextCaret caret)
 => new DocumentCursorHandle(caret);
 /// <summary> Constructor. </summary>
 public ConvertTextBlockIntoHeadingAction(TextCaret caret, int level)
     : base(caret)
 {
     _level = level;
 }
 /// <summary>
 ///  True if the block can break into two at the given position.
 /// </summary>
 /// <param name="cursor"> The caret that specified the position. </param>
 /// <returns> true if we can break, false if not. </returns>
 public static bool CanBreak(TextCaret cursor)
 => true; // TODO
Example #20
0
        //=========================================================================================
        /// <summary>Если токен многострочный, разбиваем его на строки и добавляем в очередь.</summary>
        private void EnqueueMultilineToken(string text, TextPoint startPoint, TextPoint endPoint)
        {
            TextStyle oStyle = null;

            ///Если текст однострочный
            if (text.IndexOf('\n') < 0)
            {
                var oToken = new Token(
                    this.CurrentToken.TokenTypeName,
                    text, startPoint, endPoint, this.CurrentToken.Style);
                oToken.Style = this.Settings.GetStyleFor(oToken, this.CurrentState.StyleName);
                this.TokenPool.Enqueue(oToken);
            }
            else
            {
                ///Разбиваем текст на строки
                List <string> lines = TextSplitter.SplitTextToLines(text);

                ///Первая строка
                {
                    string sLine = lines[0];
                    ///Начало токена
                    var startTokenPoint = startPoint;
                    ///Конец токена
                    int iChar         = startPoint.Char + sLine.Length;
                    int iCol          = iChar;                  //TODO: если перед нашим токеном были табы, то iCol мы вычисляем неверно.
                    var endTokenPoint = new TextPoint(startTokenPoint.Line, iCol, iChar);
                    ///Создаем токен
                    var oToken = new Token(
                        this.CurrentToken.TokenTypeName,
                        sLine, startPoint, endTokenPoint, this.CurrentToken.Style);
                    ///Выясняем стиль
                    oStyle       = this.Settings.GetStyleFor(oToken, this.CurrentState.StyleName);
                    oToken.Style = oStyle;
                    ///Добавляем в очередь
                    this.TokenPool.Enqueue(oToken);
                }

                ///Проходим по остальным строкам
                for (int iLine = 1; iLine < lines.Count; iLine++)
                {
                    string sLine = lines[iLine];
                    if (sLine.Length == 0)
                    {
                        continue;
                    }
                    ///Начало токена
                    var startTokenPoint = new TextPoint(startPoint.Line + iLine, 0, 0);
                    ///Конец токена
                    int iChar         = startTokenPoint.Char + sLine.Length;
                    int iCol          = TextCaret.GetCol(sLine, iChar, this.Scanner.TabSize);
                    var endTokenPoint = new TextPoint(startTokenPoint.Line, iCol, iChar);
                    ///Создаем токен
                    var oToken = new Token(
                        this.CurrentToken.TokenTypeName,
                        sLine, startTokenPoint, endTokenPoint, this.CurrentToken.Style);
                    ///Выясняем стиль
                    oToken.Style = oStyle;
                    ///Добавляем в очередь
                    this.TokenPool.Enqueue(oToken);
                }
            }
        }
 public ConvertIntoParagraphAction(TextCaret caret)
     : base(caret)
 {
 }
Example #22
0
        //=========================================================================================
        /// <summary>Найти начало и конец слова, определенного позицией col.</summary>
        public static int[] GetWord(string line, int chr, int tabsize)
        {
            int iStart, iEnd;

            if (chr >= line.Length)
            {
                //Последнее слово
                line = line.TrimEnd();
                if (line.Length == 0)
                {
                    return new int[] { 0, 0 }
                }
                ;
                LetterType letterType = GetLetterType(line[line.Length - 1]);
                iStart = GetFirstLetter(line, line.Length, letterType);
                iEnd   = line.Length;
            }
            else if (chr == 0)
            {
                if (line.Length == 0)
                {
                    return new int[] { 0, 0 }
                }
                ;
                LetterType letterType = GetLetterType(line[0]);

                iStart = 0;
                if (letterType == LetterType.WhiteSpace)
                {
                    iEnd = line.Length - line.TrimStart().Length;
                }
                else
                {
                    iEnd = GetLastLetter(line, 0, letterType);
                }
            }
            else if (!char.IsWhiteSpace(line, chr))
            {
                //Текущее слово
                LetterType letterType = GetLetterType(line[chr]);
                iStart = GetFirstLetter(line, chr, letterType);
                iEnd   = GetLastLetter(line, chr, letterType);
            }
            else if (!char.IsWhiteSpace(line, chr - 1))
            {
                //Предыдущее слово
                LetterType letterType = GetLetterType(line[chr - 1]);
                iStart = GetFirstLetter(line, chr - 1, letterType);
                iEnd   = chr;
            }
            else
            {
                //Текущий набор пробелов
                LetterType letterType = LetterType.WhiteSpace;
                iStart = GetFirstLetter(line, chr, letterType);
                iEnd   = GetLastLetter(line, chr, letterType);
            }
            iStart = TextCaret.GetCol(line, iStart, tabsize);
            iEnd   = TextCaret.GetCol(line, iEnd, tabsize);

            return(new int[] { iStart, iEnd });
        }
 public static MeasuredRectangle Measure(TextCaret caret)
 => caret.Block.GetView <ITextBlockView>().Measure(caret);