public static void Right(EditorViewController controller) { // Pull out some useful variables. IDisplayContext displayContext = controller.DisplayContext; LineBuffer lineBuffer = displayContext.LineBuffer; // Move the character position based on line context. TextPosition position = displayContext.Caret.Position; LinePosition linePosition = position.LinePosition; int lineIndex = linePosition.GetLineIndex(lineBuffer); int lineLength = lineBuffer.GetLineLength(lineIndex); CharacterPosition characterPosition = position.CharacterPosition; int characterIndex = position.GetCharacterIndex(lineBuffer); if (characterIndex == lineLength) { if (lineIndex < lineBuffer.LineCount - 1) { linePosition = new LinePosition(lineIndex + 1); characterPosition = CharacterPosition.Begin; } } else { characterPosition = new CharacterPosition(characterIndex + 1); } // Cause the text editor to redraw itself. var caretPosition = new TextPosition(linePosition, characterPosition); displayContext.ScrollToCaret(caretPosition); }
public void BeyondEndNormalize() { // Arrange var position = new LinePosition(1000); // Act Assert.Throws <IndexOutOfRangeException>(() => position.GetLineIndex(10)); }
public static int GetLineIndex( this TextPosition textPosition, LineBuffer lineBuffer) { LinePosition linePosition = textPosition.LinePosition; int results = linePosition.GetLineIndex(lineBuffer.LineCount); return(results); }
public static int GetLineIndex( this LinePosition linePosition, LineBuffer lineBuffer, LinePositionOptions options = LinePositionOptions.None) { int lineIndex = linePosition.GetLineIndex(lineBuffer.LineCount, options); return(lineIndex); }
public LineBlockStyle GetLineStyle( LinePosition linePosition, LineContexts lineContexts = LineContexts.None) { int lineIndex = linePosition.GetLineIndex(LineBuffer); LineBlockStyle results = GetLineStyle(lineIndex, lineContexts); return(results); }
public int GetLineLength( LinePosition linePosition, LineContexts lineContexts = LineContexts.None) { int lineIndex = linePosition.GetLineIndex(this); int results = GetLineLength(lineIndex, lineContexts); return(results); }
public string GetLineText( LinePosition line, LineContexts lineContexts) { int lineIndex = line.GetLineIndex(this); string results = GetLineText(lineIndex, lineContexts); return(results); }
public void MiddleNormalize() { // Arrange var position = new LinePosition(10); // Act int results = position.GetLineIndex(15); // Assert Assert.AreEqual(10, results); }
public void BeginningNormalize() { // Arrange var position = new LinePosition(0); // Act int results = position.GetLineIndex(15); // Assert Assert.AreEqual(0, results); }
public void EndNormalize() { // Arrange const string input = "one one one one"; LinePosition position = LinePosition.End; // Act int results = position.GetLineIndex(15); // Assert Assert.AreEqual(input.Length, results); }
public void NumericEndNormalize() { // Arrange const string input = "one one one one"; var position = new LinePosition(input.Length); // Act int results = position.GetLineIndex(15); // Assert Assert.AreEqual(input.Length, results); }
private void ClearCacheLines(TextRange selection) { LinePosition firstLinePosition = selection.FirstLinePosition; int firstLineIndex = firstLinePosition.GetLineIndex( LineBuffer, LinePositionOptions.NoBoundsChecking); LinePosition lastLinePosition = selection.LastLinePosition; int lastLineIndex = lastLinePosition.GetLineIndex( LineBuffer, LinePositionOptions.NoBoundsChecking); for (int lineIndex = firstLineIndex; lineIndex <= lastLineIndex; lineIndex++) { CachedLine line = lines[lineIndex]; line.Reset(); } }
/// <summary> /// Scrolls the view to ensure the caret is visible. /// </summary> /// <param name="bufferPosition">The buffer position.</param> public void ScrollToCaret(TextPosition bufferPosition) { // Look to see if we are moving to a different position. If we are, // we tell the line buffer that we have exited the previous line. LinePosition linePosition = caret.Position.LinePosition; int lineIndex = linePosition.GetLineIndex(Controller.DisplayContext.LineBuffer); if (linePosition != bufferPosition.LinePosition) { // Send an operation to the line buffer that we left the line. LineBuffer.ExitLine(lineIndex); } // Call the base scrolling. caret.Position = bufferPosition; ScrollToCaret(); }
public static void RightWord(EditorViewController controller) { // Pull out some useful variables. IDisplayContext displayContext = controller.DisplayContext; LineBuffer buffer = displayContext.LineBuffer; LineBuffer lineBuffer = displayContext.LineBuffer; // Pull out the line and chracter positions from where we're starting. TextPosition position = displayContext.Caret.Position; LinePosition linePosition = position.LinePosition; int lineIndex = linePosition.GetLineIndex(buffer); string lineText = buffer.GetLineText(lineIndex); CharacterPosition wordPosition = CharacterPosition.Word; CharacterPosition characterPosition = position.CharacterPosition; int characterIndex = characterPosition.GetCharacterIndex(lineText); // If we are at the beginning of the line, we need to move to the // previous line. if (characterIndex == lineText.Length) { // If we are at the last line, we don't do anything. if (lineIndex == lineBuffer.LineCount - 1) { return; } // Move to the end of the previous line. linePosition = new LinePosition(lineIndex + 1); characterPosition = CharacterPosition.Begin; } else { // Move to the previous left word. int rightCharacterIndex = wordPosition.GetCharacterIndex( lineText, characterPosition, WordSearchDirection.Right); characterPosition = new CharacterPosition(rightCharacterIndex); } // Cause the text editor to redraw itself. var caretPosition = new TextPosition(linePosition, characterPosition); displayContext.ScrollToCaret(caretPosition); }
public void Do( ICommand <OperationContext> command, OperationContext context) { // Every command needs a full write lock on the blocks. using (Project.Blocks.AcquireLock(RequestLock.Write)) { // Create the context for the block commands. var blockContext = new BlockCommandContext(Project); LinePosition linePosition = context.Position.LinePosition; int lineIndex = linePosition.GetLineIndex(Project.Blocks.Count); Block currentBlock = Project.Blocks[lineIndex]; blockContext.Position = new BlockPosition( currentBlock, context.Position.CharacterPosition); // Wrap the command with our wrappers. IWrappedCommand wrappedCommand = WrapCommand(command, context); Project.Commands.Do(wrappedCommand, blockContext); // Set the operation context from the block context. if (blockContext.Position.HasValue) { // Grab the block position and figure out the index. BlockPosition blockPosition = blockContext.Position.Value; int blockIndex = Project.Blocks.IndexOf(blockPosition.BlockKey); var position = new TextPosition(blockIndex, (int)blockPosition.TextIndex); // Set the context results. context.Results = new LineBufferOperationResults(position); } // Make sure we process our wrapped command. wrappedCommand.PostDo(context); } }
public string GetLineText(LinePosition line) { int lineIndex = line.GetLineIndex(this); return(GetLineText(lineIndex, LineContexts.Unformatted)); }
public static void Up(EditorViewController controller) { // Extract a number of useful variable for this method. IDisplayContext displayContext = controller.DisplayContext; TextPosition position = displayContext.Caret.Position; EditorViewRenderer buffer = displayContext.Renderer; // Figure out the layout and wrapped line we are currently on. Layout layout; int wrappedLineIndex; LayoutLine wrappedLine = position.GetWrappedLine( displayContext, out layout, out wrappedLineIndex); // Figure out the X coordinate of the line. If there is an action context, // use that. Otherwise, calculate it from the character index of the position. int lineX = GetLineX(controller, wrappedLine, position); // Figure out which wrapped line we'll be moving the caret to. LinePosition linePosition = position.LinePosition; int lineIndex = linePosition.GetLineIndex(buffer.LineBuffer); if (wrappedLineIndex == 0) { // If we are the last line in the buffer, just do nothing. if (linePosition == 0) { return; } // Move to the next line. lineIndex--; layout = buffer.GetLineLayout(lineIndex, LineContexts.None); wrappedLineIndex = layout.LineCount - 1; wrappedLine = layout.Lines[wrappedLineIndex]; } else { // Just move down in the layout. wrappedLineIndex--; wrappedLine = layout.Lines[wrappedLineIndex]; } // Adjust the X coordinate for the current line. lineX -= GetLeftStylePaddingPango(controller, lineIndex); // The wrapped line has the current wrapped line, so use the lineX // to figure out which character to use. int trailing; int unicodeIndex; wrappedLine.XToIndex(lineX, out unicodeIndex, out trailing); // Calculate the character position, but we have to map UTF-8 // characters because Pango uses that instead of C# strings. string lineText = controller.DisplayContext.LineBuffer.GetLineText(lineIndex); unicodeIndex = NormalizeEmptyStrings(lineText, unicodeIndex); int characterIndex = PangoUtility.TranslateStringToPangoIndex( lineText, unicodeIndex); if (lineText.Length > 0 && trailing > 0) { characterIndex++; } // Draw the new location of the caret. var caretPosition = new TextPosition(lineIndex, characterIndex); displayContext.ScrollToCaret(caretPosition); }