|
1 | | -using ColorCodeStandard; |
| 1 | +using ColorCodeStandard; |
2 | 2 | using ICSharpCode.AvalonEdit; |
3 | 3 | using ICSharpCode.AvalonEdit.Editing; |
4 | 4 | using ICSharpCode.AvalonEdit.Highlighting; |
@@ -72,6 +72,29 @@ public SampleCodePresenter() |
72 | 72 | CodePresenter.TextArea.SelectionBorder = new Pen(Brushes.Transparent, 0); |
73 | 73 | CodePresenter.TextArea.SelectionCornerRadius = 0; |
74 | 74 | CodePresenter.TextArea.SetResourceReference(TextArea.SelectionBrushProperty, ThemeKeys.TextControlSelectionHighlightColorKey); |
| 75 | + |
| 76 | + // Ensure caret never shows (keep selection & copy) |
| 77 | + HideCaretPermanently(); |
| 78 | + CodePresenter.TextArea.GotFocus += (s,e)=> HideCaretPermanently(); |
| 79 | + CodePresenter.TextArea.TextView.VisualLinesChanged += (s,e)=> HideCaretPermanently(); |
| 80 | + } |
| 81 | + |
| 82 | + private void HideCaretPermanently() |
| 83 | + { |
| 84 | + // Make sure the editor can still be clicked for selection but caret invisible. |
| 85 | + var caret = CodePresenter.TextArea.Caret; |
| 86 | + caret.CaretBrush = Brushes.Transparent; |
| 87 | + // keep focus off the editor so IME/caret logic does not repaint a visible caret |
| 88 | + if (CodePresenter.IsFocused) |
| 89 | + { |
| 90 | + // Move focus to parent container (still allows mouse selection highlight within AvalonEdit) |
| 91 | + var parent = (DependencyObject)CodePresenter.Parent; |
| 92 | + while (parent != null && parent is not Control) |
| 93 | + { |
| 94 | + parent = LogicalTreeHelper.GetParent(parent); |
| 95 | + } |
| 96 | + (parent as Control)?.Focusable.Equals(true); |
| 97 | + } |
75 | 98 | } |
76 | 99 |
|
77 | 100 | private static void OnSubstitutionsPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) |
|
0 commit comments