private void ReplaceVirtualSpaces() { if (Caret.InVirtualSpace) { TextView.TextBuffer.Insert(Caret.Position.BufferPosition, new string(' ', Caret.Position.VirtualSpaces)); Caret.MoveTo(CaretLine.End); } }
public override void OnPointerDown(PointerEventData eventData) { Caret.MoveTo( EditableText.RelativeIndexFromPosition( EditableText.MousePositionInTextRect(eventData)) + _drawStart, false); eventData.Use(); }
public void SimulateType(DeveroomEditorTypeCharCommandBase command, char c) { var caretPosition = Caret.Position.BufferPosition.Position; using (var textEdit = TextBuffer.CreateEdit()) { textEdit.Insert(Caret.Position.BufferPosition.Position, c.ToString()); textEdit.Apply(); } Caret.MoveTo(new SnapshotPoint(TextSnapshot, caretPosition + 1)); ForceReparse(); //this is needed because currently partial table formatting is not supported command.PostExec(this, c); }
private void SelectRange(int selectionStart, int selectionEnd) { SnapshotPoint startPoint = new SnapshotPoint(TextView.AdvancedTextView.TextSnapshot, selectionStart); SnapshotPoint endPoint = new SnapshotPoint(TextView.AdvancedTextView.TextSnapshot, selectionEnd); TextSelection.Select(new VirtualSnapshotPoint(startPoint), new VirtualSnapshotPoint(endPoint)); ITextViewLine textViewLine = TextView.AdvancedTextView.GetTextViewLineContainingBufferPosition(endPoint); PositionAffinity affinity = (textViewLine.IsLastTextViewLineForSnapshotLine || (endPoint != textViewLine.End)) ? PositionAffinity.Successor : PositionAffinity.Predecessor; Caret.MoveTo(endPoint, affinity); TextView.AdvancedTextView.ViewScroller.EnsureSpanVisible(TextSelection.StreamSelectionSpan.SnapshotSpan, (selectionStart <= selectionEnd) ? EnsureSpanVisibleOptions.MinimumScroll : (EnsureSpanVisibleOptions.MinimumScroll | EnsureSpanVisibleOptions.ShowStart)); }
private void MoveCaretToPreviousTabStop() { var caretStartingPosition = Caret.Position.VirtualBufferPosition; var caretStartingColumn = CaretColumn; Caret.MoveToPreviousCaretPosition(); var lastCaretColumn = -1; while (CaretColumn % IndentSize != (IndentSize - 1) && CaretCharIsASpace) { if (CaretColumn >= lastCaretColumn && lastCaretColumn != -1) { break; // Prevent infinite loop on first char of first line or in box selection } lastCaretColumn = CaretColumn; Caret.MoveToPreviousCaretPosition(); } if (Caret.Position.BufferPosition.Position != 0) { // Do this for all cases except the first char of the document Caret.MoveToNextCaretPosition(); } VirtualSnapshotPoint?caretNewPosition = Caret.Position.VirtualBufferPosition; int movedBy = caretStartingColumn - CaretColumn; if (movedBy % IndentSize != 0) { // We moved less than a full tab stop length. Only allow this if the cursor started in the middle of a full tab for (int i = 0; i < IndentSize; i++) { if (Caret.Position.BufferPosition.Add(i).GetChar() != ' ') { caretNewPosition = null; Caret.MoveTo(caretStartingPosition); // Do not align on non-exact tab stops break; } } if (caretNewPosition != null) { Caret.MoveTo(caretNewPosition.Value); // Go back to original new position } } Caret.EnsureVisible(); }
public override void OnDrag(PointerEventData eventData) { Vector2 localMousePos = EditableText.MousePositionInTextRect(eventData); if (localMousePos.y < EditableText.DisplayRect.yMin) { Caret.MoveTo(EditableText.LineDownIndex(true, Caret.GetIndex()), true); UpdateText(); } else if (localMousePos.y > EditableText.DisplayRect.yMax) { Caret.MoveTo(EditableText.LineUpIndex(true, Caret.GetIndex()), true); UpdateText(); } else { Caret.MoveTo(EditableText.RelativeIndexFromPosition(localMousePos) + _drawStart, true); InputFieldController.MarkGeometryAsDirty(); } eventData.Use(); }
private void MoveCaretToNextTabStop() { var caretStartingPosition = Caret.Position.VirtualBufferPosition; var caretStartingColumn = CaretColumn; var lastCaretColumn = -1; while (CaretColumn % IndentSize != 0 && CaretCharIsASpace) { if (CaretColumn <= lastCaretColumn) { break; // Prevent infinite loop in box selection } lastCaretColumn = CaretColumn; Caret.MoveToNextCaretPosition(); } if (CaretColumn % IndentSize != 0) { Caret.MoveTo(caretStartingPosition); // Do not align on non-exact tab stops } Caret.EnsureVisible(); }
private void MoveCaretWithinBounds(int index, bool withSelection) { index = Mathf.Clamp(index, 0, TextValue.Length); Caret.MoveTo(index, withSelection); }
private void MoveCaretToVirtualPosition(int pos) { Caret.MoveTo(new VirtualSnapshotPoint(_snapshotLine, pos)); Caret.EnsureVisible(); }