Skip to content

Commit 88ec7b9

Browse files
committed
Fix InvalidOperationException when calling VisualAncestorsAndSelf() on a TextElement.
This could happen when double-clicking on a TextElement within ICompletionData.Content.
1 parent 19611ad commit 88ec7b9

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,15 @@ public static IEnumerable<DependencyObject> VisualAncestorsAndSelf(this Dependen
213213
{
214214
while (obj != null) {
215215
yield return obj;
216-
obj = VisualTreeHelper.GetParent(obj);
216+
if (obj is Visual || obj is System.Windows.Media.Media3D.Visual3D) {
217+
obj = VisualTreeHelper.GetParent(obj);
218+
} else if (obj is FrameworkContentElement) {
219+
// When called with a non-visual such as a TextElement, walk up the
220+
// logical tree instead.
221+
obj = ((FrameworkContentElement)obj).Parent;
222+
} else {
223+
break;
224+
}
217225
}
218226
}
219227

0 commit comments

Comments
 (0)