protected override void Do( BlockCommandContext context, Block block) { // Save the previous text so we can restore it. previousText = block.Text; originalPosition = context.Position; // Figure out what the new text string would be. startIndex = BlockPosition.TextIndex.GetCharacterIndex( block.Text, End, WordSearchDirection.Left); int endIndex = End.GetCharacterIndex( block.Text, TextIndex, WordSearchDirection.Right); int firstIndex = Math.Min(startIndex, endIndex); int lastIndex = Math.Max(startIndex, endIndex); string newText = block.Text.Remove(firstIndex, lastIndex - firstIndex); // Set the new text into the block. This will fire various events to // trigger the immediate and background processing. block.SetText(newText); // Set the position after the next text. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(BlockKey, startIndex); } }
public override void Do(OperationContext state) { // Grab the line from the line buffer. string lineText = state.LineBuffer.GetLineText( (int)TextPosition.LinePosition, LineContexts.Unformatted); var buffer = new StringBuilder(lineText); // Normalize the character ranges. int characterIndex = TextPosition.CharacterPosition.GetCharacterIndex(lineText); buffer.Insert(characterIndex, Text); originalInsertPoint = characterIndex; originalPosition = state.Position; // Set the line in the buffer. lineText = buffer.ToString(); state.LineBuffer.SetText((int)TextPosition.LinePosition, lineText); // If we are updating the position, we need to do it here. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { state.Results = new LineBufferOperationResults( new TextPosition(TextPosition.LinePosition, characterIndex + Text.Length)); } }
/// <summary> /// Performs the command on the given block. /// </summary> /// <param name="context"></param> /// <param name="block">The block to perform the action on.</param> /// <param name="project">The project that contains the current state.</param> protected override void Do( BlockCommandContext context, Block block) { // Save the previous text so we can undo it. previousText = block.Text; // Figure out what the new text string would be. int textIndex = new CharacterPosition(TextIndex).GetCharacterIndex( block.Text); string newText = block.Text.Insert(textIndex, Text); // Set the new text into the block. This will fire various events to // trigger the immediate and background processing. block.SetText(newText); // After we insert text, we need to give the immediate editor plugins a // chance to made any alterations to the output. block.Project.Plugins.ProcessImmediateEdits( context, block, textIndex + Text.Length); // Set the new position in the buffer. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(BlockKey, textIndex + Text.Length); } }
public void Undo(BlockCommandContext context) { // Grab the destination block and make sure everything is locked properly. Block block; using ( context.Blocks.AcquireBlockLock( RequestLock.Write, RequestLock.Write, (int)DestinationPosition.LinePosition, out block)) { // Grab the line from the line buffer. string lineText = block.Text; var buffer = new StringBuilder(lineText); // Normalize the character ranges. buffer.Remove(originalCharacterIndex, sourceLength); // Set the line in the buffer. lineText = buffer.ToString(); block.SetText(lineText); // Set the position of this command. if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { context.Position = new BlockPosition( block.BlockKey, DestinationPosition.CharacterPosition); } } }
public override void Undo(OperationContext state) { // Grab the line from the line buffer. int lineIndex = TextRange.LinePosition.GetLineIndex(state.LineBuffer.LineCount); string lineText = state.LineBuffer.GetLineText( lineIndex, LineContexts.Unformatted); var buffer = new StringBuilder(lineText); // Normalize the character ranges. buffer.Insert(beginCharacterIndex, originalText); // Set the line in the buffer. lineText = buffer.ToString(); state.LineBuffer.SetText(lineIndex, lineText); // If we are updating the position, we need to do it here. if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { state.Results = new LineBufferOperationResults( new TextPosition( originalPosition.LinePosition.Index, originalPosition.CharacterPosition.Index)); } }
protected override void Do( BlockCommandContext context, Block block) { // Pull out some common elements we'll need. ProjectBlockCollection blocks = block.Blocks; int blockIndex = blocks.IndexOf(block) + 1; // Because of how block keys work, the ID is unique very time so we have // to update our inverse operation. addedBlocks.Clear(); // Go through and create each block at a time, adding it to the inverse // command as we create them. for (int count = 0; count < Count; count++) { // Create and insert a new block into the system. var newBlock = new Block(blocks); blocks.Insert(blockIndex, newBlock); // Keep track of the block so we can remove them later. addedBlocks.Add(newBlock); // Update the position. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(newBlock.BlockKey, 0); } } }
protected override void Undo( BlockCommandContext context, Block block) { block.SetText(previousText); if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { context.Position = new BlockPosition(BlockKey, previousText.Length); } }
protected override void Undo( BlockCommandContext context, Block block) { block.SetText(previousText); if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { context.Position = originalPosition; } }
protected override void Do( BlockCommandContext context, Block block) { previousText = block.Text; block.SetText(Text); if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(BlockKey, Text.Length); } }
protected override void Undo( BlockCommandContext context, Block block) { foreach (Block addedBlock in addedBlocks) { context.Blocks.Remove(addedBlock); } if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { context.Position = new BlockPosition(BlockKey, block.Text.Length); } }
protected override void Undo( BlockCommandContext context, Block block) { block.SetText(previousText); // Set the new cursor position. int textIndex = BlockPosition.TextIndex.GetCharacterIndex(previousText); if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { context.Position = new BlockPosition(BlockPosition.BlockKey, textIndex); } }
public void Do(BlockCommandContext context) { // Grab the destination block and make sure everything is locked properly. Block block; using ( context.Blocks.AcquireBlockLock( RequestLock.Write, RequestLock.Write, (int)DestinationPosition.LinePosition, out block)) { // Grab the text from the source line. int lineIndex, sourceBegin, sourceEnd; string sourceLine; Range.GetBeginAndEndCharacterIndices( context.Blocks, out lineIndex, out sourceBegin, out sourceEnd, out sourceLine); string sourceText = sourceLine.Substring( sourceBegin, sourceEnd - sourceBegin); // Insert the text from the source line into the destination. string destinationLine = block.Text; var buffer = new StringBuilder(destinationLine); int characterIndex = DestinationPosition.CharacterPosition.GetCharacterIndex(destinationLine); buffer.Insert(characterIndex, sourceText); // Save the source text length so we can delete it. sourceLength = sourceText.Length; originalCharacterIndex = characterIndex; // Set the line in the buffer. destinationLine = buffer.ToString(); block.SetText(destinationLine); // Set the position of this command. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(block.BlockKey, characterIndex); } } }
public override void Undo(OperationContext state) { // Delete the created line. state.LineBuffer.DeleteLines(LineIndex, 1); // If we were updating the position, we need to restore it. // If we are updating the position, then set it. if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { state.Results = new LineBufferOperationResults( new TextPosition( InitialPosition.LinePosition, InitialPosition.CharacterPosition)); } }
public override void Do(OperationContext state) { // Save the position, in case we need it. InitialPosition = state.Position; // Insert the line into the buffer. state.LineBuffer.InsertLines(LineIndex, 1); // If we are updating the position, then set it. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { var linePosition = new LinePosition(LineIndex); var textPosition = new TextPosition(linePosition, 0); state.Results = new LineBufferOperationResults(textPosition); } }
protected override void Do( BlockCommandContext context, Block block) { // We need to keep track of the previous block type so we can change // it back with Undo. previousBlockType = block.BlockType; // Set the block type. block.SetBlockType(BlockType); // Save the position from this command. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { context.Position = new BlockPosition(BlockKey, 0); } }
public override void Undo(OperationContext state) { // Grab the line from the line buffer. string lineText = state.LineBuffer.GetLineText( DestinationPosition.LinePosition, LineContexts.Unformatted); var buffer = new StringBuilder(lineText); // Normalize the character ranges. buffer.Remove(originalCharacterIndex, sourceLength); // Set the line in the buffer. lineText = buffer.ToString(); state.LineBuffer.SetText(DestinationPosition.LinePosition, lineText); // If we are updating the position, we need to do it here. if (UpdateTextPosition.HasFlag(DoTypes.Undo)) { state.Results = new LineBufferOperationResults(originalPosition); } }
public override void Do(OperationContext state) { // Grab the line from the line buffer. int lineIndex = TextRange.LinePosition.GetLineIndex(state.LineBuffer.LineCount); string lineText = state.LineBuffer.GetLineText( lineIndex, LineContexts.Unformatted); var buffer = new StringBuilder(lineText); // Normalize the character ranges. int firstCharacterIndex; int lastCharacterIndex; TextRange.GetFirstAndLastCharacterIndices( lineText, out firstCharacterIndex, out lastCharacterIndex); beginCharacterIndex = firstCharacterIndex; int length = lastCharacterIndex - firstCharacterIndex; // Remove the text from the string, but save it so we can restore it. originalText = lineText.Substring(firstCharacterIndex, length); buffer.Remove(firstCharacterIndex, length); // Set the line in the buffer. lineText = buffer.ToString(); state.LineBuffer.SetText(lineIndex, lineText); // If we are updating the position, we need to do it here. if (UpdateTextPosition.HasFlag(DoTypes.Do)) { var firstCharacterPosition = new CharacterPosition(firstCharacterIndex); var firstTextPosition = new TextPosition( TextRange.LinePosition, firstCharacterPosition); originalPosition = state.Position; state.Results = new LineBufferOperationResults(firstTextPosition); } }