From 593a1179aec175804bde287144e9d7d2606bde34 Mon Sep 17 00:00:00 2001 From: "shess@chromium.org" <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Fri, 18 Sep 2009 21:21:50 +0000 Subject: [PATCH] [Mac] Paste in Omnibox needs to initiate field editing correctly. We override -paste: to do Chrome-specific stuff. This circumvents certain Cocoa-standard setup which happens when user's edit text views, and elsewhere we depend on that setup being right. This changes our code to participate in that setup process. http://crbug.com/21301 TEST=Copy "raising arizona" to the clipboard. Put focus in the NTP (Omnibox field does not have focus ring). Click in Omnibox field and paste. Should now see autocomplete popup. Review URL: http://codereview.chromium.org/213029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26620 0039d316-1c4b-4281-b951-d872f2087c98 --- .../autocomplete_edit_view_mac.mm | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index b3af808067193..94130e4832206 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -588,24 +588,32 @@ void AutocompleteEditViewMac::OnPaste() { if (text.empty()) { return; } + NSString* s = base::SysWideToNSString(text); - // If this paste will be replacing all the text, record that, so we - // can do different behaviors in such a case. - const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); + // -shouldChangeTextInRange:* and -didChangeText are documented in + // NSTextView as things you need to do if you write additional + // user-initiated editing functions. They cause the appropriate + // delegate methods to be called. + // TODO(shess): It would be nice to separate the Cocoa-specific code + // from the Chrome-specific code. + NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); const NSRange selectedRange = GetSelectedRange(); - if (NSEqualRanges(allRange, selectedRange)) { - model_->on_paste_replacing_all(); - } - - // Force a Paste operation to trigger the text_changed code in - // OnAfterPossibleChange(), even if identical contents are pasted into the - // text box. - text_before_change_.clear(); + if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) { + // If this paste will be replacing all the text, record that, so + // we can do different behaviors in such a case. + const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); + if (NSEqualRanges(allRange, selectedRange)) { + model_->on_paste_replacing_all(); + } - NSString* s = base::SysWideToNSString(text); - [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s]; + // Force a Paste operation to trigger the text_changed code in + // OnAfterPossibleChange(), even if identical contents are pasted + // into the text box. + text_before_change_.clear(); - OnAfterPossibleChange(); + [editor replaceCharactersInRange:selectedRange withString:s]; + [editor didChangeText]; + } } bool AutocompleteEditViewMac::CanPasteAndGo() { -- GitLab