| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.CodeMirrorTextEditor} | 7 * @extends {WebInspector.CodeMirrorTextEditor} |
| 8 * @param {!WebInspector.SourcesTextEditorDelegate} delegate | 8 * @param {!WebInspector.SourcesTextEditorDelegate} delegate |
| 9 */ | 9 */ |
| 10 WebInspector.SourcesTextEditor = function(delegate) | 10 WebInspector.SourcesTextEditor = function(delegate) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, true), true); | 52 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, true), true); |
| 53 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, false), false); | 53 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, false), false); |
| 54 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this._onUpd
ateEditorIndentation, this); | 54 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this._onUpd
ateEditorIndentation, this); |
| 55 WebInspector.moduleSetting("textEditorAutoDetectIndent").addChangeListener(t
his._onUpdateEditorIndentation, this); | 55 WebInspector.moduleSetting("textEditorAutoDetectIndent").addChangeListener(t
his._onUpdateEditorIndentation, this); |
| 56 WebInspector.moduleSetting("showWhitespacesInEditor").addChangeListener(this
._updateWhitespace, this); | 56 WebInspector.moduleSetting("showWhitespacesInEditor").addChangeListener(this
._updateWhitespace, this); |
| 57 | 57 |
| 58 this._onUpdateEditorIndentation(); | 58 this._onUpdateEditorIndentation(); |
| 59 this._setupWhitespaceHighlight(); | 59 this._setupWhitespaceHighlight(); |
| 60 } | 60 }; |
| 61 WebInspector.SourcesTextEditor.prototype = { | 61 WebInspector.SourcesTextEditor.prototype = { |
| 62 /** | 62 /** |
| 63 * @return {boolean} | 63 * @return {boolean} |
| 64 */ | 64 */ |
| 65 _isSearchActive: function() | 65 _isSearchActive: function() |
| 66 { | 66 { |
| 67 return !!this._tokenHighlighter.highlightedRegex(); | 67 return !!this._tokenHighlighter.highlightedRegex(); |
| 68 }, | 68 }, |
| 69 | 69 |
| 70 /** | 70 /** |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 this.refresh(); | 193 this.refresh(); |
| 194 }, | 194 }, |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * @param {number} lineNumber | 197 * @param {number} lineNumber |
| 198 * @param {string} type | 198 * @param {string} type |
| 199 * @param {?Element} element | 199 * @param {?Element} element |
| 200 */ | 200 */ |
| 201 setGutterDecoration: function(lineNumber, type, element) | 201 setGutterDecoration: function(lineNumber, type, element) |
| 202 { | 202 { |
| 203 console.assert(this._gutters.indexOf(type) !== -1, "Cannot decorate unex
isting gutter.") | 203 console.assert(this._gutters.indexOf(type) !== -1, "Cannot decorate unex
isting gutter."); |
| 204 this.codeMirror().setGutterMarker(lineNumber, type, element); | 204 this.codeMirror().setGutterMarker(lineNumber, type, element); |
| 205 }, | 205 }, |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * @param {number} lineNumber | 208 * @param {number} lineNumber |
| 209 * @param {number} columnNumber | 209 * @param {number} columnNumber |
| 210 */ | 210 */ |
| 211 setExecutionLocation: function(lineNumber, columnNumber) | 211 setExecutionLocation: function(lineNumber, columnNumber) |
| 212 { | 212 { |
| 213 this.clearPositionHighlight(); | 213 this.clearPositionHighlight(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 this.codeMirror().setOption("indentUnit", 4); | 336 this.codeMirror().setOption("indentUnit", 4); |
| 337 } else { | 337 } else { |
| 338 this.codeMirror().setOption("indentWithTabs", false); | 338 this.codeMirror().setOption("indentWithTabs", false); |
| 339 this.codeMirror().setOption("indentUnit", indent.length); | 339 this.codeMirror().setOption("indentUnit", indent.length); |
| 340 extraKeys.Tab = function(codeMirror) | 340 extraKeys.Tab = function(codeMirror) |
| 341 { | 341 { |
| 342 if (codeMirror.somethingSelected()) | 342 if (codeMirror.somethingSelected()) |
| 343 return CodeMirror.Pass; | 343 return CodeMirror.Pass; |
| 344 var pos = codeMirror.getCursor("head"); | 344 var pos = codeMirror.getCursor("head"); |
| 345 codeMirror.replaceRange(indent.substring(pos.ch % indent.length)
, codeMirror.getCursor()); | 345 codeMirror.replaceRange(indent.substring(pos.ch % indent.length)
, codeMirror.getCursor()); |
| 346 } | 346 }; |
| 347 } | 347 } |
| 348 | 348 |
| 349 this.codeMirror().setOption("extraKeys", extraKeys); | 349 this.codeMirror().setOption("extraKeys", extraKeys); |
| 350 this._indentationLevel = indent; | 350 this._indentationLevel = indent; |
| 351 }, | 351 }, |
| 352 | 352 |
| 353 /** | 353 /** |
| 354 * @return {string} | 354 * @return {string} |
| 355 */ | 355 */ |
| 356 indent: function() | 356 indent: function() |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 spaceChars += spaceChar; | 598 spaceChars += spaceChar; |
| 599 var rule = classBase + i + "::before { content: '" + spaceChars + "'
;}\n"; | 599 var rule = classBase + i + "::before { content: '" + spaceChars + "'
;}\n"; |
| 600 rules += rule; | 600 rules += rule; |
| 601 } | 601 } |
| 602 var style = doc.createElement("style"); | 602 var style = doc.createElement("style"); |
| 603 style.textContent = rules; | 603 style.textContent = rules; |
| 604 doc.head.appendChild(style); | 604 doc.head.appendChild(style); |
| 605 }, | 605 }, |
| 606 | 606 |
| 607 __proto__: WebInspector.CodeMirrorTextEditor.prototype | 607 __proto__: WebInspector.CodeMirrorTextEditor.prototype |
| 608 } | 608 }; |
| 609 | 609 |
| 610 /** @typedef {{lineNumber: number, event: !Event}} */ | 610 /** @typedef {{lineNumber: number, event: !Event}} */ |
| 611 WebInspector.SourcesTextEditor.GutterClickEventData; | 611 WebInspector.SourcesTextEditor.GutterClickEventData; |
| 612 | 612 |
| 613 /** @enum {symbol} */ | 613 /** @enum {symbol} */ |
| 614 WebInspector.SourcesTextEditor.Events = { | 614 WebInspector.SourcesTextEditor.Events = { |
| 615 GutterClick: Symbol("GutterClick"), | 615 GutterClick: Symbol("GutterClick"), |
| 616 TextChanged: Symbol("TextChanged"), | 616 TextChanged: Symbol("TextChanged"), |
| 617 SelectionChanged: Symbol("SelectionChanged"), | 617 SelectionChanged: Symbol("SelectionChanged"), |
| 618 ScrollChanged: Symbol("ScrollChanged"), | 618 ScrollChanged: Symbol("ScrollChanged"), |
| 619 EditorFocused: Symbol("EditorFocused"), | 619 EditorFocused: Symbol("EditorFocused"), |
| 620 EditorBlurred: Symbol("EditorBlurred"), | 620 EditorBlurred: Symbol("EditorBlurred"), |
| 621 JumpHappened: Symbol("JumpHappened") | 621 JumpHappened: Symbol("JumpHappened") |
| 622 } | 622 }; |
| 623 | 623 |
| 624 /** | 624 /** |
| 625 * @interface | 625 * @interface |
| 626 */ | 626 */ |
| 627 WebInspector.SourcesTextEditorDelegate = function() { } | 627 WebInspector.SourcesTextEditorDelegate = function() { }; |
| 628 WebInspector.SourcesTextEditorDelegate.prototype = { | 628 WebInspector.SourcesTextEditorDelegate.prototype = { |
| 629 /** | 629 /** |
| 630 * @param {!WebInspector.ContextMenu} contextMenu | 630 * @param {!WebInspector.ContextMenu} contextMenu |
| 631 * @param {number} lineNumber | 631 * @param {number} lineNumber |
| 632 * @return {!Promise} | 632 * @return {!Promise} |
| 633 */ | 633 */ |
| 634 populateLineGutterContextMenu: function(contextMenu, lineNumber) { }, | 634 populateLineGutterContextMenu: function(contextMenu, lineNumber) { }, |
| 635 | 635 |
| 636 /** | 636 /** |
| 637 * @param {!WebInspector.ContextMenu} contextMenu | 637 * @param {!WebInspector.ContextMenu} contextMenu |
| 638 * @param {number} lineNumber | 638 * @param {number} lineNumber |
| 639 * @param {number} columnNumber | 639 * @param {number} columnNumber |
| 640 * @return {!Promise} | 640 * @return {!Promise} |
| 641 */ | 641 */ |
| 642 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber)
{ }, | 642 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber)
{ }, |
| 643 } | 643 }; |
| 644 | 644 |
| 645 /** | 645 /** |
| 646 * @param {!CodeMirror} codeMirror | 646 * @param {!CodeMirror} codeMirror |
| 647 */ | 647 */ |
| 648 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) | 648 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) |
| 649 { | 649 { |
| 650 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); | 650 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); |
| 651 function innerSmartNewlineAndIndent(codeMirror) | 651 function innerSmartNewlineAndIndent(codeMirror) |
| 652 { | 652 { |
| 653 var selections = codeMirror.listSelections(); | 653 var selections = codeMirror.listSelections(); |
| 654 var replacements = []; | 654 var replacements = []; |
| 655 for (var i = 0; i < selections.length; ++i) { | 655 for (var i = 0; i < selections.length; ++i) { |
| 656 var selection = selections[i]; | 656 var selection = selections[i]; |
| 657 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ?
selection.head : selection.anchor; | 657 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ?
selection.head : selection.anchor; |
| 658 var line = codeMirror.getLine(cur.line); | 658 var line = codeMirror.getLine(cur.line); |
| 659 var indent = WebInspector.TextUtils.lineIndent(line); | 659 var indent = WebInspector.TextUtils.lineIndent(line); |
| 660 replacements.push("\n" + indent.substring(0, Math.min(cur.ch, indent
.length))); | 660 replacements.push("\n" + indent.substring(0, Math.min(cur.ch, indent
.length))); |
| 661 } | 661 } |
| 662 codeMirror.replaceSelections(replacements); | 662 codeMirror.replaceSelections(replacements); |
| 663 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); | 663 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); |
| 664 } | 664 } |
| 665 } | 665 }; |
| 666 | 666 |
| 667 /** | 667 /** |
| 668 * @return {!Object|undefined} | 668 * @return {!Object|undefined} |
| 669 */ | 669 */ |
| 670 CodeMirror.commands.sourcesDismiss = function(codemirror) | 670 CodeMirror.commands.sourcesDismiss = function(codemirror) |
| 671 { | 671 { |
| 672 if (codemirror.listSelections().length === 1 && codemirror._codeMirrorTextEd
itor._isSearchActive()) | 672 if (codemirror.listSelections().length === 1 && codemirror._codeMirrorTextEd
itor._isSearchActive()) |
| 673 return CodeMirror.Pass; | 673 return CodeMirror.Pass; |
| 674 return CodeMirror.commands.dismiss(codemirror); | 674 return CodeMirror.commands.dismiss(codemirror); |
| 675 } | 675 }; |
| 676 | 676 |
| 677 /** | 677 /** |
| 678 * @constructor | 678 * @constructor |
| 679 * @param {!CodeMirror} codeMirror | 679 * @param {!CodeMirror} codeMirror |
| 680 */ | 680 */ |
| 681 WebInspector.SourcesTextEditor.BlockIndentController = function(codeMirror) | 681 WebInspector.SourcesTextEditor.BlockIndentController = function(codeMirror) |
| 682 { | 682 { |
| 683 codeMirror.addKeyMap(this); | 683 codeMirror.addKeyMap(this); |
| 684 } | 684 }; |
| 685 | 685 |
| 686 WebInspector.SourcesTextEditor.BlockIndentController.prototype = { | 686 WebInspector.SourcesTextEditor.BlockIndentController.prototype = { |
| 687 name: "blockIndentKeymap", | 687 name: "blockIndentKeymap", |
| 688 | 688 |
| 689 /** | 689 /** |
| 690 * @return {*} | 690 * @return {*} |
| 691 */ | 691 */ |
| 692 Enter: function(codeMirror) | 692 Enter: function(codeMirror) |
| 693 { | 693 { |
| 694 var selections = codeMirror.listSelections(); | 694 var selections = codeMirror.listSelections(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 head: selection.head, | 763 head: selection.head, |
| 764 anchor: new CodeMirror.Pos(selection.head.line, 0) | 764 anchor: new CodeMirror.Pos(selection.head.line, 0) |
| 765 }); | 765 }); |
| 766 var line = codeMirror.getLine(matchingBracket.to.line); | 766 var line = codeMirror.getLine(matchingBracket.to.line); |
| 767 var indent = WebInspector.TextUtils.lineIndent(line); | 767 var indent = WebInspector.TextUtils.lineIndent(line); |
| 768 replacements.push(indent + "}"); | 768 replacements.push(indent + "}"); |
| 769 } | 769 } |
| 770 codeMirror.setSelections(updatedSelections); | 770 codeMirror.setSelections(updatedSelections); |
| 771 codeMirror.replaceSelections(replacements); | 771 codeMirror.replaceSelections(replacements); |
| 772 } | 772 } |
| 773 } | 773 }; |
| 774 | 774 |
| 775 /** | 775 /** |
| 776 * @param {!Array.<string>} lines | 776 * @param {!Array.<string>} lines |
| 777 * @return {string} | 777 * @return {string} |
| 778 */ | 778 */ |
| 779 WebInspector.SourcesTextEditor._guessIndentationLevel = function(lines) | 779 WebInspector.SourcesTextEditor._guessIndentationLevel = function(lines) |
| 780 { | 780 { |
| 781 var tabRegex = /^\t+/; | 781 var tabRegex = /^\t+/; |
| 782 var tabLines = 0; | 782 var tabLines = 0; |
| 783 var indents = {}; | 783 var indents = {}; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 803 for (var i in indents) { | 803 for (var i in indents) { |
| 804 if (indents[i] < linesCountPerIndentThreshold) | 804 if (indents[i] < linesCountPerIndentThreshold) |
| 805 continue; | 805 continue; |
| 806 var indent = parseInt(i, 10); | 806 var indent = parseInt(i, 10); |
| 807 if (minimumIndent > indent) | 807 if (minimumIndent > indent) |
| 808 minimumIndent = indent; | 808 minimumIndent = indent; |
| 809 } | 809 } |
| 810 if (minimumIndent === Infinity) | 810 if (minimumIndent === Infinity) |
| 811 return WebInspector.moduleSetting("textEditorIndent").get(); | 811 return WebInspector.moduleSetting("textEditorIndent").get(); |
| 812 return " ".repeat(minimumIndent); | 812 return " ".repeat(minimumIndent); |
| 813 } | 813 }; |
| 814 | 814 |
| 815 /** | 815 /** |
| 816 * @constructor | 816 * @constructor |
| 817 * @param {!WebInspector.SourcesTextEditor} textEditor | 817 * @param {!WebInspector.SourcesTextEditor} textEditor |
| 818 * @param {!CodeMirror} codeMirror | 818 * @param {!CodeMirror} codeMirror |
| 819 */ | 819 */ |
| 820 WebInspector.SourcesTextEditor.TokenHighlighter = function(textEditor, codeMirro
r) | 820 WebInspector.SourcesTextEditor.TokenHighlighter = function(textEditor, codeMirro
r) |
| 821 { | 821 { |
| 822 this._textEditor = textEditor; | 822 this._textEditor = textEditor; |
| 823 this._codeMirror = codeMirror; | 823 this._codeMirror = codeMirror; |
| 824 } | 824 }; |
| 825 | 825 |
| 826 WebInspector.SourcesTextEditor.TokenHighlighter.prototype = { | 826 WebInspector.SourcesTextEditor.TokenHighlighter.prototype = { |
| 827 /** | 827 /** |
| 828 * @param {!RegExp} regex | 828 * @param {!RegExp} regex |
| 829 * @param {?WebInspector.TextRange} range | 829 * @param {?WebInspector.TextRange} range |
| 830 */ | 830 */ |
| 831 highlightSearchResults: function(regex, range) | 831 highlightSearchResults: function(regex, range) |
| 832 { | 832 { |
| 833 var oldRegex = this._highlightRegex; | 833 var oldRegex = this._highlightRegex; |
| 834 this._highlightRegex = regex; | 834 this._highlightRegex = regex; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 { | 966 { |
| 967 var overlayMode = { | 967 var overlayMode = { |
| 968 token: highlighter | 968 token: highlighter |
| 969 }; | 969 }; |
| 970 this._codeMirror.addOverlay(overlayMode); | 970 this._codeMirror.addOverlay(overlayMode); |
| 971 this._highlightDescriptor = { | 971 this._highlightDescriptor = { |
| 972 overlay: overlayMode, | 972 overlay: overlayMode, |
| 973 selectionStart: selectionStart | 973 selectionStart: selectionStart |
| 974 }; | 974 }; |
| 975 } | 975 } |
| 976 } | 976 }; |
| 977 | 977 |
| 978 WebInspector.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; | 978 WebInspector.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; |
| 979 WebInspector.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 979 WebInspector.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| OLD | NEW |