Exemplo n.º 1
0
        public void ProcessDeletion(bool backward)
        {
            SaveCurrentOperationToStack();

            var start     = Viewer.GetSelectionBoundary(true);
            var end       = Viewer.GetSelectionBoundary(false);
            var operation = new UndoRedoOperation
            {
                Type      = UndoRedoOperationType.Remove,
                StartLine = start.Line,
                StartChar = start.Char,
                EndLine   = end.Line,
                EndChar   = end.Char,
            };

            if (!Viewer.SelectionExists)
            {
                if (backward)
                {
                    operation.Text = Viewer.Caret.Char > 0 ? Doc[Viewer.Caret.Line].Text[Viewer.Caret.Char - 1].ToString() : "\r\n";
                }
                else
                {
                    if (Viewer.Caret.Char < Doc[Viewer.Caret.Line].Text.Length)
                    {
                        operation.Text = Doc[Viewer.Caret.Line].Text[Viewer.Caret.Char].ToString();
                    }
                    else
                    {
                        operation.Text = "\r\n";
                    }
                }
            }
            else
            {
                operation.Text = Viewer.SelectionText;
            }
            Operations.Push(operation);
        }
Exemplo n.º 2
0
        //=========================================================================================
        internal bool PasteFromClipboard()
        {
            if (this.ClipboardProxy == null)
            {
                this.ClipboardProxy = ClipboardProxyClass.Self;
            }
            if (!this.ClipboardProxy.ContainsText())
            {
                return(false);
            }

            string text         = ClipboardProxy.GetText();
            var    startPoint   = Viewer.GetSelectionBoundary(true);
            string previousText = Viewer.SelectionText;

            PasteText(text);

            UndoRedoManager.ProcessPaste(startPoint.Line, startPoint.Col, text, previousText);

            this.InitTokens();
            this.Viewer.Body.Invalidate(false);
            return(true);
        }