| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 * @param {?WebInspector.TextRange} range | 332 * @param {?WebInspector.TextRange} range |
| 333 */ | 333 */ |
| 334 highlightSearchResults: function(regex, range) | 334 highlightSearchResults: function(regex, range) |
| 335 { | 335 { |
| 336 /** | 336 /** |
| 337 * @this {WebInspector.CodeMirrorTextEditor} | 337 * @this {WebInspector.CodeMirrorTextEditor} |
| 338 */ | 338 */ |
| 339 function innerHighlightRegex() | 339 function innerHighlightRegex() |
| 340 { | 340 { |
| 341 if (range) { | 341 if (range) { |
| 342 this.revealLine(range.startLine); | 342 this._revealLine(range.startLine); |
| 343 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl
ightLength) | 343 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl
ightLength) |
| 344 this.setSelection(range); | 344 this.setSelection(range); |
| 345 else | 345 else |
| 346 this.setSelection(WebInspector.TextRange.createFromLocation(
range.startLine, range.startColumn)); | 346 this.setSelection(WebInspector.TextRange.createFromLocation(
range.startLine, range.startColumn)); |
| 347 } else { | 347 } else { |
| 348 // Collapse selection to end on search start so that we jump to
next occurence on the first enter press. | 348 // Collapse selection to end on search start so that we jump to
next occurence on the first enter press. |
| 349 this.setSelection(this.selection().collapseToEnd()); | 349 this.setSelection(this.selection().collapseToEnd()); |
| 350 } | 350 } |
| 351 this._tokenHighlighter.highlightSearchResults(regex, range); | 351 this._tokenHighlighter.highlightSearchResults(regex, range); |
| 352 } | 352 } |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 678 |
| 679 endUpdates: function() | 679 endUpdates: function() |
| 680 { | 680 { |
| 681 if (!--this._nestedUpdatesCounter) | 681 if (!--this._nestedUpdatesCounter) |
| 682 this._codeMirror.refresh(); | 682 this._codeMirror.refresh(); |
| 683 }, | 683 }, |
| 684 | 684 |
| 685 /** | 685 /** |
| 686 * @param {number} lineNumber | 686 * @param {number} lineNumber |
| 687 */ | 687 */ |
| 688 revealLine: function(lineNumber) | 688 _revealLine: function(lineNumber) |
| 689 { | 689 { |
| 690 this._innerRevealLine(lineNumber, this._codeMirror.getScrollInfo()); | 690 this._innerRevealLine(lineNumber, this._codeMirror.getScrollInfo()); |
| 691 }, | 691 }, |
| 692 | 692 |
| 693 /** | 693 /** |
| 694 * @param {number} lineNumber | 694 * @param {number} lineNumber |
| 695 * @param {!{left: number, top: number, width: number, height: number, clien
tWidth: number, clientHeight: number}} scrollInfo | 695 * @param {!{left: number, top: number, width: number, height: number, clien
tWidth: number, clientHeight: number}} scrollInfo |
| 696 */ | 696 */ |
| 697 _innerRevealLine: function(lineNumber, scrollInfo) | 697 _innerRevealLine: function(lineNumber, scrollInfo) |
| 698 { | 698 { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 removeDecoration: function(lineNumber, element) | 787 removeDecoration: function(lineNumber, element) |
| 788 { | 788 { |
| 789 var widget = this._elementToWidget.remove(element); | 789 var widget = this._elementToWidget.remove(element); |
| 790 if (widget) | 790 if (widget) |
| 791 this._codeMirror.removeLineWidget(widget); | 791 this._codeMirror.removeLineWidget(widget); |
| 792 }, | 792 }, |
| 793 | 793 |
| 794 /** | 794 /** |
| 795 * @param {number} lineNumber | 795 * @param {number} lineNumber |
| 796 * @param {number=} columnNumber | 796 * @param {number=} columnNumber |
| 797 * @param {boolean=} shouldHighlight |
| 797 */ | 798 */ |
| 798 highlightPosition: function(lineNumber, columnNumber) | 799 revealPosition: function(lineNumber, columnNumber, shouldHighlight) |
| 799 { | 800 { |
| 800 lineNumber = Number.constrain(lineNumber, 0, this._codeMirror.lineCount(
) - 1); | 801 lineNumber = Number.constrain(lineNumber, 0, this._codeMirror.lineCount(
) - 1); |
| 801 if (typeof columnNumber !== "number") | 802 if (typeof columnNumber !== "number") |
| 802 columnNumber = 0; | 803 columnNumber = 0; |
| 803 columnNumber = Number.constrain(columnNumber, 0, this._codeMirror.getLin
e(lineNumber).length); | 804 columnNumber = Number.constrain(columnNumber, 0, this._codeMirror.getLin
e(lineNumber).length); |
| 804 | 805 |
| 805 this.clearPositionHighlight(); | 806 this.clearPositionHighlight(); |
| 806 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); | 807 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); |
| 807 if (!this._highlightedLine) | 808 if (!this._highlightedLine) |
| 808 return; | 809 return; |
| 809 this.revealLine(lineNumber); | 810 this._revealLine(lineNumber); |
| 810 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight
"); | 811 if (shouldHighlight) { |
| 811 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin
d(this), 2000); | 812 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highl
ight"); |
| 813 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight
.bind(this), 2000); |
| 814 } |
| 812 this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber,
columnNumber)); | 815 this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber,
columnNumber)); |
| 813 }, | 816 }, |
| 814 | 817 |
| 815 clearPositionHighlight: function() | 818 clearPositionHighlight: function() |
| 816 { | 819 { |
| 817 if (this._clearHighlightTimeout) | 820 if (this._clearHighlightTimeout) |
| 818 clearTimeout(this._clearHighlightTimeout); | 821 clearTimeout(this._clearHighlightTimeout); |
| 819 delete this._clearHighlightTimeout; | 822 delete this._clearHighlightTimeout; |
| 820 | 823 |
| 821 if (this._highlightedLine) | 824 if (this._highlightedLine) |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte
d { background-color: " + backgroundColor + ";}" : ""; | 1719 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte
d { background-color: " + backgroundColor + ";}" : ""; |
| 1717 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); | 1720 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); |
| 1718 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte
dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import
ant;}" : ""; | 1721 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte
dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import
ant;}" : ""; |
| 1719 if (!foregroundColorRule && !backgroundColorRule) | 1722 if (!foregroundColorRule && !backgroundColorRule) |
| 1720 return; | 1723 return; |
| 1721 | 1724 |
| 1722 var style = document.createElement("style"); | 1725 var style = document.createElement("style"); |
| 1723 style.textContent = backgroundColorRule + foregroundColorRule; | 1726 style.textContent = backgroundColorRule + foregroundColorRule; |
| 1724 document.head.appendChild(style); | 1727 document.head.appendChild(style); |
| 1725 })(); | 1728 })(); |
| OLD | NEW |