| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 /** | 300 /** |
| 301 * @param {!Event} event | 301 * @param {!Event} event |
| 302 */ | 302 */ |
| 303 onInput(event) { | 303 onInput(event) { |
| 304 var text = this.text(); | 304 var text = this.text(); |
| 305 var hasCommonPrefix = text.startsWith(this._previousText) || this._previousT
ext.startsWith(text); | 305 var hasCommonPrefix = text.startsWith(this._previousText) || this._previousT
ext.startsWith(text); |
| 306 if (this._queryRange && hasCommonPrefix) | 306 if (this._queryRange && hasCommonPrefix) |
| 307 this._queryRange.endColumn += text.length - this._previousText.length; | 307 this._queryRange.endColumn += text.length - this._previousText.length; |
| 308 this._refreshGhostText(); | 308 this._refreshGhostText(); |
| 309 this._previousText = text; | 309 this._previousText = text; |
| 310 this.emit(new UI.TextPrompt.TextChangedEvent()); |
| 310 | 311 |
| 311 this.autoCompleteSoon(); | 312 this.autoCompleteSoon(); |
| 312 } | 313 } |
| 313 | 314 |
| 314 /** | 315 /** |
| 315 * @return {boolean} | 316 * @return {boolean} |
| 316 */ | 317 */ |
| 317 acceptAutoComplete() { | 318 acceptAutoComplete() { |
| 318 var result = false; | 319 var result = false; |
| 319 if (this._isSuggestBoxVisible()) | 320 if (this._isSuggestBoxVisible()) |
| 320 result = this._suggestBox.acceptSuggestion(); | 321 result = this._suggestBox.acceptSuggestion(); |
| 321 if (!result) | 322 if (!result) |
| 322 result = this._acceptSuggestionInternal(); | 323 result = this._acceptSuggestionInternal(); |
| 323 | 324 |
| 324 return result; | 325 return result; |
| 325 } | 326 } |
| 326 | 327 |
| 327 clearAutocomplete() { | 328 clearAutocomplete() { |
| 328 var beforeText = this.textWithCurrentSuggestion(); | 329 var beforeText = this.textWithCurrentSuggestion(); |
| 329 | 330 |
| 330 if (this._isSuggestBoxVisible()) | 331 if (this._isSuggestBoxVisible()) |
| 331 this._suggestBox.hide(); | 332 this._suggestBox.hide(); |
| 332 this._clearAutocompleteTimeout(); | 333 this._clearAutocompleteTimeout(); |
| 333 this._queryRange = null; | 334 this._queryRange = null; |
| 334 this._refreshGhostText(); | 335 this._refreshGhostText(); |
| 335 | 336 |
| 336 if (beforeText !== this.textWithCurrentSuggestion()) | 337 if (beforeText !== this.textWithCurrentSuggestion()) |
| 337 this.dispatchEventToListeners(UI.TextPrompt.Events.ItemApplied); | 338 this.emit(new UI.TextPrompt.TextChangedEvent()); |
| 338 } | 339 } |
| 339 | 340 |
| 340 _refreshGhostText() { | 341 _refreshGhostText() { |
| 341 if (this._queryRange && this._isCaretAtEndOfPrompt() && | 342 if (this._queryRange && this._isCaretAtEndOfPrompt() && |
| 342 this._currentSuggestion.startsWith(this.text().substring(this._queryRang
e.startColumn))) { | 343 this._currentSuggestion.startsWith(this.text().substring(this._queryRang
e.startColumn))) { |
| 343 this._ghostTextElement.textContent = | 344 this._ghostTextElement.textContent = |
| 344 this._currentSuggestion.substring(this._queryRange.endColumn - this._q
ueryRange.startColumn); | 345 this._currentSuggestion.substring(this._queryRange.endColumn - this._q
ueryRange.startColumn); |
| 345 this._element.appendChild(this._ghostTextElement); | 346 this._element.appendChild(this._ghostTextElement); |
| 346 } else { | 347 } else { |
| 347 this._ghostTextElement.remove(); | 348 this._ghostTextElement.remove(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 * @override | 502 * @override |
| 502 * @param {string} suggestion | 503 * @param {string} suggestion |
| 503 * @param {boolean=} isIntermediateSuggestion | 504 * @param {boolean=} isIntermediateSuggestion |
| 504 */ | 505 */ |
| 505 applySuggestion(suggestion, isIntermediateSuggestion) { | 506 applySuggestion(suggestion, isIntermediateSuggestion) { |
| 506 if (!this._queryRange) | 507 if (!this._queryRange) |
| 507 return; | 508 return; |
| 508 this._currentSuggestion = suggestion; | 509 this._currentSuggestion = suggestion; |
| 509 this._refreshGhostText(); | 510 this._refreshGhostText(); |
| 510 if (isIntermediateSuggestion) | 511 if (isIntermediateSuggestion) |
| 511 this.dispatchEventToListeners(UI.TextPrompt.Events.ItemApplied); | 512 this.emit(new UI.TextPrompt.TextChangedEvent()); |
| 512 } | 513 } |
| 513 | 514 |
| 514 /** | 515 /** |
| 515 * @override | 516 * @override |
| 516 */ | 517 */ |
| 517 acceptSuggestion() { | 518 acceptSuggestion() { |
| 518 this._acceptSuggestionInternal(); | 519 this._acceptSuggestionInternal(); |
| 519 } | 520 } |
| 520 | 521 |
| 521 /** | 522 /** |
| 522 * @return {boolean} | 523 * @return {boolean} |
| 523 */ | 524 */ |
| 524 _acceptSuggestionInternal() { | 525 _acceptSuggestionInternal() { |
| 525 if (!this._queryRange) | 526 if (!this._queryRange) |
| 526 return false; | 527 return false; |
| 527 | 528 |
| 528 this._element.textContent = this.textWithCurrentSuggestion(); | 529 this._element.textContent = this.textWithCurrentSuggestion(); |
| 529 this.setDOMSelection( | 530 this.setDOMSelection( |
| 530 this._queryRange.startColumn + this._currentSuggestion.length, | 531 this._queryRange.startColumn + this._currentSuggestion.length, |
| 531 this._queryRange.startColumn + this._currentSuggestion.length); | 532 this._queryRange.startColumn + this._currentSuggestion.length); |
| 532 | 533 |
| 533 this.clearAutocomplete(); | 534 this.clearAutocomplete(); |
| 534 this.dispatchEventToListeners(UI.TextPrompt.Events.ItemAccepted); | 535 this.emit(new UI.TextPrompt.TextChangedEvent()); |
| 535 | 536 |
| 536 return true; | 537 return true; |
| 537 } | 538 } |
| 538 | 539 |
| 539 /** | 540 /** |
| 540 * @param {number} startColumn | 541 * @param {number} startColumn |
| 541 * @param {number} endColumn | 542 * @param {number} endColumn |
| 542 */ | 543 */ |
| 543 setDOMSelection(startColumn, endColumn) { | 544 setDOMSelection(startColumn, endColumn) { |
| 544 this._element.normalize(); | 545 this._element.normalize(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 /** | 632 /** |
| 632 * @return {?Element} | 633 * @return {?Element} |
| 633 */ | 634 */ |
| 634 proxyElementForTests() { | 635 proxyElementForTests() { |
| 635 return this._proxyElement || null; | 636 return this._proxyElement || null; |
| 636 } | 637 } |
| 637 }; | 638 }; |
| 638 | 639 |
| 639 UI.TextPrompt.DefaultAutocompletionTimeout = 250; | 640 UI.TextPrompt.DefaultAutocompletionTimeout = 250; |
| 640 | 641 |
| 641 /** @enum {symbol} */ | 642 /** @implements {Common.Emittable} */ |
| 642 UI.TextPrompt.Events = { | 643 UI.TextPrompt.TextChangedEvent = class {}; |
| 643 ItemApplied: Symbol('text-prompt-item-applied'), | |
| 644 ItemAccepted: Symbol('text-prompt-item-accepted') | |
| 645 }; | |
| OLD | NEW |