Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/source_frame/SourcesTextEditor.js

Issue 2565113002: DevTools: update console viewport scroll when prompt is resized (Closed)
Patch Set: rebaseline Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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));
24 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this)); 23 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this));
25 this.codeMirror().on('gutterClick', this._gutterClick.bind(this)); 24 this.codeMirror().on('gutterClick', this._gutterClick.bind(this));
26 this.codeMirror().on('scroll', this._scroll.bind(this)); 25 this.codeMirror().on('scroll', this._scroll.bind(this));
27 this.codeMirror().on('focus', this._focus.bind(this)); 26 this.codeMirror().on('focus', this._focus.bind(this));
28 this.codeMirror().on('blur', this._blur.bind(this)); 27 this.codeMirror().on('blur', this._blur.bind(this));
29 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this)); 28 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this));
30 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse); 29 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse);
31 30
32 this.codeMirror().addKeyMap(SourceFrame.SourcesTextEditor._BlockIndentContro ller); 31 this.codeMirror().addKeyMap(SourceFrame.SourcesTextEditor._BlockIndentContro ller);
33 this._tokenHighlighter = new SourceFrame.SourcesTextEditor.TokenHighlighter( this, this.codeMirror()); 32 this._tokenHighlighter = new SourceFrame.SourcesTextEditor.TokenHighlighter( this, this.codeMirror());
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 298
300 /** 299 /**
301 * @override 300 * @override
302 * @param {!TextUtils.TextRange} range 301 * @param {!TextUtils.TextRange} range
303 * @param {string} text 302 * @param {string} text
304 * @param {string=} origin 303 * @param {string=} origin
305 * @return {!TextUtils.TextRange} 304 * @return {!TextUtils.TextRange}
306 */ 305 */
307 editRange(range, text, origin) { 306 editRange(range, text, origin) {
308 var newRange = super.editRange(range, text, origin); 307 var newRange = super.editRange(range, text, origin);
309 this.dispatchEventToListeners(
310 SourceFrame.SourcesTextEditor.Events.TextChanged, {oldRange: range, newR ange: newRange});
311
312 if (Common.moduleSetting('textEditorAutoDetectIndent').get()) 308 if (Common.moduleSetting('textEditorAutoDetectIndent').get())
313 this._onUpdateEditorIndentation(); 309 this._onUpdateEditorIndentation();
314 310
315 return newRange; 311 return newRange;
316 } 312 }
317 313
318 _onUpdateEditorIndentation() { 314 _onUpdateEditorIndentation() {
319 this._setEditorIndentation(TextEditor.CodeMirrorUtils.pullLines( 315 this._setEditorIndentation(TextEditor.CodeMirrorUtils.pullLines(
320 this.codeMirror(), SourceFrame.SourcesTextEditor.LinesToScanForIndentati onGuessing)); 316 this.codeMirror(), SourceFrame.SourcesTextEditor.LinesToScanForIndentati onGuessing));
321 } 317 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 366 }
371 367
372 this._autoAppendedSpaces = []; 368 this._autoAppendedSpaces = [];
373 var selections = this.selections(); 369 var selections = this.selections();
374 for (var i = 0; i < selections.length; ++i) { 370 for (var i = 0; i < selections.length; ++i) {
375 var selection = selections[i]; 371 var selection = selections[i];
376 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn)); 372 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn));
377 } 373 }
378 } 374 }
379 375
380 /**
381 * @param {!CodeMirror} codeMirror
382 * @param {!Array.<!CodeMirror.ChangeObject>} changes
383 */
384 _fireTextChanged(codeMirror, changes) {
385 if (!changes.length || this._muteTextChangedEvent)
386 return;
387 var edits = [];
388 var currentEdit;
389
390 for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) {
391 var changeObject = changes[changeIndex];
392 var edit = TextEditor.CodeMirrorUtils.changeObjectToEditOperation(changeOb ject);
393 if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) {
394 currentEdit.newRange = edit.newRange;
395 } else {
396 currentEdit = edit;
397 edits.push(currentEdit);
398 }
399 }
400
401 for (var i = 0; i < edits.length; ++i)
402 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.TextCha nged, edits[i]);
403 }
404
405 _cursorActivity() { 376 _cursorActivity() {
406 if (!this._isSearchActive()) 377 if (!this._isSearchActive())
407 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter)); 378 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter));
408 379
409 var start = this.codeMirror().getCursor('anchor'); 380 var start = this.codeMirror().getCursor('anchor');
410 var end = this.codeMirror().getCursor('head'); 381 var end = this.codeMirror().getCursor('head');
411 this.dispatchEventToListeners( 382 this.dispatchEventToListeners(
412 SourceFrame.SourcesTextEditor.Events.SelectionChanged, TextEditor.CodeMi rrorUtils.toRange(start, end)); 383 SourceFrame.SourcesTextEditor.Events.SelectionChanged, TextEditor.CodeMi rrorUtils.toRange(start, end));
413 } 384 }
414 385
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 Common.moduleSetting('textEditorIndent').removeChangeListener(this._onUpdate EditorIndentation, this); 429 Common.moduleSetting('textEditorIndent').removeChangeListener(this._onUpdate EditorIndentation, this);
459 Common.moduleSetting('textEditorAutoDetectIndent').removeChangeListener(this ._onUpdateEditorIndentation, this); 430 Common.moduleSetting('textEditorAutoDetectIndent').removeChangeListener(this ._onUpdateEditorIndentation, this);
460 Common.moduleSetting('showWhitespacesInEditor').removeChangeListener(this._u pdateWhitespace, this); 431 Common.moduleSetting('showWhitespacesInEditor').removeChangeListener(this._u pdateWhitespace, this);
461 } 432 }
462 433
463 /** 434 /**
464 * @override 435 * @override
465 * @param {string} text 436 * @param {string} text
466 */ 437 */
467 setText(text) { 438 setText(text) {
468 this._muteTextChangedEvent = true;
469 this._setEditorIndentation( 439 this._setEditorIndentation(
470 text.split('\n').slice(0, SourceFrame.SourcesTextEditor.LinesToScanForIn dentationGuessing)); 440 text.split('\n').slice(0, SourceFrame.SourcesTextEditor.LinesToScanForIn dentationGuessing));
471 super.setText(text); 441 super.setText(text);
472 delete this._muteTextChangedEvent;
473 } 442 }
474 443
475 _updateWhitespace() { 444 _updateWhitespace() {
476 this.setMimeType(this.mimeType()); 445 this.setMimeType(this.mimeType());
477 } 446 }
478 447
479 /** 448 /**
480 * @override 449 * @override
481 * @param {string} mimeType 450 * @param {string} mimeType
482 * @return {string} 451 * @return {string}
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 doc.head.appendChild(style); 544 doc.head.appendChild(style);
576 } 545 }
577 }; 546 };
578 547
579 /** @typedef {{lineNumber: number, event: !Event}} */ 548 /** @typedef {{lineNumber: number, event: !Event}} */
580 SourceFrame.SourcesTextEditor.GutterClickEventData; 549 SourceFrame.SourcesTextEditor.GutterClickEventData;
581 550
582 /** @enum {symbol} */ 551 /** @enum {symbol} */
583 SourceFrame.SourcesTextEditor.Events = { 552 SourceFrame.SourcesTextEditor.Events = {
584 GutterClick: Symbol('GutterClick'), 553 GutterClick: Symbol('GutterClick'),
585 TextChanged: Symbol('TextChanged'),
586 SelectionChanged: Symbol('SelectionChanged'), 554 SelectionChanged: Symbol('SelectionChanged'),
587 ScrollChanged: Symbol('ScrollChanged'), 555 ScrollChanged: Symbol('ScrollChanged'),
588 EditorFocused: Symbol('EditorFocused'), 556 EditorFocused: Symbol('EditorFocused'),
589 EditorBlurred: Symbol('EditorBlurred'), 557 EditorBlurred: Symbol('EditorBlurred'),
590 JumpHappened: Symbol('JumpHappened') 558 JumpHappened: Symbol('JumpHappened')
591 }; 559 };
592 560
593 /** 561 /**
594 * @interface 562 * @interface
595 */ 563 */
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 */ 839 */
872 _setHighlighter(highlighter, selectionStart) { 840 _setHighlighter(highlighter, selectionStart) {
873 var overlayMode = {token: highlighter}; 841 var overlayMode = {token: highlighter};
874 this._codeMirror.addOverlay(overlayMode); 842 this._codeMirror.addOverlay(overlayMode);
875 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start}; 843 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start};
876 } 844 }
877 }; 845 };
878 846
879 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; 847 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000;
880 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; 848 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698