public void TestCommand()
        {
            // Arrange
            ProjectBlockCollection blocks;
            BlockCommandSupervisor commands;
            BlockTypeSupervisor blockTypes;
            BlockCommandContext context;
            SetupMultilineTest(out context, out blocks, out blockTypes, out commands);

            // Act
            var command = new ChangeBlockTypeCommand(
                blocks[0].BlockKey, blockTypes.Paragraph);
            commands.Do(command, context);

            // Assert
            Assert.AreEqual(4, blocks.Count);
            Assert.AreEqual(new BlockPosition(blocks[0], 0), commands.LastPosition);

            int index = 0;
            Assert.AreEqual("Line 1", blocks[index].Text);
            Assert.AreEqual(blockTypes.Paragraph, blocks[index].BlockType);

            index++;
            Assert.AreEqual("Line 2", blocks[index].Text);
            Assert.AreEqual(blockTypes.Scene, blocks[index].BlockType);

            index++;
            Assert.AreEqual("Line 3", blocks[index].Text);
            Assert.AreEqual(blockTypes.Scene, blocks[index].BlockType);

            index++;
            Assert.AreEqual("Line 4", blocks[index].Text);
            Assert.AreEqual(blockTypes.Scene, blocks[index].BlockType);
        }
        public void ProcessImmediateEdits(
			BlockCommandContext context,
			Block block,
			int textIndex)
        {
            // Get the plugin settings from the project.
            ImmediateBlockTypesSettings settings = Settings;

            // Grab the substring from the beginning to the index and compare that
            // in the dictionary.
            string text = block.Text.Substring(0, textIndex);

            if (!settings.Replacements.ContainsKey(text))
            {
                // We want to fail as fast as possible.
                return;
            }

            // If the block type is already set to the same name, skip it.
            string blockTypeName = settings.Replacements[text];
            BlockType blockType = Project.BlockTypes[blockTypeName];

            if (block.BlockType == blockType)
            {
                return;
            }

            // Perform the substitution with a replace operation and a block change
            // operation.
            var replaceCommand =
                new ReplaceTextCommand(
                    new BlockPosition(block.BlockKey, 0), textIndex, string.Empty);
            var changeCommand = new ChangeBlockTypeCommand(block.BlockKey, blockType);

            // Create a composite command that binds everything together.
            var compositeCommand = new CompositeCommand<BlockCommandContext>(true, false);

            compositeCommand.Commands.Add(replaceCommand);
            compositeCommand.Commands.Add(changeCommand);

            // Add the command to the deferred execution so the command could
            // be properly handled via the undo/redo management.
            block.Project.Commands.DeferDo(compositeCommand);
        }