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

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

Issue 1820393002: DevTools: [ux regression] There is no way to clear console history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 * @return {?Range} 464 * @return {?Range}
465 * @suppressGlobalPropertiesCheck 465 * @suppressGlobalPropertiesCheck
466 */ 466 */
467 _createRange: function() 467 _createRange: function()
468 { 468 {
469 return document.createRange(); 469 return document.createRange();
470 }, 470 },
471 471
472 /** 472 /**
473 * @param {string} prefix 473 * @param {string} prefix
474 * @return {!Array.<string>} 474 * @return {!Array.<{title: string, className: (string|undefined)}>}
dgozman 2016/03/24 18:39:34 WebInspector.SuggestBox.Suggestions
475 */ 475 */
476 additionalCompletions: function(prefix) 476 additionalCompletions: function(prefix)
477 { 477 {
478 return []; 478 return [];
479 }, 479 },
480 480
481 /** 481 /**
482 * @param {!Selection} selection 482 * @param {!Selection} selection
483 * @param {!Range} originalWordPrefixRange 483 * @param {!Range} originalWordPrefixRange
484 * @param {boolean} reverse 484 * @param {boolean} reverse
485 * @param {boolean} force 485 * @param {boolean} force
486 * @param {!Array.<string>} completions 486 * @param {!Array.<string>} completions
487 * @param {number=} selectedIndex 487 * @param {number=} selectedIndex
488 */ 488 */
489 _completionsReady: function(selection, originalWordPrefixRange, reverse, for ce, completions, selectedIndex) 489 _completionsReady: function(selection, originalWordPrefixRange, reverse, for ce, completions, selectedIndex)
490 { 490 {
491 var prefix = originalWordPrefixRange.toString(); 491 var prefix = originalWordPrefixRange.toString();
492 if (prefix || force) {
493 if (prefix)
494 completions = completions.concat(this.additionalCompletions(pref ix));
495 else
496 completions = this.additionalCompletions(prefix).concat(completi ons);
497 }
498 492
499 // Filter out dupes. 493 // Filter out dupes.
500 var store = new Set(); 494 var store = new Set();
501 completions = completions.filter(item => !store.has(item) && !!store.add (item)); 495 completions = completions.filter(item => !store.has(item) && !!store.add (item));
496 var annotatedCompletions = completions.map(item => ({title: item}));
502 497
503 if (!this._waitingForCompletions || !completions.length) { 498 if (prefix || force) {
499 if (prefix)
500 annotatedCompletions = annotatedCompletions.concat(this.addition alCompletions(prefix));
501 else
502 annotatedCompletions = this.additionalCompletions(prefix).concat (annotatedCompletions);
503 }
504
505 if (!this._waitingForCompletions || !annotatedCompletions.length) {
504 this.hideSuggestBox(); 506 this.hideSuggestBox();
505 return; 507 return;
506 } 508 }
507 509
508 delete this._waitingForCompletions; 510 delete this._waitingForCompletions;
509 511
510 var selectionRange = selection.getRangeAt(0); 512 var selectionRange = selection.getRangeAt(0);
511 513
512 var fullWordRange = this._createRange(); 514 var fullWordRange = this._createRange();
513 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset); 515 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset);
514 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et); 516 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et);
515 517
516 if (prefix + selectionRange.toString() !== fullWordRange.toString()) 518 if (prefix + selectionRange.toString() !== fullWordRange.toString())
517 return; 519 return;
518 520
519 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt()) ? -1 : (selectedIndex || 0); 521 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt()) ? -1 : (selectedIndex || 0);
520 522
521 this._userEnteredRange = fullWordRange; 523 this._userEnteredRange = fullWordRange;
522 this._userEnteredText = fullWordRange.toString(); 524 this._userEnteredText = fullWordRange.toString();
523 525
524 if (this._suggestBox) 526 if (this._suggestBox)
525 this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selecti on, fullWordRange), completions, selectedIndex, !this.isCaretAtEndOfPrompt(), th is._userEnteredText); 527 this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selecti on, fullWordRange), annotatedCompletions, selectedIndex, !this.isCaretAtEndOfPro mpt(), this._userEnteredText);
526 528
527 if (selectedIndex === -1) 529 if (selectedIndex === -1)
528 return; 530 return;
529 531
530 var wordPrefixLength = originalWordPrefixRange.toString().length; 532 var wordPrefixLength = originalWordPrefixRange.toString().length;
531 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng th); 533 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng th);
532 534
533 if (this.isCaretAtEndOfPrompt()) { 535 if (this.isCaretAtEndOfPrompt()) {
534 var completionText = completions[selectedIndex]; 536 var completionText = annotatedCompletions[selectedIndex].title;
535 var prefixText = this._userEnteredRange.toString(); 537 var prefixText = this._userEnteredRange.toString();
536 var suffixText = completionText.substring(wordPrefixLength); 538 var suffixText = completionText.substring(wordPrefixLength);
537 this._userEnteredRange.deleteContents(); 539 this._userEnteredRange.deleteContents();
538 this._element.normalize(); 540 this._element.normalize();
539 var finalSelectionRange = this._createRange(); 541 var finalSelectionRange = this._createRange();
540 542
541 var prefixTextNode = createTextNode(prefixText); 543 var prefixTextNode = createTextNode(prefixText);
542 fullWordRange.insertNode(prefixTextNode); 544 fullWordRange.insertNode(prefixTextNode);
543 545
544 this.autoCompleteElement = createElementWithClass("span", "auto-comp lete-text"); 546 this.autoCompleteElement = createElementWithClass("span", "auto-comp lete-text");
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 */ 822 */
821 historyData: function() 823 historyData: function()
822 { 824 {
823 // FIXME: do we need to copy this? 825 // FIXME: do we need to copy this?
824 return this._data; 826 return this._data;
825 }, 827 },
826 828
827 /** 829 /**
828 * @override 830 * @override
829 * @param {string} prefix 831 * @param {string} prefix
830 * @return {!Array.<string>} 832 * @return {!Array.<{title: string, className: (string|undefined)}>}
dgozman 2016/03/24 18:39:34 WebInspector.SuggestBox.Suggestions
831 */ 833 */
832 additionalCompletions: function(prefix) 834 additionalCompletions: function(prefix)
833 { 835 {
834 if (!this.isCaretAtEndOfPrompt()) 836 if (!this.isCaretAtEndOfPrompt())
835 return []; 837 return [];
836 var result = []; 838 var result = [];
837 var text = this.text(); 839 var text = this.text();
840 var set = new Set();
838 for (var i = this._data.length - 1; i >= 0 && result.length < 50; --i) { 841 for (var i = this._data.length - 1; i >= 0 && result.length < 50; --i) {
839 var item = this._data[i]; 842 var item = this._data[i];
840 if (!item.startsWith(text)) 843 if (!item.startsWith(text))
841 continue; 844 continue;
842 result.push(item.substring(text.length - prefix.length)); 845 if (set.has(item))
846 continue;
847 set.add(item);
848 result.push({title: item.substring(text.length - prefix.length), cla ssName: "additional"});
843 } 849 }
844 return result; 850 return result;
845 }, 851 },
846 852
847 /** 853 /**
848 * @param {!Array.<string>} data 854 * @param {!Array.<string>} data
849 */ 855 */
850 setHistoryData: function(data) 856 setHistoryData: function(data)
851 { 857 {
852 this._data = [].concat(data); 858 this._data = [].concat(data);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 974
969 return; 975 return;
970 } 976 }
971 977
972 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); 978 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments);
973 }, 979 },
974 980
975 __proto__: WebInspector.TextPrompt.prototype 981 __proto__: WebInspector.TextPrompt.prototype
976 } 982 }
977 983
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698