From 1acfe88347c863e1753fc13babf391fc429d6c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Tue, 13 Oct 2015 14:45:56 +0200 Subject: [PATCH] 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. --- src/osx/cocoa/textctrl.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index ec32b8be4d..a9fed0b0a1 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -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; }