AvalonEdit icon indicating copy to clipboard operation
AvalonEdit copied to clipboard

TextAreaAutomationPeer throws NullReferenceException at some cases

Open sloutsky opened this issue 6 years ago • 0 comments

https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/Editing/TextAreaAutomationPeer.cs: line 118

FromElement(editor) may return null in some (random) cases - and the current code throws NullReferenceException. The suggestion (below) is to check returned value and fall-back to 'retrun base.GetPattern(patternInterface)'

        public override object GetPattern(PatternInterface patternInterface)
	{
		if (patternInterface == PatternInterface.Text)
			return this;
		if (patternInterface == PatternInterface.Value)
			return this;
		if (patternInterface == PatternInterface.Scroll) {
			TextEditor editor = TextArea.GetService(typeof(TextEditor)) as TextEditor;
			if (editor != null)
			{
				var fromElement = FromElement(editor);
				if (fromElement != null)
					fromElement.GetPattern(patternInterface);
			}
		}
		return base.GetPattern(patternInterface);
	}

sloutsky avatar Sep 10 '19 05:09 sloutsky