Skip to content
Snippets Groups Projects
Commit 593a1179 authored by shess@chromium.org's avatar shess@chromium.org
Browse files

[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
parent fce98b6e
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment