| Index: chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
|
| diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
|
| index a003166bc4d071ed7db2a3c3485b3d423d01cca4..2a8af7c05786e8bcfc45d2ccf63bf4e9cc78cef8 100644
|
| --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
|
| +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
|
| @@ -444,19 +444,6 @@ void AutocompleteEditViewMac::ClosePopup() {
|
| void AutocompleteEditViewMac::SetFocus() {
|
| }
|
|
|
| -bool AutocompleteEditViewMac::CommitSuggestText() {
|
| - if (suggest_text_length_ == 0)
|
| - return false;
|
| -
|
| - string16 input_text(GetText());
|
| - suggest_text_length_ = 0;
|
| - string16 text(GetText());
|
| - // Call SetText() to force a redraw and move the cursor to the end.
|
| - SetText(text);
|
| - model()->FinalizeInstantQuery(input_text, text.substr(input_text.size()));
|
| - return true;
|
| -}
|
| -
|
| void AutocompleteEditViewMac::SetText(const string16& display_text) {
|
| // If we are setting the text directly, there cannot be any suggest text.
|
| suggest_text_length_ = 0;
|
| @@ -507,6 +494,16 @@ NSString* AutocompleteEditViewMac::GetNonSuggestTextSubstring() const {
|
| return text;
|
| }
|
|
|
| +NSString* AutocompleteEditViewMac::GetSuggestTextSubstring() const {
|
| + if (suggest_text_length_ == 0)
|
| + return nil;
|
| +
|
| + NSString* text = [field_ stringValue];
|
| + NSUInteger length = [text length];
|
| + DCHECK_LE(suggest_text_length_, length);
|
| + return [text substringFromIndex:(length - suggest_text_length_)];
|
| +}
|
| +
|
| void AutocompleteEditViewMac::EmphasizeURLComponents() {
|
| NSTextView* editor = (NSTextView*)[field_ currentEditor];
|
| // If the autocomplete text field is in editing mode, then we can just change
|
| @@ -723,6 +720,11 @@ void AutocompleteEditViewMac::SetInstantSuggestion(
|
| }
|
| }
|
|
|
| +string16 AutocompleteEditViewMac::GetInstantSuggestion() const {
|
| + return suggest_text_length_ ?
|
| + base::SysNSStringToUTF16(GetSuggestTextSubstring()) : string16();
|
| +}
|
| +
|
| int AutocompleteEditViewMac::TextWidth() const {
|
| // Not used on mac.
|
| NOTREACHED();
|
| @@ -790,7 +792,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) {
|
| suggest_text_length_ > 0 &&
|
| (range.location + suggest_text_length_ ==
|
| [[field_ stringValue] length])) {
|
| - controller_->OnCommitSuggestedText(GetText());
|
| + controller_->OnCommitSuggestedText(true);
|
| return true;
|
| }
|
| }
|
| @@ -815,7 +817,17 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) {
|
| return model_->AcceptKeyword();
|
|
|
| if (suggest_text_length_ > 0) {
|
| - controller_->OnCommitSuggestedText(GetText());
|
| + controller_->OnCommitSuggestedText(true);
|
| + return true;
|
| + }
|
| +
|
| + NSRange selected_range = GetSelectedRange();
|
| + NSUInteger length = [[[field_ currentEditor] string] length];
|
| + if (selected_range.length != 0 || selected_range.location < length) {
|
| + [[field_ currentEditor] setSelectedRange:NSMakeRange(length, length)];
|
| + // OnDidChange() will not be triggered when setting selected range in this
|
| + // method, so we need to call it explicitly.
|
| + OnDidChange();
|
| return true;
|
| }
|
|
|
|
|