private bool HandleUpDownKeys(KeyEventArgs args) { var pos = CaretPosition.CompareTo(_promptInline.ContentEnd); if (pos < 0) { return(false); } if (!_buffer.Any()) { return(true); } ClearAfterPrompt(); string existingLine; if (args.Key == Key.Down) { existingLine = _buffer[_buffer.Count - 1]; _buffer.RemoveAt(_buffer.Count - 1); _buffer.Insert(0, existingLine); } else { existingLine = _buffer[0]; _buffer.RemoveAt(0); _buffer.Add(existingLine); } AddLine(existingLine); return(true); }
private bool HandleLeftKey() { var promptEnd = _promptInline.ContentEnd; var textPointer = GetTextPointer(promptEnd, LogicalDirection.Forward); if (textPointer == null) { var pos = CaretPosition.CompareTo(promptEnd); if (pos == 0) { return(true); } } else { var pos = CaretPosition.CompareTo(textPointer); if (pos == 0) { return(true); } } return(false); }
private bool HandleCopyKeys(KeyEventArgs args) { if (args.Key == Key.C) { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { return(false); } var promptEnd = _promptInline.ContentEnd; var pos = CaretPosition.CompareTo(promptEnd); var selectionPos = Selection.Start.CompareTo(CaretPosition); return(pos < 0 || selectionPos < 0); } if (args.Key == Key.X || args.Key == Key.V) { var promptEnd = _promptInline.ContentEnd; var pos = CaretPosition.CompareTo(promptEnd); var selectionPos = Selection.Start.CompareTo(CaretPosition); return(pos < 0 || selectionPos < 0); } return(false); }
private bool HandleCopyKeys(KeyEventArgs args) { switch (args.Key) { case Key.C: { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { return(false); } var pos = CaretPosition.CompareTo(_promptInline.ContentEnd); var selectionPos = Selection.Start.CompareTo(CaretPosition); return(pos < 0 || selectionPos < 0); } case Key.X: case Key.V: { var end = _promptInline.ContentEnd; var pos = CaretPosition.CompareTo(end); var selectionPos = Selection.Start.CompareTo(CaretPosition); return(pos < 0 || selectionPos < 0); } } return(false); }
internal void MoveCaretToFirstLine(Rect rect) { TextPointer tp = Document.ContentStart; TextPointer last_tp = tp; Rect r = tp.GetCharacterRect(LogicalDirection.Forward); while (tp != null && r.X < rect.X && tp.CompareTo(Document.ContentEnd) != 0) { tp = tp.GetNextInsertionPosition(LogicalDirection.Forward); if (tp == null) { break; } r = tp.GetCharacterRect(LogicalDirection.Forward); last_tp = tp; } if (last_tp != null) { CaretPosition = last_tp; } // Workaround for bug in .NET 3.0 if (!CaretPosition.IsAtLineStartPosition) { EditingCommands.MoveLeftByCharacter.Execute(null, this); EditingCommands.MoveRightByCharacter.Execute(null, this); } else if (CaretPosition.CompareTo(Document.ContentEnd) != 0) { EditingCommands.MoveRightByCharacter.Execute(null, this); EditingCommands.MoveLeftByCharacter.Execute(null, this); } }
private bool HandleAnyOtherKey() { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { return(false); } var promptEnd = _promptInline.ContentEnd; var pos = CaretPosition.CompareTo(promptEnd); return(pos < 0); }
private bool HandleDeleteKey() { var pos = CaretPosition.CompareTo(_promptInline.ContentEnd); return(pos < 0); }
private void LinkRemove(Paragraph paragraph, Hyperlink hl) { Inline nextInline = hl.NextInline; Inline prevInline = hl.PreviousInline; int caretOffset = 0; int caretPosition = paragraph.ContentStart.GetOffsetToPosition(CaretPosition); if (CaretPosition.CompareTo(hl.ContentStart) > 0) { caretOffset++; } if (CaretPosition.CompareTo(hl.ContentEnd) > 0) { caretOffset++; } paragraph.Inlines.Remove(hl); foreach (var hlInline in hl.Inlines) { Inline newInline = null; if (hlInline is Run) { newInline = new Run(((Run)hlInline).Text); } else if (hlInline is LineBreak) { newInline = new LineBreak(); } if (newInline == null) { continue; } if (prevInline == null && nextInline == null) { paragraph.Inlines.Add(newInline); } else if (prevInline != null) { paragraph.Inlines.InsertAfter(prevInline, newInline); } else if (nextInline != null) { paragraph.Inlines.InsertBefore(nextInline, newInline); } prevInline = newInline; } if (caretPosition - caretOffset >= 0) { var newPosition = paragraph.ContentStart.GetPositionAtOffset(caretPosition - caretOffset); if (newPosition != null) { CaretPosition = newPosition; } else { CaretPosition = paragraph.ContentEnd; } } }