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._completionRequestId = 0; |
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, ++this._completio
nRequestId, selection, wordPrefixRange, !!reverse, !!force)); |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 /** | 488 /** |
490 * @param {string} prefix | 489 * @param {string} prefix |
491 * @return {!WebInspector.SuggestBox.Suggestions} | 490 * @return {!WebInspector.SuggestBox.Suggestions} |
492 */ | 491 */ |
493 additionalCompletions: function(prefix) | 492 additionalCompletions: function(prefix) |
494 { | 493 { |
495 return []; | 494 return []; |
496 }, | 495 }, |
497 | 496 |
498 /** | 497 /** |
| 498 * @param {number} completionRequestId |
499 * @param {!Selection} selection | 499 * @param {!Selection} selection |
500 * @param {!Range} originalWordPrefixRange | 500 * @param {!Range} originalWordPrefixRange |
501 * @param {boolean} reverse | 501 * @param {boolean} reverse |
502 * @param {boolean} force | 502 * @param {boolean} force |
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(completionRequestId, selection, originalWordPref
ixRange, reverse, force, completions, selectedIndex) |
507 { | 507 { |
| 508 if (this._completionRequestId !== completionRequestId) |
| 509 return; |
| 510 |
508 var prefix = originalWordPrefixRange.toString(); | 511 var prefix = originalWordPrefixRange.toString(); |
509 | 512 |
510 // Filter out dupes. | 513 // Filter out dupes. |
511 var store = new Set(); | 514 var store = new Set(); |
512 completions = completions.filter(item => !store.has(item) && !!store.add
(item)); | 515 completions = completions.filter(item => !store.has(item) && !!store.add
(item)); |
513 var annotatedCompletions = completions.map(item => ({title: item})); | 516 var annotatedCompletions = completions.map(item => ({title: item})); |
514 | 517 |
515 if (prefix || force) { | 518 if (prefix || force) { |
516 if (prefix) | 519 if (prefix) |
517 annotatedCompletions = annotatedCompletions.concat(this.addition
alCompletions(prefix)); | 520 annotatedCompletions = annotatedCompletions.concat(this.addition
alCompletions(prefix)); |
518 else | 521 else |
519 annotatedCompletions = this.additionalCompletions(prefix).concat
(annotatedCompletions); | 522 annotatedCompletions = this.additionalCompletions(prefix).concat
(annotatedCompletions); |
520 } | 523 } |
521 | 524 |
522 if (!this._waitingForCompletions || !annotatedCompletions.length) { | 525 if (!annotatedCompletions.length) { |
523 this.clearAutoComplete(); | 526 this.clearAutoComplete(); |
524 return; | 527 return; |
525 } | 528 } |
526 | 529 |
527 delete this._waitingForCompletions; | |
528 | |
529 var selectionRange = selection.getRangeAt(0); | 530 var selectionRange = selection.getRangeAt(0); |
530 | 531 |
531 var fullWordRange = this._createRange(); | 532 var fullWordRange = this._createRange(); |
532 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW
ordPrefixRange.startOffset); | 533 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW
ordPrefixRange.startOffset); |
533 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); | 534 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); |
534 | 535 |
535 if (prefix + selectionRange.toString() !== fullWordRange.toString()) | 536 if (prefix + selectionRange.toString() !== fullWordRange.toString()) |
536 return; | 537 return; |
537 | 538 |
538 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te
xt()) ? -1 : (selectedIndex || 0); | 539 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te
xt()) ? -1 : (selectedIndex || 0); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 }, | 1019 }, |
1019 | 1020 |
1020 /** | 1021 /** |
1021 * @return {string|undefined} | 1022 * @return {string|undefined} |
1022 */ | 1023 */ |
1023 _currentHistoryItem: function() | 1024 _currentHistoryItem: function() |
1024 { | 1025 { |
1025 return this._data[this._data.length - this._historyOffset]; | 1026 return this._data[this._data.length - this._historyOffset]; |
1026 } | 1027 } |
1027 }; | 1028 }; |
OLD | NEW |