/// <summary> /// </summary> public ICaretPosition MoveTo(Int32 characterIndex, CaretPlacement caretPlacement) { if (_overwriteMode) { caretPlacement = CaretPlacement.LeftOfCharacter; } ICaretPosition oldPosition = this.Position; Span textElementSpan = _editorView.GetTextElementSpan(characterIndex); if (textElementSpan == null) { return(oldPosition); } _caretPlacement = caretPlacement; if ((_caretPlacement == CaretPlacement.RightOfCharacter) && (characterIndex < _editorView.TextBuffer.Length)) { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.End); } else { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.Start); } ICaretPosition position = this.Position; this.PositionChanged(this, new CaretPositionChangedEventArgs(oldPosition, position)); return(position); }
internal CaretPosition(Int32 characterIndex, Int32 textInsertionIndex, CaretPlacement caretPlacement) { if (characterIndex < 0) { throw new ArgumentOutOfRangeException("characterIndex"); } if (textInsertionIndex < 0) { throw new ArgumentOutOfRangeException("textInsertionIndex"); } _characterIndex = characterIndex; _textInsertionIndex = textInsertionIndex; _placement = caretPlacement; }
/// <summary> /// </summary> public CaretElement(EditorView editorView) { SizeChangedEventHandler handler = null; _editorView = editorView; _caretPlacement = CaretPlacement.LeftOfCharacter; _insertionPoint = new TextPoint(editorView.TextBuffer, 0); _preferredVerticalPosition = _preferredHorizontalPosition = 0; _textViewHelper = new TextViewHelper(_editorView); this.ConstructCaretGeometry(); TextLine line = TextFormatter.Create().FormatLine(new DefaultLineGutterTextSource("W", TextFormattingRunProperties.DefaultProperties), 0, 10, new TextFormattingParagraphProperties(), null); _defaultOverwriteCaretWidth = line.Width; _overwriteCaretBrush = new SolidColorBrush(Colors.Gray); _overwriteCaretBrush.Opacity = 0.5; DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); frames.BeginTime = new TimeSpan((long)0); frames.RepeatBehavior = RepeatBehavior.Forever; frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromPercent(0))); Int32 caretBlinkTime = User32.GetCaretBlinkTime(); if (caretBlinkTime > 0) { frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromPercent(0.5))); } else { caretBlinkTime = 500; } frames.Duration = new Duration(new TimeSpan(0, 0, 0, 0, caretBlinkTime * 2)); _blinkAnimationClock = frames.CreateClock(); base.ApplyAnimationClock(UIElement.OpacityProperty, _blinkAnimationClock); this.PositionChanged = (EventHandler <CaretPositionChangedEventArgs>)Delegate.Combine(this.PositionChanged, new EventHandler <CaretPositionChangedEventArgs>(this.CaretElement_PositionChanged)); if (handler == null) { handler = delegate { this.ConstructCaretGeometry(); }; } base.SizeChanged += handler; base.IsVisibleChanged += new DependencyPropertyChangedEventHandler(this.UIElement_VisibleChanged); this.OverwriteMode = false; }
/// <summary> /// </summary> public CaretElement(EditorView editorView) { SizeChangedEventHandler handler = null; _editorView = editorView; _caretPlacement = CaretPlacement.LeftOfCharacter; _insertionPoint = new TextPoint(editorView.TextBuffer, 0); _preferredVerticalPosition = _preferredHorizontalPosition = 0; _textViewHelper = new TextViewHelper(_editorView); this.ConstructCaretGeometry(); TextLine line = TextFormatter.Create().FormatLine(new DefaultLineGutterTextSource("W", TextFormattingRunProperties.DefaultProperties), 0, 10, new TextFormattingParagraphProperties(), null); _defaultOverwriteCaretWidth = line.Width; _overwriteCaretBrush = new SolidColorBrush(Colors.Gray); _overwriteCaretBrush.Opacity = 0.5; DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); frames.BeginTime = new TimeSpan((long)0); frames.RepeatBehavior = RepeatBehavior.Forever; frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromPercent(0))); Int32 caretBlinkTime = User32.GetCaretBlinkTime(); if (caretBlinkTime > 0) { frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromPercent(0.5))); } else { caretBlinkTime = 500; } frames.Duration = new Duration(new TimeSpan(0, 0, 0, 0, caretBlinkTime * 2)); _blinkAnimationClock = frames.CreateClock(); base.ApplyAnimationClock(UIElement.OpacityProperty, _blinkAnimationClock); this.PositionChanged = (EventHandler<CaretPositionChangedEventArgs>)Delegate.Combine(this.PositionChanged, new EventHandler<CaretPositionChangedEventArgs>(this.CaretElement_PositionChanged)); if (handler == null) { handler = delegate { this.ConstructCaretGeometry(); }; } base.SizeChanged += handler; base.IsVisibleChanged += new DependencyPropertyChangedEventHandler(this.UIElement_VisibleChanged); this.OverwriteMode = false; }
private ICaretPosition CreateCaretPosition(Int32 characterIndex, CaretPlacement caretPlacement) { Span textElementSpan = _editorView.GetTextElementSpan(characterIndex); return(new CaretPosition(textElementSpan.Start, (caretPlacement == CaretPlacement.LeftOfCharacter) ? textElementSpan.Start : textElementSpan.End, (textElementSpan.Length == 0) ? CaretPlacement.LeftOfCharacter : caretPlacement)); }
/// <summary> /// </summary> public ICaretPosition MoveTo(Int32 characterIndex, CaretPlacement caretPlacement) { if (_overwriteMode) { caretPlacement = CaretPlacement.LeftOfCharacter; } ICaretPosition oldPosition = this.Position; Span textElementSpan = _editorView.GetTextElementSpan(characterIndex); if (textElementSpan == null) { return oldPosition; } _caretPlacement = caretPlacement; if ((_caretPlacement == CaretPlacement.RightOfCharacter) && (characterIndex < _editorView.TextBuffer.Length)) { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.End); } else { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.Start); } ICaretPosition position = this.Position; this.PositionChanged(this, new CaretPositionChangedEventArgs(oldPosition, position)); return position; }
private ICaretPosition CreateCaretPosition(Int32 characterIndex, CaretPlacement caretPlacement) { Span textElementSpan = _editorView.GetTextElementSpan(characterIndex); return new CaretPosition(textElementSpan.Start, (caretPlacement == CaretPlacement.LeftOfCharacter) ? textElementSpan.Start : textElementSpan.End, (textElementSpan.Length == 0) ? CaretPlacement.LeftOfCharacter : caretPlacement); }