From fe685bc4c6dff358366f6c5cbbe46b003232c9ec Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Nov 2016 23:35:01 +0100 Subject: [PATCH] Allow pasting using Cmd+V in wxTextCtrl with wxTE_PASSWORD style For some reason known only to Apple, NSSecureTextField allows pasting text into it using its standard context menu, but not using the standard Cmd+V keyboard shortcut. Moreover, apparently the control does something special to disable it because pressing Cmd+V does result in a call to -[NSSecureTextField control:textView:doCommandBySelector:], but with a dummy "noop:" selector. Detect this specific situation and check if we're called while handling Cmd+V event and, if this is indeed the case, do paste the text into the control. While it could be argued that this changes the platform behaviour, it seems very hard, if not impossible, to imagine a situation in which this would be a problem while not being able to easily paste into password fields is definitely a real usability bug. --- docs/changes.txt | 1 + src/osx/cocoa/textctrl.mm | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index a3d2550fb1..d89b055450 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -167,6 +167,7 @@ wxOSX: and OSXDisableAllSmartSubstitutions() to control wxTextCtrl smart behavior. - Don't allow interacting with disabled wxSlider (Andreas Falkenhahn). - Fix setting alignment in wxTextCtrl with wxTE_DONTWRAP (Andreas Falkenhahn). +- Allow pasting using Cmd+V in wxTextCtrl with wxTE_PASSWORD style. Unix: diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 8180421885..50cca3f039 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -258,6 +258,25 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; } } } + else if ( commandSelector == @selector(noop:) ) + { + // We are called with this strange "noop:" selector when an + // attempt to paste the text into a password text control using + // Cmd+V is made. Check if we're really in this case and, if + // we're, do paste as otherwise nothing happens by default + // which is annoying, it is pretty common and useful to paste + // passwords, e.g. from a password manager. + NSEvent* cevent = [[NSApplication sharedApplication] currentEvent]; + if ( [cevent type] == NSKeyDown && + [cevent keyCode] == 9 /* V */ && + ([cevent modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask ) + { + wxTextWidgetImpl* impl = (wxNSTextFieldControl * ) wxWidgetImpl::FindFromWXWidget( self ); + wxTextEntry * const entry = impl->GetTextEntry(); + entry->Paste(); + handled = YES; + } + } } }