| 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) |
| 11 { | 11 { |
| 12 WebInspector.CodeMirrorTextEditor.call(this); | 12 WebInspector.CodeMirrorTextEditor.call(this); |
| 13 | 13 |
| 14 this.codeMirror().addKeyMap({ | 14 this.codeMirror().addKeyMap({ |
| 15 "Enter": "smartNewlineAndIndent", | 15 "Enter": "smartNewlineAndIndent", |
| 16 "Esc": "sourcesDismiss" | 16 "Esc": "sourcesDismiss" |
| 17 }); | 17 }); |
| 18 | 18 |
| 19 this._delegate = delegate; | 19 this._delegate = delegate; |
| 20 | 20 |
| 21 this.codeMirror().on("changes", this._changesForDelegate.bind(this)); | 21 this.codeMirror().on("changes", this._changesForDelegate.bind(this)); |
| 22 this.codeMirror().on("cursorActivity", this._cursorActivity.bind(this)); | 22 this.codeMirror().on("cursorActivity", this._cursorActivity.bind(this)); |
| 23 this.codeMirror().on("gutterClick", this._gutterClick.bind(this)); | 23 this.codeMirror().on("gutterClick", this._gutterClick.bind(this)); |
| 24 this.codeMirror().on("scroll", this._scroll.bind(this)); | 24 this.codeMirror().on("scroll", this._scroll.bind(this)); |
| 25 this.codeMirror().on("focus", this._focus.bind(this)); | 25 this.codeMirror().on("focus", this._focus.bind(this)); |
| 26 this.codeMirror().on("blur", this._blur.bind(this)); |
| 26 this.codeMirror().on("beforeSelectionChange", this._beforeSelectionChangeFor
Delegate.bind(this)); | 27 this.codeMirror().on("beforeSelectionChange", this._beforeSelectionChangeFor
Delegate.bind(this)); |
| 27 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f
alse); | 28 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f
alse); |
| 28 | 29 |
| 29 this._blockIndentController = new WebInspector.SourcesTextEditor.BlockIndent
Controller(this.codeMirror()); | 30 this._blockIndentController = new WebInspector.SourcesTextEditor.BlockIndent
Controller(this.codeMirror()); |
| 30 this._tokenHighlighter = new WebInspector.SourcesTextEditor.TokenHighlighter
(this, this.codeMirror()); | 31 this._tokenHighlighter = new WebInspector.SourcesTextEditor.TokenHighlighter
(this, this.codeMirror()); |
| 31 | 32 |
| 32 /** @type {!Array<string>} */ | 33 /** @type {!Array<string>} */ |
| 33 this._gutters = ["CodeMirror-linenumbers"]; | 34 this._gutters = ["CodeMirror-linenumbers"]; |
| 34 | 35 |
| 35 /** | 36 /** |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 { | 421 { |
| 421 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror()
.getScrollInfo().top, "local"); | 422 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror()
.getScrollInfo().top, "local"); |
| 422 this._delegate.scrollChanged(topmostLineNumber); | 423 this._delegate.scrollChanged(topmostLineNumber); |
| 423 }, | 424 }, |
| 424 | 425 |
| 425 _focus: function() | 426 _focus: function() |
| 426 { | 427 { |
| 427 this._delegate.editorFocused(); | 428 this._delegate.editorFocused(); |
| 428 }, | 429 }, |
| 429 | 430 |
| 431 _blur: function() |
| 432 { |
| 433 this._delegate.editorBlurred(); |
| 434 }, |
| 435 |
| 430 /** | 436 /** |
| 431 * @param {!CodeMirror} codeMirror | 437 * @param {!CodeMirror} codeMirror |
| 432 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}
>}} selection | 438 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}
>}} selection |
| 433 */ | 439 */ |
| 434 _beforeSelectionChangeForDelegate: function(codeMirror, selection) | 440 _beforeSelectionChangeForDelegate: function(codeMirror, selection) |
| 435 { | 441 { |
| 436 if (!this._isHandlingMouseDownEvent) | 442 if (!this._isHandlingMouseDownEvent) |
| 437 return; | 443 return; |
| 438 if (!selection.ranges.length) | 444 if (!selection.ranges.length) |
| 439 return; | 445 return; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 */ | 620 */ |
| 615 selectionChanged: function(textRange) { }, | 621 selectionChanged: function(textRange) { }, |
| 616 | 622 |
| 617 /** | 623 /** |
| 618 * @param {number} lineNumber | 624 * @param {number} lineNumber |
| 619 */ | 625 */ |
| 620 scrollChanged: function(lineNumber) { }, | 626 scrollChanged: function(lineNumber) { }, |
| 621 | 627 |
| 622 editorFocused: function() { }, | 628 editorFocused: function() { }, |
| 623 | 629 |
| 630 editorBlurred: function() { }, |
| 631 |
| 624 /** | 632 /** |
| 625 * @param {!WebInspector.ContextMenu} contextMenu | 633 * @param {!WebInspector.ContextMenu} contextMenu |
| 626 * @param {number} lineNumber | 634 * @param {number} lineNumber |
| 627 * @return {!Promise} | 635 * @return {!Promise} |
| 628 */ | 636 */ |
| 629 populateLineGutterContextMenu: function(contextMenu, lineNumber) { }, | 637 populateLineGutterContextMenu: function(contextMenu, lineNumber) { }, |
| 630 | 638 |
| 631 /** | 639 /** |
| 632 * @param {!WebInspector.ContextMenu} contextMenu | 640 * @param {!WebInspector.ContextMenu} contextMenu |
| 633 * @param {number} lineNumber | 641 * @param {number} lineNumber |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 this._codeMirror.addOverlay(overlayMode); | 979 this._codeMirror.addOverlay(overlayMode); |
| 972 this._highlightDescriptor = { | 980 this._highlightDescriptor = { |
| 973 overlay: overlayMode, | 981 overlay: overlayMode, |
| 974 selectionStart: selectionStart | 982 selectionStart: selectionStart |
| 975 }; | 983 }; |
| 976 } | 984 } |
| 977 } | 985 } |
| 978 | 986 |
| 979 WebInspector.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; | 987 WebInspector.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; |
| 980 WebInspector.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 988 WebInspector.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| OLD | NEW |