diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index b3af808067193e8127b7a2cd442de4ef57cc49f0..94130e483220603ecf9f620c9b71967030afea5f 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() {