Allow NSAttributedString in [wxNSTextFieldEditor insertText]

According to the documentation, insertText: argument is either NSString
or NSAttributedString. The latter is not a subclass of the former, yet
the code assumed the argument is always a NSString. This caused the
following exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
-[NSConcreteMutableAttributedString characterAtIndex:]: unrecognized selector sent to instance

Fix this by checking for NSAttributedString and extracting plain string
from it.
This commit is contained in:
Václav Slavík 2015-10-13 14:45:56 +02:00
parent b9b9a30bc7
commit 1acfe88347

View File

@ -302,8 +302,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
// programmatically.
if ( !wxMacEditHelper::IsCurrentEditor(self) )
{
NSString *text = [str isKindOfClass:[NSAttributedString class]] ? [str string] : str;
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
if ( impl && lastKeyDownEvent && impl->DoHandleCharEvent(lastKeyDownEvent, str) )
if ( impl && lastKeyDownEvent && impl->DoHandleCharEvent(lastKeyDownEvent, text) )
return;
}