| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 this._disableDefaultSuggestionForEmptyInput = true; | 407 this._disableDefaultSuggestionForEmptyInput = true; |
| 408 }, | 408 }, |
| 409 | 409 |
| 410 /** | 410 /** |
| 411 * @param {!Selection} selection | 411 * @param {!Selection} selection |
| 412 * @param {!Range} textRange | 412 * @param {!Range} textRange |
| 413 */ | 413 */ |
| 414 _boxForAnchorAtStart: function(selection, textRange) | 414 _boxForAnchorAtStart: function(selection, textRange) |
| 415 { | 415 { |
| 416 var rangeCopy = selection.getRangeAt(0).cloneRange(); | 416 var rangeCopy = selection.getRangeAt(0).cloneRange(); |
| 417 var anchorElement = document.createElement("span"); | 417 var anchorElement = createElement("span"); |
| 418 anchorElement.textContent = "\u200B"; | 418 anchorElement.textContent = "\u200B"; |
| 419 textRange.insertNode(anchorElement); | 419 textRange.insertNode(anchorElement); |
| 420 var box = anchorElement.boxInWindow(window); | 420 var box = anchorElement.boxInWindow(window); |
| 421 anchorElement.remove(); | 421 anchorElement.remove(); |
| 422 selection.removeAllRanges(); | 422 selection.removeAllRanges(); |
| 423 selection.addRange(rangeCopy); | 423 selection.addRange(rangeCopy); |
| 424 return box; | 424 return box; |
| 425 }, | 425 }, |
| 426 | 426 |
| 427 /** | 427 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng
th); | 483 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng
th); |
| 484 | 484 |
| 485 if (this.isCaretAtEndOfPrompt()) { | 485 if (this.isCaretAtEndOfPrompt()) { |
| 486 var completionText = completions[selectedIndex]; | 486 var completionText = completions[selectedIndex]; |
| 487 var prefixText = this._userEnteredRange.toString(); | 487 var prefixText = this._userEnteredRange.toString(); |
| 488 var suffixText = completionText.substring(wordPrefixLength); | 488 var suffixText = completionText.substring(wordPrefixLength); |
| 489 this._userEnteredRange.deleteContents(); | 489 this._userEnteredRange.deleteContents(); |
| 490 this._element.normalize(); | 490 this._element.normalize(); |
| 491 var finalSelectionRange = document.createRange(); | 491 var finalSelectionRange = document.createRange(); |
| 492 | 492 |
| 493 var prefixTextNode = document.createTextNode(prefixText); | 493 var prefixTextNode = createTextNode(prefixText); |
| 494 fullWordRange.insertNode(prefixTextNode); | 494 fullWordRange.insertNode(prefixTextNode); |
| 495 | 495 |
| 496 this.autoCompleteElement = document.createElementWithClass("span", "
auto-complete-text"); | 496 this.autoCompleteElement = createElementWithClass("span", "auto-comp
lete-text"); |
| 497 this.autoCompleteElement.textContent = suffixText; | 497 this.autoCompleteElement.textContent = suffixText; |
| 498 | 498 |
| 499 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre
fixTextNode.nextSibling); | 499 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre
fixTextNode.nextSibling); |
| 500 | 500 |
| 501 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength); | 501 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength); |
| 502 finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength); | 502 finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength); |
| 503 selection.removeAllRanges(); | 503 selection.removeAllRanges(); |
| 504 selection.addRange(finalSelectionRange); | 504 selection.addRange(finalSelectionRange); |
| 505 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApp
lied); | 505 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApp
lied); |
| 506 } | 506 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 { | 538 { |
| 539 var wordPrefixLength; | 539 var wordPrefixLength; |
| 540 if (originalPrefixRange) | 540 if (originalPrefixRange) |
| 541 wordPrefixLength = originalPrefixRange.toString().length; | 541 wordPrefixLength = originalPrefixRange.toString().length; |
| 542 else | 542 else |
| 543 wordPrefixLength = this._userEnteredText ? this._userEnteredText.len
gth : 0; | 543 wordPrefixLength = this._userEnteredText ? this._userEnteredText.len
gth : 0; |
| 544 | 544 |
| 545 this._userEnteredRange.deleteContents(); | 545 this._userEnteredRange.deleteContents(); |
| 546 this._element.normalize(); | 546 this._element.normalize(); |
| 547 var finalSelectionRange = document.createRange(); | 547 var finalSelectionRange = document.createRange(); |
| 548 var completionTextNode = document.createTextNode(completionText); | 548 var completionTextNode = createTextNode(completionText); |
| 549 this._userEnteredRange.insertNode(completionTextNode); | 549 this._userEnteredRange.insertNode(completionTextNode); |
| 550 if (this.autoCompleteElement) { | 550 if (this.autoCompleteElement) { |
| 551 this.autoCompleteElement.remove(); | 551 this.autoCompleteElement.remove(); |
| 552 delete this.autoCompleteElement; | 552 delete this.autoCompleteElement; |
| 553 } | 553 } |
| 554 | 554 |
| 555 if (isIntermediateSuggestion) | 555 if (isIntermediateSuggestion) |
| 556 finalSelectionRange.setStart(completionTextNode, wordPrefixLength); | 556 finalSelectionRange.setStart(completionTextNode, wordPrefixLength); |
| 557 else | 557 else |
| 558 finalSelectionRange.setStart(completionTextNode, completionText.leng
th); | 558 finalSelectionRange.setStart(completionTextNode, completionText.leng
th); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 577 /** | 577 /** |
| 578 * @param {boolean=} prefixAccepted | 578 * @param {boolean=} prefixAccepted |
| 579 * @return {boolean} | 579 * @return {boolean} |
| 580 */ | 580 */ |
| 581 _acceptSuggestionInternal: function(prefixAccepted) | 581 _acceptSuggestionInternal: function(prefixAccepted) |
| 582 { | 582 { |
| 583 if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode) | 583 if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode) |
| 584 return false; | 584 return false; |
| 585 | 585 |
| 586 var text = this.autoCompleteElement.textContent; | 586 var text = this.autoCompleteElement.textContent; |
| 587 var textNode = document.createTextNode(text); | 587 var textNode = createTextNode(text); |
| 588 this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoComp
leteElement); | 588 this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoComp
leteElement); |
| 589 delete this.autoCompleteElement; | 589 delete this.autoCompleteElement; |
| 590 | 590 |
| 591 var finalSelectionRange = document.createRange(); | 591 var finalSelectionRange = document.createRange(); |
| 592 finalSelectionRange.setStart(textNode, text.length); | 592 finalSelectionRange.setStart(textNode, text.length); |
| 593 finalSelectionRange.setEnd(textNode, text.length); | 593 finalSelectionRange.setEnd(textNode, text.length); |
| 594 | 594 |
| 595 var selection = window.getSelection(); | 595 var selection = window.getSelection(); |
| 596 selection.removeAllRanges(); | 596 selection.removeAllRanges(); |
| 597 selection.addRange(finalSelectionRange); | 597 selection.addRange(finalSelectionRange); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 | 907 |
| 908 return; | 908 return; |
| 909 } | 909 } |
| 910 | 910 |
| 911 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); | 911 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); |
| 912 }, | 912 }, |
| 913 | 913 |
| 914 __proto__: WebInspector.TextPrompt.prototype | 914 __proto__: WebInspector.TextPrompt.prototype |
| 915 } | 915 } |
| 916 | 916 |
| OLD | NEW |