Index: components/autofill/content/renderer/form_autofill_util.cc |
diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc |
index c9ebc62c3996f80d2205c16dd60be43d3a05382f..1a5d474d9dccff923927aa573cf25158fb4eaee9 100644 |
--- a/components/autofill/content/renderer/form_autofill_util.cc |
+++ b/components/autofill/content/renderer/form_autofill_util.cc |
@@ -16,6 +16,7 @@ |
#include "components/autofill/core/common/autofill_data_validation.h" |
#include "components/autofill/core/common/autofill_regexes.h" |
#include "components/autofill/core/common/autofill_switches.h" |
+#include "components/autofill/core/common/autofill_util.h" |
#include "components/autofill/core/common/form_data.h" |
#include "components/autofill/core/common/form_field_data.h" |
#include "third_party/WebKit/public/platform/WebString.h" |
@@ -871,9 +872,15 @@ void PreviewFormField(const FormFieldData& data, |
if (is_initiating_node && |
(IsTextInput(input_element) || IsTextAreaElement(*field))) { |
// Select the part of the text that the user didn't type. |
- int start = field->value().length(); |
- int end = field->suggestedValue().length(); |
- field->setSelectionRange(start, end); |
+ if (IsFeatureSubstringMatchEnabled()) { |
+ size_t start = autofill::GetTextSelectionStart(field->suggestedValue(), |
+ field->value()); |
+ if (start != base::string16::npos) |
+ field->setSelectionRange(start, field->suggestedValue().length()); |
+ } else { |
+ field->setSelectionRange(field->value().length(), |
+ field->suggestedValue().length()); |
+ } |
} |
} |