Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: appengine/chromium_rietveld/new_static/components/cr-user-autocomplete.html

Issue 2208573003: Fix cr-user-autocomplete for Chrome. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Use String#contains Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 <!-- Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 Use of this source code is governed by a BSD-style license that can be 2 Use of this source code is governed by a BSD-style license that can be
3 found in the LICENSE file. --> 3 found in the LICENSE file. -->
4 4
5 <link rel="import" href="../common/cr-keyboard.html"> 5 <link rel="import" href="../common/cr-keyboard.html">
6 6
7 <polymer-element name="cr-user-autocomplete" attributes="value"> 7 <polymer-element name="cr-user-autocomplete" attributes="value">
8 <template> 8 <template>
9 <style> 9 <style>
10 :host { 10 :host {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 var range = this.termRange; 143 var range = this.termRange;
144 var value = user.email.substring(range.text.length) + ", "; 144 var value = user.email.substring(range.text.length) + ", ";
145 145
146 // Restore selection to where the autocomplete expects it. This prevents the user from 146 // Restore selection to where the autocomplete expects it. This prevents the user from
147 // selecting some random text and then clicking a suggestion whi ch might destroy their 147 // selecting some random text and then clicking a suggestion whi ch might destroy their
148 // input. We might also dismiss the suggestions if the selection moves but there's no 148 // input. We might also dismiss the suggestions if the selection moves but there's no
149 // obvious way to detect that. 149 // obvious way to detect that.
150 input.selectionStart = range.end; 150 input.selectionStart = range.end;
151 input.selectionEnd = input.selectionStart; 151 input.selectionEnd = input.selectionStart;
152 152
153 // For Safari/Chrome: 153 // Make sure the input is focused.
154 // Simulate the user entering the text. This makes undo work pro perly instead of using 154 input.focus();
155 // data binding which is like a big "replace" action. 155
156 var inputEvent = document.createEvent("TextEvent"); 156 // TODO(esprehn): This is a terrible hack but there's no obvious
157 if (inputEvent.initTextEvent) { 157 // work around since execCommand doesn't work for input in Firef ox
158 inputEvent.initTextEvent("textInput", true, true, window, va lue, 0, "en-US"); 158 // and I can't figure out how to detect that, and we shouldn't
159 input.dispatchEvent(inputEvent); 159 // feature detect based on InputEvent otherwise it'll break Chro me
160 } else if (window.InputEvent) { 160 // later.
161 // For Firefox we can just update the value and undo will wo rk. 161 if (navigator.userAgent.contains("Firefox")) {
PhistucK 2016/08/03 15:51:20 Yes, no. :P
162 // For Firefox we can just update the value and undo will wo rk,
163 // execCommand doesn't seem to update the input value.
162 input.value = input.value.to(input.selectionEnd) + value + i nput.value.from(input.selectionEnd); 164 input.value = input.value.to(input.selectionEnd) + value + i nput.value.from(input.selectionEnd);
163 input.dispatchEvent(wrap(new InputEvent("input", { 165 input.dispatchEvent(wrap(new InputEvent("input", {
164 data: value, 166 data: value,
165 bubbles: true, 167 bubbles: true,
166 cancelable:false 168 cancelable:false
167 }))); 169 })));
PhistucK 2016/08/03 15:51:20 Perhaps this is a Blink issue. Have you filed one?
170 } else {
171 // Chrome and Safari can use execCommand.
Bons 2016/08/03 15:49:42 FYI Polymer Rietveld doesn’t render in Safari (mob
esprehn 2016/08/03 16:46:53 It works for me in WebKit nightly , where do you s
172 document.execCommand("InsertText", false, value);
PhistucK 2016/08/03 15:51:20 Yes, well, this is non-standard. I advise against
esprehn 2016/08/03 16:46:53 Given that there's no workaround we're going to do
168 } 173 }
169 174
170 // Put the caret back at the end of the new input. This also mak es sure the input scrolls 175 // Put the caret back at the end of the new input. This also mak es sure the input scrolls
171 // to reveal the new text. 176 // to reveal the new text.
172 input.selectionStart = range.end + value.length; 177 input.selectionStart = range.end + value.length;
173 input.selectionEnd = input.selectionStart; 178 input.selectionEnd = input.selectionStart;
174 179
175 this.resetAutocomplete(); 180 this.resetAutocomplete();
176 this.didComplete = true; 181 this.didComplete = true;
177 }, 182 },
178 resetAutocomplete: function() { 183 resetAutocomplete: function() {
179 this.completions = []; 184 this.completions = [];
180 this.termRange = {}; 185 this.termRange = {};
181 this.active = false; 186 this.active = false;
182 }, 187 },
183 }); 188 });
184 </script> 189 </script>
185 </polymer-element> 190 </polymer-element>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698