예제 #1
0
        private void ExecuteInsertTextCommand(ref int iChar, string text)
        {
            var lines = text.Split('\n');
            var iLine = 0;

            foreach (var r in range.GetSubRanges(true))
            {
                var line        = ts.CurrentTB[r.Start.iLine];
                var lineIsEmpty = r.End < r.Start && line.StartSpacesCount == line.Count;
                if (!lineIsEmpty)
                {
                    var insertedText = lines[iLine % lines.Length];
                    if (r.End < r.Start && insertedText != "")
                    {
                        //add forwarding spaces
                        insertedText = new string(' ', r.Start.iChar - r.End.iChar) + insertedText;
                        r.Start      = r.End;
                    }
                    ts.CurrentTB.Selection = r;
                    var c = new InsertTextCommand(ts, insertedText);
                    c.Execute();
                    if (ts.CurrentTB.Selection.End.iChar > iChar)
                    {
                        iChar = ts.CurrentTB.Selection.End.iChar;
                    }
                    commandsByRanges.Add(c);
                }
                iLine++;
            }
        }
예제 #2
0
        /// <summary>
        /// Execute operation
        /// </summary>
        public override void Execute()
        {
            var tb = ts.CurrentTB;

            prevText.Clear();

            ts.OnTextChanging(ref insertedText);

            tb.Selection.BeginUpdate();
            tb.BeginUpdate();
            for (int i = ranges.Count - 1; i >= 0; i--)
            {
                tb.Selection.Start = ranges[i].Start;
                tb.Selection.End   = ranges[i].End;
                prevText.Add(tb.Selection.Text);
                ClearSelected(ts);
                if (insertedText != "")
                {
                    InsertTextCommand.InsertText(insertedText, ts);
                }
            }
            if (ranges.Count > 0)
            {
                ts.OnTextChanged(ranges[0].Start.iLine, ranges[ranges.Count - 1].End.iLine);
            }
            tb.EndUpdate();
            tb.Selection.EndUpdate();
            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));

            lastSel = new RangeInfo(tb.Selection);
        }
예제 #3
0
        /// <summary>
        /// Undo operation
        /// </summary>
        public override void Undo()
        {
            var tb = ts.CurrentTB;

            ts.OnTextChanging();
            tb.BeginUpdate();

            tb.Selection.BeginUpdate();
            for (int i = 0; i < ranges.Count; i++)
            {
                tb.Selection.Start = ranges[i].Start;
                for (int j = 0; j < insertedText.Length; j++)
                {
                    tb.Selection.GoRight(true);
                }
                ClearSelected(ts);
                InsertTextCommand.InsertText(prevText[prevText.Count - i - 1], ts);
            }
            tb.Selection.EndUpdate();
            tb.EndUpdate();

            if (ranges.Count > 0)
            {
                ts.OnTextChanged(ranges[0].Start.iLine, ranges[ranges.Count - 1].End.iLine);
            }

            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));
        }
예제 #4
0
        public void TestUndoRedoCommand()
        {
            // Arrange
            var project = new Project();
            var context = new BlockCommandContext(project);
            ProjectBlockCollection blocks = project.Blocks;
            Block block = blocks[0];

            using (block.AcquireBlockLock(RequestLock.Write))
            {
                block.SetText("abcd");
            }
            int      blockVersion = block.Version;
            BlockKey blockKey     = block.BlockKey;

            var command = new InsertTextCommand(new BlockPosition(blockKey, 2), "YES");

            project.Commands.Do(command, context);
            project.Commands.Undo(context);

            // Act
            project.Commands.Redo(context);

            // Assert
            Assert.AreEqual(1, blocks.Count);
            Assert.AreEqual(
                new BlockPosition(blocks[0], 5), project.Commands.LastPosition);

            const int index = 0;

            Assert.AreEqual("abYEScd", blocks[index].Text);
            Assert.AreEqual(blockVersion + 3, blocks[index].Version);
        }
예제 #5
0
 /// <summary>
 /// Undo operation
 /// </summary>
 public override void Undo()
 {
     ts.CurrentTB.Selection.Start = new Place(sel.FromX, Math.Min(sel.Start.iLine, sel.End.iLine));
     ts.OnTextChanging();
     InsertTextCommand.InsertText(deletedText, ts);
     ts.OnTextChanged(sel.Start.iLine, sel.End.iLine);
     ts.CurrentTB.Selection.Start = sel.Start;
     ts.CurrentTB.Selection.End   = sel.End;
 }
        public ProjectInsertTextCommand(
            Project project,
            TextPosition textPosition,
            string text)
            : base(project)
        {
            // Create the project command wrapper.
            var command = new InsertTextCommand(textPosition, text);

            // Set the command into the adapter.
            Command = command;
        }
        public void InsertTextWithCRLF()
        {
            FastColoredTextBox fctb = new FastColoredTextBox();
            string insertedText = GetCRLFLine();
            var command = new InsertTextCommand(fctb.TextSource, insertedText);

            Assert.AreEqual("", fctb.Text);
            command.Execute();
            Assert.AreEqual(GetCRLFLine(), fctb.Text);
            command.Undo();
            Assert.AreEqual("", fctb.Text);
        }
        public override LineBufferOperationResults InsertText(
            int lineIndex,
            int characterIndex,
            string text)
        {
            using (project.Blocks.AcquireLock(RequestLock.Write))
            {
                Block block    = project.Blocks[lineIndex];
                var   position = new BlockPosition(block.BlockKey, characterIndex);
                var   command  = new InsertTextCommand(position, text);
                var   context  = new BlockCommandContext(project);
                project.Commands.Do(command, context);

                return(GetOperationResults());
            }
        }
예제 #9
0
        /// <summary>
        /// Undo operation
        /// </summary>
        public override void Undo()
        {
            var tb = ts.CurrentTB;

            ts.OnTextChanging();

            tb.Selection.BeginUpdate();
            //tb.BeginUpdate();
            for (int i = 0; i < iLines.Count; i++)
            {
                var iLine = iLines[i];

                if (iLine < ts.Count)
                {
                    tb.Selection.Start = new Place(0, iLine);
                }
                else
                {
                    tb.Selection.Start = new Place(ts[ts.Count - 1].Count, ts.Count - 1);
                }

                InsertCharCommand.InsertLine(ts);
                tb.Selection.Start = new Place(0, iLine);
                var text = prevText[prevText.Count - i - 1];
                InsertTextCommand.InsertText(text, ts);
                ts[iLine].IsChanged = true;
                if (iLine < ts.Count - 1)
                {
                    ts[iLine + 1].IsChanged = true;
                }
                else
                {
                    ts[iLine - 1].IsChanged = true;
                }
                if (text.Trim() != string.Empty)
                {
                    ts.OnTextChanged(iLine, iLine);
                }
            }
            //tb.EndUpdate();
            tb.Selection.EndUpdate();

            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));
        }
        public void InsertEOL()
        {
            FastColoredTextBox fctb = new FastColoredTextBox();

            string insertedText = "foobaar";
            var command = new InsertTextCommand(fctb.TextSource, insertedText);

            command.Execute();

            Assert.AreEqual("foobaar", fctb.Text);

            fctb.Selection = new Range(fctb, 3,0,3,0);
            command = new InsertTextCommand(fctb.TextSource, "\n");

            command.Execute();

            Assert.AreEqual("foo\nbaar", fctb.Text);

            command.Undo();
            Assert.AreEqual("foobaar", fctb.Text);
        }
예제 #11
0
        /// <summary>
        /// Undo operation
        /// </summary>
        public override void Undo()
        {
            var tb = ts.CurrentTB;

            ts.OnTextChanging();

            tb.Selection.BeginUpdate();
            for (int i = 0; i < ranges.Count; i++)
            {
                tb.Selection.Start = ranges[i].ReplacedRange.Start;
                for (int j = 0; j < ranges[i].ReplaceText.Length; j++)
                {
                    tb.Selection.GoRight(true);
                }
                ClearSelectedCommand.ClearSelected(ts);
                var prevTextIndex = ranges.Count - 1 - i;
                InsertTextCommand.InsertText(prevText[prevTextIndex], ts);
                ts.OnTextChanged(ranges[i].ReplacedRange.Start.iLine, ranges[i].ReplacedRange.Start.iLine);
            }
            tb.Selection.EndUpdate();

            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));
        }