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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js

Issue 2478563002: DevTools: Substring autocomplete in Console and StylesSideBar. (Closed)
Patch Set: tests Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 271
272 /** 272 /**
273 * @param {string} query 273 * @param {string} query
274 * @param {string} text 274 * @param {string} text
275 * @param {string=} className 275 * @param {string=} className
276 * @return {!Element} 276 * @return {!Element}
277 */ 277 */
278 _createItemElement(query, text, className) { 278 _createItemElement(query, text, className) {
279 var element = createElementWithClass('div', 'suggest-box-content-item source -code ' + (className || '')); 279 var element = createElementWithClass('div', 'suggest-box-content-item source -code ' + (className || ''));
280 element.tabIndex = -1; 280 element.tabIndex = -1;
281 if (query && query.length && !text.indexOf(query)) { 281 var displayText = text.trimEnd(50 + query.length);
282 element.createChild('span', 'query').textContent = query; 282 var index = displayText.toLowerCase().indexOf(query.toLowerCase());
283 element.createChild('span').textContent = text.substring(query.length).tri mEnd(50); 283 if (index > 0)
284 } else { 284 element.createChild('span').textContent = displayText.substring(0, index);
285 element.createChild('span').textContent = text.trimEnd(50); 285 if (index > -1)
286 } 286 element.createChild('span', 'query').textContent = displayText.substring(i ndex, index + query.length);
287 element.createChild('span').textContent = displayText.substring(index > -1 ? index + query.length : 0);
287 element.__fullValue = text; 288 element.__fullValue = text;
288 element.createChild('span', 'spacer'); 289 element.createChild('span', 'spacer');
289 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals e); 290 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals e);
290 return element; 291 return element;
291 } 292 }
292 293
293 /** 294 /**
294 * @param {!WebInspector.SuggestBox.Suggestions} items 295 * @param {!WebInspector.SuggestBox.Suggestions} items
295 * @param {string} userEnteredText 296 * @param {string} userEnteredText
296 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails 297 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 * @param {string} userEnteredText 368 * @param {string} userEnteredText
368 * @return {boolean} 369 * @return {boolean}
369 */ 370 */
370 _canShowBox(completions, canShowForSingleItem, userEnteredText) { 371 _canShowBox(completions, canShowForSingleItem, userEnteredText) {
371 if (!completions || !completions.length) 372 if (!completions || !completions.length)
372 return false; 373 return false;
373 374
374 if (completions.length > 1) 375 if (completions.length > 1)
375 return true; 376 return true;
376 377
378 if (!completions[0].title.startsWith(userEnteredText))
379 return true;
380
377 // Do not show a single suggestion if it is the same as user-entered query, even if allowed to show single-item suggest boxes. 381 // Do not show a single suggestion if it is the same as user-entered query, even if allowed to show single-item suggest boxes.
378 return canShowForSingleItem && completions[0].title !== userEnteredText; 382 return canShowForSingleItem && completions[0].title !== userEnteredText;
379 } 383 }
380 384
381 _ensureRowCountPerViewport() { 385 _ensureRowCountPerViewport() {
382 if (this._rowCountPerViewport) 386 if (this._rowCountPerViewport)
383 return; 387 return;
384 if (!this._items.length) 388 if (!this._items.length)
385 return; 389 return;
386 390
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 this.element.style.left = containerBox.x + 'px'; 572 this.element.style.left = containerBox.x + 'px';
569 this.element.style.top = containerBox.y + 'px'; 573 this.element.style.top = containerBox.y + 'px';
570 this.element.style.height = containerBox.height + 'px'; 574 this.element.style.height = containerBox.height + 'px';
571 this.element.style.width = containerBox.width + 'px'; 575 this.element.style.width = containerBox.width + 'px';
572 } 576 }
573 577
574 dispose() { 578 dispose() {
575 this.element.remove(); 579 this.element.remove();
576 } 580 }
577 }; 581 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698