| 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 SourceFrame.SourcesTextEditor = class extends TextEditor.CodeMirrorTextEditor { | 7 SourceFrame.SourcesTextEditor = class extends TextEditor.CodeMirrorTextEditor { |
| 8 /** | 8 /** |
| 9 * @param {!SourceFrame.SourcesTextEditorDelegate} delegate | 9 * @param {!SourceFrame.SourcesTextEditorDelegate} delegate |
| 10 */ | 10 */ |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 * @param {string} text | 495 * @param {string} text |
| 496 */ | 496 */ |
| 497 setText(text) { | 497 setText(text) { |
| 498 this._muteTextChangedEvent = true; | 498 this._muteTextChangedEvent = true; |
| 499 this._setEditorIndentation( | 499 this._setEditorIndentation( |
| 500 text.split('\n').slice(0, SourceFrame.SourcesTextEditor.LinesToScanForIn
dentationGuessing)); | 500 text.split('\n').slice(0, SourceFrame.SourcesTextEditor.LinesToScanForIn
dentationGuessing)); |
| 501 super.setText(text); | 501 super.setText(text); |
| 502 delete this._muteTextChangedEvent; | 502 delete this._muteTextChangedEvent; |
| 503 } | 503 } |
| 504 | 504 |
| 505 _updateWhitespace() { |
| 506 this.setMimeType(this.mimeType()); |
| 507 } |
| 508 |
| 505 /** | 509 /** |
| 506 * @override | 510 * @override |
| 507 * @param {string} mimeType | 511 * @param {string} mimeType |
| 508 * @return {!Promise} | |
| 509 */ | |
| 510 setMimeType(mimeType) { | |
| 511 this._mimeType = mimeType; | |
| 512 return super.setMimeType(mimeType).then( | |
| 513 () => this._codeMirror.setOption('mode', this._applyWhitespaceMimetype(m
imeType))); | |
| 514 } | |
| 515 | |
| 516 _updateWhitespace() { | |
| 517 if (this._mimeType) | |
| 518 this.setMimeType(this._mimeType); | |
| 519 } | |
| 520 | |
| 521 /** | |
| 522 * @param {string} mimeType | |
| 523 * @return {string} | 512 * @return {string} |
| 524 */ | 513 */ |
| 525 _applyWhitespaceMimetype(mimeType) { | 514 rewriteMimeType(mimeType) { |
| 526 this._setupWhitespaceHighlight(); | 515 this._setupWhitespaceHighlight(); |
| 527 var whitespaceMode = Common.moduleSetting('showWhitespacesInEditor').get(); | 516 var whitespaceMode = Common.moduleSetting('showWhitespacesInEditor').get(); |
| 528 this.element.classList.toggle('show-whitespaces', whitespaceMode === 'all'); | 517 this.element.classList.toggle('show-whitespaces', whitespaceMode === 'all'); |
| 529 | 518 |
| 530 if (whitespaceMode === 'all') | 519 if (whitespaceMode === 'all') |
| 531 return this._allWhitespaceOverlayMode(mimeType); | 520 return this._allWhitespaceOverlayMode(mimeType); |
| 532 else if (whitespaceMode === 'trailing') | 521 else if (whitespaceMode === 'trailing') |
| 533 return this._trailingWhitespaceOverlayMode(mimeType); | 522 return this._trailingWhitespaceOverlayMode(mimeType); |
| 534 | 523 |
| 535 return mimeType; | 524 return mimeType; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 */ | 902 */ |
| 914 _setHighlighter(highlighter, selectionStart) { | 903 _setHighlighter(highlighter, selectionStart) { |
| 915 var overlayMode = {token: highlighter}; | 904 var overlayMode = {token: highlighter}; |
| 916 this._codeMirror.addOverlay(overlayMode); | 905 this._codeMirror.addOverlay(overlayMode); |
| 917 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection
Start}; | 906 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection
Start}; |
| 918 } | 907 } |
| 919 }; | 908 }; |
| 920 | 909 |
| 921 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; | 910 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; |
| 922 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 911 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| OLD | NEW |