Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 27 matching lines...) Expand all Loading... | |
| 38 { | 38 { |
| 39 /** | 39 /** |
| 40 * @type {!Element|undefined} | 40 * @type {!Element|undefined} |
| 41 */ | 41 */ |
| 42 this._proxyElement; | 42 this._proxyElement; |
| 43 this._proxyElementDisplay = "inline-block"; | 43 this._proxyElementDisplay = "inline-block"; |
| 44 this._loadCompletions = completions; | 44 this._loadCompletions = completions; |
| 45 this._completionStopCharacters = stopCharacters || " =:[({;,!+-*/&|^<>."; | 45 this._completionStopCharacters = stopCharacters || " =:[({;,!+-*/&|^<>."; |
| 46 this._autocompletionTimeout = WebInspector.TextPrompt.DefaultAutocompletionT imeout; | 46 this._autocompletionTimeout = WebInspector.TextPrompt.DefaultAutocompletionT imeout; |
| 47 this._title = ""; | 47 this._title = ""; |
| 48 this._completionsCounter = 0; | |
|
lushnikov
2016/09/08 14:45:50
let's name it _completionRequestId
einbinder
2016/09/08 17:49:16
Done.
| |
| 48 } | 49 } |
| 49 | 50 |
| 50 WebInspector.TextPrompt.DefaultAutocompletionTimeout = 250; | 51 WebInspector.TextPrompt.DefaultAutocompletionTimeout = 250; |
| 51 | 52 |
| 52 /** @enum {symbol} */ | 53 /** @enum {symbol} */ |
| 53 WebInspector.TextPrompt.Events = { | 54 WebInspector.TextPrompt.Events = { |
| 54 ItemApplied: Symbol("text-prompt-item-applied"), | 55 ItemApplied: Symbol("text-prompt-item-applied"), |
| 55 ItemAccepted: Symbol("text-prompt-item-accepted") | 56 ItemAccepted: Symbol("text-prompt-item-accepted") |
| 56 }; | 57 }; |
| 57 | 58 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 374 |
| 374 clearAutoComplete: function() | 375 clearAutoComplete: function() |
| 375 { | 376 { |
| 376 if (this.isSuggestBoxVisible()) | 377 if (this.isSuggestBoxVisible()) |
| 377 this._suggestBox.hide(); | 378 this._suggestBox.hide(); |
| 378 | 379 |
| 379 if (this._completeTimeout) { | 380 if (this._completeTimeout) { |
| 380 clearTimeout(this._completeTimeout); | 381 clearTimeout(this._completeTimeout); |
| 381 delete this._completeTimeout; | 382 delete this._completeTimeout; |
| 382 } | 383 } |
| 383 delete this._waitingForCompletions; | |
| 384 | 384 |
| 385 if (!this.autoCompleteElement) | 385 if (!this.autoCompleteElement) |
| 386 return; | 386 return; |
| 387 | 387 |
| 388 this.autoCompleteElement.remove(); | 388 this.autoCompleteElement.remove(); |
| 389 delete this.autoCompleteElement; | 389 delete this.autoCompleteElement; |
| 390 delete this._userEnteredRange; | 390 delete this._userEnteredRange; |
| 391 delete this._userEnteredText; | 391 delete this._userEnteredText; |
| 392 }, | 392 }, |
| 393 | 393 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 424 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele ctionRange.endOffset, this._completionStopCharacters, this._element, "forward"); | 424 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele ctionRange.endOffset, this._completionStopCharacters, this._element, "forward"); |
| 425 if (wordSuffixRange.toString().length) | 425 if (wordSuffixRange.toString().length) |
| 426 shouldExit = true; | 426 shouldExit = true; |
| 427 } | 427 } |
| 428 if (shouldExit) { | 428 if (shouldExit) { |
| 429 this.clearAutoComplete(); | 429 this.clearAutoComplete(); |
| 430 return; | 430 return; |
| 431 } | 431 } |
| 432 | 432 |
| 433 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio nRange.startOffset, this._completionStopCharacters, this._element, "backward"); | 433 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio nRange.startOffset, this._completionStopCharacters, this._element, "backward"); |
| 434 this._waitingForCompletions = true; | 434 this._loadCompletions(/** @type {!Element} */ (this._proxyElement), word PrefixRange, force || false, this._completionsReady.bind(this, selection, wordPr efixRange, !!reverse, !!force, ++this._completionsCounter)); |
| 435 this._loadCompletions(/** @type {!Element} */ (this._proxyElement), word PrefixRange, force || false, this._completionsReady.bind(this, selection, wordPr efixRange, !!reverse, !!force)); | |
| 436 }, | 435 }, |
| 437 | 436 |
| 438 disableDefaultSuggestionForEmptyInput: function() | 437 disableDefaultSuggestionForEmptyInput: function() |
| 439 { | 438 { |
| 440 this._disableDefaultSuggestionForEmptyInput = true; | 439 this._disableDefaultSuggestionForEmptyInput = true; |
| 441 }, | 440 }, |
| 442 | 441 |
| 443 /** | 442 /** |
| 444 * @param {!Selection} selection | 443 * @param {!Selection} selection |
| 445 * @param {!Range} textRange | 444 * @param {!Range} textRange |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 additionalCompletions: function(prefix) | 492 additionalCompletions: function(prefix) |
| 494 { | 493 { |
| 495 return []; | 494 return []; |
| 496 }, | 495 }, |
| 497 | 496 |
| 498 /** | 497 /** |
| 499 * @param {!Selection} selection | 498 * @param {!Selection} selection |
| 500 * @param {!Range} originalWordPrefixRange | 499 * @param {!Range} originalWordPrefixRange |
| 501 * @param {boolean} reverse | 500 * @param {boolean} reverse |
| 502 * @param {boolean} force | 501 * @param {boolean} force |
| 502 * @param {number} completionsCounter | |
|
lushnikov
2016/09/08 14:45:50
let's make it the very first one and name it compl
einbinder
2016/09/08 17:49:16
Done.
| |
| 503 * @param {!Array.<string>} completions | 503 * @param {!Array.<string>} completions |
| 504 * @param {number=} selectedIndex | 504 * @param {number=} selectedIndex |
| 505 */ | 505 */ |
| 506 _completionsReady: function(selection, originalWordPrefixRange, reverse, for ce, completions, selectedIndex) | 506 _completionsReady: function(selection, originalWordPrefixRange, reverse, for ce, completionsCounter, completions, selectedIndex) |
| 507 { | 507 { |
| 508 var prefix = originalWordPrefixRange.toString(); | 508 var prefix = originalWordPrefixRange.toString(); |
| 509 | 509 |
| 510 // Filter out dupes. | 510 // Filter out dupes. |
| 511 var store = new Set(); | 511 var store = new Set(); |
| 512 completions = completions.filter(item => !store.has(item) && !!store.add (item)); | 512 completions = completions.filter(item => !store.has(item) && !!store.add (item)); |
| 513 var annotatedCompletions = completions.map(item => ({title: item})); | 513 var annotatedCompletions = completions.map(item => ({title: item})); |
| 514 | 514 |
| 515 if (prefix || force) { | 515 if (prefix || force) { |
| 516 if (prefix) | 516 if (prefix) |
| 517 annotatedCompletions = annotatedCompletions.concat(this.addition alCompletions(prefix)); | 517 annotatedCompletions = annotatedCompletions.concat(this.addition alCompletions(prefix)); |
| 518 else | 518 else |
| 519 annotatedCompletions = this.additionalCompletions(prefix).concat (annotatedCompletions); | 519 annotatedCompletions = this.additionalCompletions(prefix).concat (annotatedCompletions); |
| 520 } | 520 } |
| 521 | 521 |
| 522 if (!this._waitingForCompletions || !annotatedCompletions.length) { | 522 if (this._completionsCounter !== completionsCounter || !annotatedComplet ions.length) { |
|
lushnikov
2016/09/08 14:45:50
let's bail out in the very beginning of the callba
einbinder
2016/09/08 17:49:16
Done.
| |
| 523 this.clearAutoComplete(); | 523 this.clearAutoComplete(); |
| 524 return; | 524 return; |
| 525 } | 525 } |
| 526 | 526 |
| 527 delete this._waitingForCompletions; | |
| 528 | |
| 529 var selectionRange = selection.getRangeAt(0); | 527 var selectionRange = selection.getRangeAt(0); |
| 530 | 528 |
| 531 var fullWordRange = this._createRange(); | 529 var fullWordRange = this._createRange(); |
| 532 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset); | 530 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset); |
| 533 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et); | 531 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et); |
| 534 | 532 |
| 535 if (prefix + selectionRange.toString() !== fullWordRange.toString()) | 533 if (prefix + selectionRange.toString() !== fullWordRange.toString()) |
| 536 return; | 534 return; |
| 537 | 535 |
| 538 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt()) ? -1 : (selectedIndex || 0); | 536 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt()) ? -1 : (selectedIndex || 0); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 }, | 1016 }, |
| 1019 | 1017 |
| 1020 /** | 1018 /** |
| 1021 * @return {string|undefined} | 1019 * @return {string|undefined} |
| 1022 */ | 1020 */ |
| 1023 _currentHistoryItem: function() | 1021 _currentHistoryItem: function() |
| 1024 { | 1022 { |
| 1025 return this._data[this._data.length - this._historyOffset]; | 1023 return this._data[this._data.length - this._historyOffset]; |
| 1026 } | 1024 } |
| 1027 }; | 1025 }; |
| OLD | NEW |