Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 this._textEditor = new SourceFrame.SourcesTextEditor(this); | 47 this._textEditor = new SourceFrame.SourcesTextEditor(this); |
| 48 | 48 |
| 49 this._currentSearchResultIndex = -1; | 49 this._currentSearchResultIndex = -1; |
| 50 this._searchResults = []; | 50 this._searchResults = []; |
| 51 | 51 |
| 52 this._textEditor.addEventListener( | 52 this._textEditor.addEventListener( |
| 53 SourceFrame.SourcesTextEditor.Events.EditorFocused, this._resetCurrentSe archResultIndex, this); | 53 SourceFrame.SourcesTextEditor.Events.EditorFocused, this._resetCurrentSe archResultIndex, this); |
| 54 this._textEditor.addEventListener( | 54 this._textEditor.addEventListener( |
| 55 SourceFrame.SourcesTextEditor.Events.SelectionChanged, this._updateSourc ePosition, this); | 55 SourceFrame.SourcesTextEditor.Events.SelectionChanged, this._updateSourc ePosition, this); |
| 56 this._textEditor.addEventListener( | 56 this._textEditor.on(UI.TextEditor.TextChangedEvent, event => { |
| 57 SourceFrame.SourcesTextEditor.Events.TextChanged, | 57 if (!this._muteChangeEventsForSetContent) |
| 58 event => this.onTextChanged(event.data.oldRange, event.data.newRange)); | 58 this.onTextChanged(event.oldRange, event.newRange); |
| 59 }); | |
| 60 /** @type {boolean|undefined} */ | |
| 61 this._muteChangeEventsForSetContent; | |
|
luoe
2017/03/31 02:18:08
AFAICT, the reason why we had muteTextChangedEvent
pfeldman
2017/04/04 20:21:09
Makes sense to me.
| |
| 59 | 62 |
| 60 this._shortcuts = {}; | 63 this._shortcuts = {}; |
| 61 this.element.addEventListener('keydown', this._handleKeyDown.bind(this), fal se); | 64 this.element.addEventListener('keydown', this._handleKeyDown.bind(this), fal se); |
| 62 | 65 |
| 63 this._sourcePosition = new UI.ToolbarText(); | 66 this._sourcePosition = new UI.ToolbarText(); |
| 64 | 67 |
| 65 /** | 68 /** |
| 66 * @type {?UI.SearchableView} | 69 * @type {?UI.SearchableView} |
| 67 */ | 70 */ |
| 68 this._searchableView = null; | 71 this._searchableView = null; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 * @param {string} content | 260 * @param {string} content |
| 258 */ | 261 */ |
| 259 _updateHighlighterType(content) { | 262 _updateHighlighterType(content) { |
| 260 this._textEditor.setMimeType(this._simplifyMimeType(content, this._highlight erType)); | 263 this._textEditor.setMimeType(this._simplifyMimeType(content, this._highlight erType)); |
| 261 } | 264 } |
| 262 | 265 |
| 263 /** | 266 /** |
| 264 * @param {?string} content | 267 * @param {?string} content |
| 265 */ | 268 */ |
| 266 setContent(content) { | 269 setContent(content) { |
| 270 this._muteChangeEventsForSetContent = true; | |
| 267 if (!this._loaded) { | 271 if (!this._loaded) { |
| 268 this._loaded = true; | 272 this._loaded = true; |
| 269 this._textEditor.setText(content || ''); | 273 this._textEditor.setText(content || ''); |
| 270 this._textEditor.markClean(); | 274 this._textEditor.markClean(); |
| 271 this._textEditor.setReadOnly(!this._editable); | 275 this._textEditor.setReadOnly(!this._editable); |
| 272 } else { | 276 } else { |
| 273 var scrollTop = this._textEditor.scrollTop(); | 277 var scrollTop = this._textEditor.scrollTop(); |
| 274 var selection = this._textEditor.selection(); | 278 var selection = this._textEditor.selection(); |
| 275 this._textEditor.setText(content || ''); | 279 this._textEditor.setText(content || ''); |
| 276 this._textEditor.setScrollTop(scrollTop); | 280 this._textEditor.setScrollTop(scrollTop); |
| 277 this._textEditor.setSelection(selection); | 281 this._textEditor.setSelection(selection); |
| 278 } | 282 } |
| 279 | 283 |
| 280 this._updateHighlighterType(content || ''); | 284 this._updateHighlighterType(content || ''); |
| 281 this._wasShownOrLoaded(); | 285 this._wasShownOrLoaded(); |
| 282 | 286 |
| 283 if (this._delayedFindSearchMatches) { | 287 if (this._delayedFindSearchMatches) { |
| 284 this._delayedFindSearchMatches(); | 288 this._delayedFindSearchMatches(); |
| 285 delete this._delayedFindSearchMatches; | 289 delete this._delayedFindSearchMatches; |
| 286 } | 290 } |
| 291 delete this._muteChangeEventsForSetContent; | |
| 287 this.onTextEditorContentSet(); | 292 this.onTextEditorContentSet(); |
| 288 } | 293 } |
| 289 | 294 |
| 290 onTextEditorContentSet() { | 295 onTextEditorContentSet() { |
| 291 } | 296 } |
| 292 | 297 |
| 293 /** | 298 /** |
| 294 * @param {?UI.SearchableView} view | 299 * @param {?UI.SearchableView} view |
| 295 */ | 300 */ |
| 296 setSearchableView(view) { | 301 setSearchableView(view) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 } | 581 } |
| 577 } | 582 } |
| 578 | 583 |
| 579 _handleKeyDown(e) { | 584 _handleKeyDown(e) { |
| 580 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(e); | 585 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(e); |
| 581 var handler = this._shortcuts[shortcutKey]; | 586 var handler = this._shortcuts[shortcutKey]; |
| 582 if (handler && handler()) | 587 if (handler && handler()) |
| 583 e.consume(true); | 588 e.consume(true); |
| 584 } | 589 } |
| 585 }; | 590 }; |
| OLD | NEW |