コード例 #1
0
        public PasteCommand(
            ITextEditingCommandController <TContext> controller,
            TextPosition position,
            string text)
            : base(true, false)
        {
            // Split the clipboard text into different lines.
            string[] lines = text.Split('\n');

            // If we have only one line, then we just insert the command.
            if (lines.Length == 1)
            {
                IInsertTextCommand <TContext> singleCommand =
                    controller.CreateInsertTextCommand(position, text);
                singleCommand.UpdateTextPosition = DoTypes.All;

                Commands.Add(singleCommand);

                return;
            }

            // Start by splitting the first paragraph at that position.
            var splitCommand = new SplitParagraphCommand <TContext>(controller, position);

            Commands.Add(splitCommand);

            // The first line is inserted into at the position.
            IInsertTextCommand <TContext> firstCommand =
                controller.CreateInsertTextCommand(position, lines[0]);

            firstCommand.UpdateTextPosition = DoTypes.All;

            Commands.Add(firstCommand);

            // Loop through and add all the blank lines we'll need for the paste
            // operation.
            for (int i = 2;
                 i < lines.Length;
                 i++)
            {
                IInsertLineCommand <TContext> lineCommand =
                    controller.CreateInsertLineCommand((int)position.LinePosition + 1);

                Commands.Add(lineCommand);
            }

            // For every other line, we add the line and paste it.
            for (int i = 1;
                 i < lines.Length;
                 i++)
            {
                IInsertTextCommand <TContext> textCommand =
                    controller.CreateInsertTextCommand(
                        new TextPosition((int)position.LinePosition + i, CharacterPosition.Begin),
                        lines[i]);
                textCommand.UpdateTextPosition = DoTypes.DoAndRedo;

                Commands.Add(textCommand);
            }
        }
コード例 #2
0
        public SplitParagraphCommand(
            ITextEditingCommandController <TContext> controller,
            TextPosition position)
            : base(true, false)
        {
            // The split paragraph consists of inserting a new line, pasting the
            // text to the right of the position into that one, and then removing
            // the text from the current line.
            var line = (int)position.LinePosition;

            // Start by inserting the new line.
            IInsertLineCommand <TContext> insertLineCommand =
                controller.CreateInsertLineCommand((int)position.LinePosition + 1);

            insertLineCommand.UpdateTextPosition = DoTypes.All;

            // Insert the text from the line into the nmew line.
            IInsertTextFromTextRangeCommand <TContext> insertTextCommand =
                controller.CreateInsertTextFromTextRangeCommand(
                    new TextPosition((line + 1), CharacterPosition.Begin),
                    new SingleLineTextRange(
                        position.LinePosition, position.CharacterPosition, CharacterPosition.End));

            // Delete the text from the current line.
            IDeleteTextCommand <TContext> deleteTextCommand =
                controller.CreateDeleteTextCommand(
                    new SingleLineTextRange(
                        line, position.CharacterPosition, CharacterPosition.End));

            // Add the commands into the composite and indicate that the whitespace
            // command controls where the text position will end up.
            Commands.Add(insertLineCommand);
            Commands.Add(insertTextCommand);
            Commands.Add(deleteTextCommand);
        }