Chromium Code Reviews| 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 */ |
| 11 constructor(delegate) { | 11 constructor(delegate) { |
| 12 super({ | 12 super({ |
| 13 lineNumbers: true, | 13 lineNumbers: true, |
| 14 lineWrapping: false, | 14 lineWrapping: false, |
| 15 bracketMatchingSetting: Common.moduleSetting('textEditorBracketMatching'), | 15 bracketMatchingSetting: Common.moduleSetting('textEditorBracketMatching'), |
| 16 padBottom: true | 16 padBottom: true |
| 17 }); | 17 }); |
| 18 | 18 |
| 19 this.codeMirror().addKeyMap({'Enter': 'smartNewlineAndIndent', 'Esc': 'sourc esDismiss'}); | 19 this.codeMirror().addKeyMap({'Enter': 'smartNewlineAndIndent', 'Esc': 'sourc esDismiss'}); |
| 20 | 20 |
| 21 this._delegate = delegate; | 21 this._delegate = delegate; |
| 22 | 22 |
| 23 this.codeMirror().on('changes', this._fireTextChanged.bind(this)); | 23 this.on(UI.TextEditor.ContentChangedEvent, this._fireTextChanged, this); |
| 24 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this)); | 24 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this)); |
| 25 this.codeMirror().on('gutterClick', this._gutterClick.bind(this)); | 25 this.codeMirror().on('gutterClick', this._gutterClick.bind(this)); |
| 26 this.codeMirror().on('scroll', this._scroll.bind(this)); | 26 this.codeMirror().on('scroll', this._scroll.bind(this)); |
| 27 this.codeMirror().on('focus', this._focus.bind(this)); | 27 this.codeMirror().on('focus', this._focus.bind(this)); |
| 28 this.codeMirror().on('blur', this._blur.bind(this)); | 28 this.codeMirror().on('blur', this._blur.bind(this)); |
| 29 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this)); | 29 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this)); |
| 30 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse); | 30 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse); |
| 31 | 31 |
| 32 this.codeMirror().addKeyMap(SourceFrame.SourcesTextEditor._BlockIndentContro ller); | 32 this.codeMirror().addKeyMap(SourceFrame.SourcesTextEditor._BlockIndentContro ller); |
| 33 this._tokenHighlighter = new SourceFrame.SourcesTextEditor.TokenHighlighter( this, this.codeMirror()); | 33 this._tokenHighlighter = new SourceFrame.SourcesTextEditor.TokenHighlighter( this, this.codeMirror()); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 371 |
| 372 this._autoAppendedSpaces = []; | 372 this._autoAppendedSpaces = []; |
| 373 var selections = this.selections(); | 373 var selections = this.selections(); |
| 374 for (var i = 0; i < selections.length; ++i) { | 374 for (var i = 0; i < selections.length; ++i) { |
| 375 var selection = selections[i]; | 375 var selection = selections[i]; |
| 376 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn)); | 376 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn)); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 /** | 380 /** |
| 381 * @param {!CodeMirror} codeMirror | 381 * @param {!UI.TextEditor.ContentChangedEvent} event |
| 382 * @param {!Array.<!CodeMirror.ChangeObject>} changes | |
| 383 */ | 382 */ |
| 384 _fireTextChanged(codeMirror, changes) { | 383 _fireTextChanged(event) { |
| 385 if (!changes.length || this._muteTextChangedEvent) | 384 if (this._muteTextChangedEvent) |
| 386 return; | 385 return; |
| 386 var changes = event.changes; | |
| 387 var edits = []; | 387 var edits = []; |
| 388 var currentEdit; | 388 var currentEdit; |
| 389 | 389 |
| 390 for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) { | 390 for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) { |
| 391 var changeObject = changes[changeIndex]; | 391 var changeObject = changes[changeIndex]; |
| 392 var edit = TextEditor.CodeMirrorUtils.changeObjectToEditOperation(changeOb ject); | 392 var edit = TextEditor.CodeMirrorUtils.changeObjectToEditOperation(changeOb ject); |
| 393 if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) { | 393 if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) { |
| 394 currentEdit.newRange = edit.newRange; | 394 currentEdit.newRange = edit.newRange; |
| 395 } else { | 395 } else { |
| 396 currentEdit = edit; | 396 currentEdit = edit; |
| 397 edits.push(currentEdit); | 397 edits.push(currentEdit); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 for (var i = 0; i < edits.length; ++i) | 401 for (var i = 0; i < edits.length; ++i) |
| 402 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.TextCha nged, edits[i]); | 402 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.TextCha nged, edits[i]); |
|
lushnikov
2017/03/17 01:33:36
can we move this method up to CMTE?
luoe
2017/03/17 23:44:48
Yes we can!
| |
| 403 } | 403 } |
| 404 | 404 |
| 405 _cursorActivity() { | 405 _cursorActivity() { |
| 406 if (!this._isSearchActive()) | 406 if (!this._isSearchActive()) |
| 407 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter)); | 407 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter)); |
| 408 | 408 |
| 409 var start = this.codeMirror().getCursor('anchor'); | 409 var start = this.codeMirror().getCursor('anchor'); |
| 410 var end = this.codeMirror().getCursor('head'); | 410 var end = this.codeMirror().getCursor('head'); |
| 411 this.dispatchEventToListeners( | 411 this.dispatchEventToListeners( |
| 412 SourceFrame.SourcesTextEditor.Events.SelectionChanged, TextEditor.CodeMi rrorUtils.toRange(start, end)); | 412 SourceFrame.SourcesTextEditor.Events.SelectionChanged, TextEditor.CodeMi rrorUtils.toRange(start, end)); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 */ | 871 */ |
| 872 _setHighlighter(highlighter, selectionStart) { | 872 _setHighlighter(highlighter, selectionStart) { |
| 873 var overlayMode = {token: highlighter}; | 873 var overlayMode = {token: highlighter}; |
| 874 this._codeMirror.addOverlay(overlayMode); | 874 this._codeMirror.addOverlay(overlayMode); |
| 875 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start}; | 875 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start}; |
| 876 } | 876 } |
| 877 }; | 877 }; |
| 878 | 878 |
| 879 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; | 879 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; |
| 880 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 880 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| OLD | NEW |