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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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 WebInspector.SourcesTextEditor = class extends WebInspector.CodeMirrorTextEditor { 7 SourceFrame.SourcesTextEditor = class extends TextEditor.CodeMirrorTextEditor {
8 /** 8 /**
9 * @param {!WebInspector.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: WebInspector.moduleSetting('textEditorBracketMatch ing'), 15 bracketMatchingSetting: Common.moduleSetting('textEditorBracketMatching'),
16 }); 16 });
17 17
18 this.codeMirror().addKeyMap({'Enter': 'smartNewlineAndIndent', 'Esc': 'sourc esDismiss'}); 18 this.codeMirror().addKeyMap({'Enter': 'smartNewlineAndIndent', 'Esc': 'sourc esDismiss'});
19 19
20 this._delegate = delegate; 20 this._delegate = delegate;
21 21
22 this.codeMirror().on('changes', this._fireTextChanged.bind(this)); 22 this.codeMirror().on('changes', this._fireTextChanged.bind(this));
23 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this)); 23 this.codeMirror().on('cursorActivity', this._cursorActivity.bind(this));
24 this.codeMirror().on('gutterClick', this._gutterClick.bind(this)); 24 this.codeMirror().on('gutterClick', this._gutterClick.bind(this));
25 this.codeMirror().on('scroll', this._scroll.bind(this)); 25 this.codeMirror().on('scroll', this._scroll.bind(this));
26 this.codeMirror().on('focus', this._focus.bind(this)); 26 this.codeMirror().on('focus', this._focus.bind(this));
27 this.codeMirror().on('blur', this._blur.bind(this)); 27 this.codeMirror().on('blur', this._blur.bind(this));
28 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this)); 28 this.codeMirror().on('beforeSelectionChange', this._fireBeforeSelectionChang ed.bind(this));
29 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse); 29 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), f alse);
30 30
31 this.codeMirror().addKeyMap(WebInspector.SourcesTextEditor._BlockIndentContr oller); 31 this.codeMirror().addKeyMap(SourceFrame.SourcesTextEditor._BlockIndentContro ller);
32 this._tokenHighlighter = new WebInspector.SourcesTextEditor.TokenHighlighter (this, this.codeMirror()); 32 this._tokenHighlighter = new SourceFrame.SourcesTextEditor.TokenHighlighter( this, this.codeMirror());
33 33
34 /** @type {!Array<string>} */ 34 /** @type {!Array<string>} */
35 this._gutters = ['CodeMirror-linenumbers']; 35 this._gutters = ['CodeMirror-linenumbers'];
36 this.codeMirror().setOption('gutters', this._gutters.slice()); 36 this.codeMirror().setOption('gutters', this._gutters.slice());
37 37
38 this.codeMirror().setOption('electricChars', false); 38 this.codeMirror().setOption('electricChars', false);
39 this.codeMirror().setOption('smartIndent', false); 39 this.codeMirror().setOption('smartIndent', false);
40 40
41 /** 41 /**
42 * @this {WebInspector.SourcesTextEditor} 42 * @this {SourceFrame.SourcesTextEditor}
43 */ 43 */
44 function updateAnticipateJumpFlag(value) { 44 function updateAnticipateJumpFlag(value) {
45 this._isHandlingMouseDownEvent = value; 45 this._isHandlingMouseDownEvent = value;
46 } 46 }
47 47
48 this.element.addEventListener('mousedown', updateAnticipateJumpFlag.bind(thi s, true), true); 48 this.element.addEventListener('mousedown', updateAnticipateJumpFlag.bind(thi s, true), true);
49 this.element.addEventListener('mousedown', updateAnticipateJumpFlag.bind(thi s, false), false); 49 this.element.addEventListener('mousedown', updateAnticipateJumpFlag.bind(thi s, false), false);
50 WebInspector.moduleSetting('textEditorIndent').addChangeListener(this._onUpd ateEditorIndentation, this); 50 Common.moduleSetting('textEditorIndent').addChangeListener(this._onUpdateEdi torIndentation, this);
51 WebInspector.moduleSetting('textEditorAutoDetectIndent').addChangeListener(t his._onUpdateEditorIndentation, this); 51 Common.moduleSetting('textEditorAutoDetectIndent').addChangeListener(this._o nUpdateEditorIndentation, this);
52 WebInspector.moduleSetting('showWhitespacesInEditor').addChangeListener(this ._updateWhitespace, this); 52 Common.moduleSetting('showWhitespacesInEditor').addChangeListener(this._upda teWhitespace, this);
53 53
54 this._onUpdateEditorIndentation(); 54 this._onUpdateEditorIndentation();
55 this._setupWhitespaceHighlight(); 55 this._setupWhitespaceHighlight();
56 } 56 }
57 57
58 /** 58 /**
59 * @param {!Array.<string>} lines 59 * @param {!Array.<string>} lines
60 * @return {string} 60 * @return {string}
61 */ 61 */
62 static _guessIndentationLevel(lines) { 62 static _guessIndentationLevel(lines) {
63 var tabRegex = /^\t+/; 63 var tabRegex = /^\t+/;
64 var tabLines = 0; 64 var tabLines = 0;
65 var indents = {}; 65 var indents = {};
66 for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) { 66 for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) {
67 var text = lines[lineNumber]; 67 var text = lines[lineNumber];
68 if (text.length === 0 || !WebInspector.TextUtils.isSpaceChar(text[0])) 68 if (text.length === 0 || !Common.TextUtils.isSpaceChar(text[0]))
69 continue; 69 continue;
70 if (tabRegex.test(text)) { 70 if (tabRegex.test(text)) {
71 ++tabLines; 71 ++tabLines;
72 continue; 72 continue;
73 } 73 }
74 var i = 0; 74 var i = 0;
75 while (i < text.length && WebInspector.TextUtils.isSpaceChar(text[i])) 75 while (i < text.length && Common.TextUtils.isSpaceChar(text[i]))
76 ++i; 76 ++i;
77 if (i % 2 !== 0) 77 if (i % 2 !== 0)
78 continue; 78 continue;
79 indents[i] = 1 + (indents[i] || 0); 79 indents[i] = 1 + (indents[i] || 0);
80 } 80 }
81 var linesCountPerIndentThreshold = 3 * lines.length / 100; 81 var linesCountPerIndentThreshold = 3 * lines.length / 100;
82 if (tabLines && tabLines > linesCountPerIndentThreshold) 82 if (tabLines && tabLines > linesCountPerIndentThreshold)
83 return '\t'; 83 return '\t';
84 var minimumIndent = Infinity; 84 var minimumIndent = Infinity;
85 for (var i in indents) { 85 for (var i in indents) {
86 if (indents[i] < linesCountPerIndentThreshold) 86 if (indents[i] < linesCountPerIndentThreshold)
87 continue; 87 continue;
88 var indent = parseInt(i, 10); 88 var indent = parseInt(i, 10);
89 if (minimumIndent > indent) 89 if (minimumIndent > indent)
90 minimumIndent = indent; 90 minimumIndent = indent;
91 } 91 }
92 if (minimumIndent === Infinity) 92 if (minimumIndent === Infinity)
93 return WebInspector.moduleSetting('textEditorIndent').get(); 93 return Common.moduleSetting('textEditorIndent').get();
94 return ' '.repeat(minimumIndent); 94 return ' '.repeat(minimumIndent);
95 } 95 }
96 96
97 /** 97 /**
98 * @return {boolean} 98 * @return {boolean}
99 */ 99 */
100 _isSearchActive() { 100 _isSearchActive() {
101 return !!this._tokenHighlighter.highlightedRegex(); 101 return !!this._tokenHighlighter.highlightedRegex();
102 } 102 }
103 103
104 /** 104 /**
105 * @override 105 * @override
106 * @param {number} lineNumber 106 * @param {number} lineNumber
107 */ 107 */
108 scrollToLine(lineNumber) { 108 scrollToLine(lineNumber) {
109 super.scrollToLine(lineNumber); 109 super.scrollToLine(lineNumber);
110 this._scroll(); 110 this._scroll();
111 } 111 }
112 112
113 /** 113 /**
114 * @param {!RegExp} regex 114 * @param {!RegExp} regex
115 * @param {?WebInspector.TextRange} range 115 * @param {?Common.TextRange} range
116 */ 116 */
117 highlightSearchResults(regex, range) { 117 highlightSearchResults(regex, range) {
118 /** 118 /**
119 * @this {WebInspector.CodeMirrorTextEditor} 119 * @this {TextEditor.CodeMirrorTextEditor}
120 */ 120 */
121 function innerHighlightRegex() { 121 function innerHighlightRegex() {
122 if (range) { 122 if (range) {
123 this.scrollLineIntoView(range.startLine); 123 this.scrollLineIntoView(range.startLine);
124 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighlightLeng th) 124 if (range.endColumn > TextEditor.CodeMirrorTextEditor.maxHighlightLength )
125 this.setSelection(range); 125 this.setSelection(range);
126 else 126 else
127 this.setSelection(WebInspector.TextRange.createFromLocation(range.star tLine, range.startColumn)); 127 this.setSelection(Common.TextRange.createFromLocation(range.startLine, range.startColumn));
128 } 128 }
129 this._tokenHighlighter.highlightSearchResults(regex, range); 129 this._tokenHighlighter.highlightSearchResults(regex, range);
130 } 130 }
131 131
132 if (!this._selectionBeforeSearch) 132 if (!this._selectionBeforeSearch)
133 this._selectionBeforeSearch = this.selection(); 133 this._selectionBeforeSearch = this.selection();
134 134
135 this.codeMirror().operation(innerHighlightRegex.bind(this)); 135 this.codeMirror().operation(innerHighlightRegex.bind(this));
136 } 136 }
137 137
138 cancelSearchResultsHighlight() { 138 cancelSearchResultsHighlight() {
139 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens.b ind(this._tokenHighlighter)); 139 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens.b ind(this._tokenHighlighter));
140 140
141 if (this._selectionBeforeSearch) { 141 if (this._selectionBeforeSearch) {
142 this._reportJump(this._selectionBeforeSearch, this.selection()); 142 this._reportJump(this._selectionBeforeSearch, this.selection());
143 delete this._selectionBeforeSearch; 143 delete this._selectionBeforeSearch;
144 } 144 }
145 } 145 }
146 146
147 /** 147 /**
148 * @param {!Object} highlightDescriptor 148 * @param {!Object} highlightDescriptor
149 */ 149 */
150 removeHighlight(highlightDescriptor) { 150 removeHighlight(highlightDescriptor) {
151 highlightDescriptor.clear(); 151 highlightDescriptor.clear();
152 } 152 }
153 153
154 /** 154 /**
155 * @param {!WebInspector.TextRange} range 155 * @param {!Common.TextRange} range
156 * @param {string} cssClass 156 * @param {string} cssClass
157 * @return {!Object} 157 * @return {!Object}
158 */ 158 */
159 highlightRange(range, cssClass) { 159 highlightRange(range, cssClass) {
160 cssClass = 'CodeMirror-persist-highlight ' + cssClass; 160 cssClass = 'CodeMirror-persist-highlight ' + cssClass;
161 var pos = WebInspector.CodeMirrorUtils.toPos(range); 161 var pos = TextEditor.CodeMirrorUtils.toPos(range);
162 ++pos.end.ch; 162 ++pos.end.ch;
163 return this.codeMirror().markText( 163 return this.codeMirror().markText(
164 pos.start, pos.end, {className: cssClass, startStyle: cssClass + '-start ', endStyle: cssClass + '-end'}); 164 pos.start, pos.end, {className: cssClass, startStyle: cssClass + '-start ', endStyle: cssClass + '-end'});
165 } 165 }
166 166
167 /** 167 /**
168 * @param {number} lineNumber 168 * @param {number} lineNumber
169 * @param {boolean} disabled 169 * @param {boolean} disabled
170 * @param {boolean} conditional 170 * @param {boolean} conditional
171 */ 171 */
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 */ 294 */
295 hasLineClass(lineNumber, className) { 295 hasLineClass(lineNumber, className) {
296 var lineInfo = this.codeMirror().lineInfo(lineNumber); 296 var lineInfo = this.codeMirror().lineInfo(lineNumber);
297 var wrapClass = lineInfo.wrapClass || ''; 297 var wrapClass = lineInfo.wrapClass || '';
298 var classNames = wrapClass.split(' '); 298 var classNames = wrapClass.split(' ');
299 return classNames.indexOf(className) !== -1; 299 return classNames.indexOf(className) !== -1;
300 } 300 }
301 301
302 _gutterClick(instance, lineNumber, gutter, event) { 302 _gutterClick(instance, lineNumber, gutter, event) {
303 this.dispatchEventToListeners( 303 this.dispatchEventToListeners(
304 WebInspector.SourcesTextEditor.Events.GutterClick, {lineNumber: lineNumb er, event: event}); 304 SourceFrame.SourcesTextEditor.Events.GutterClick, {lineNumber: lineNumbe r, event: event});
305 } 305 }
306 306
307 _contextMenu(event) { 307 _contextMenu(event) {
308 var contextMenu = new WebInspector.ContextMenu(event); 308 var contextMenu = new UI.ContextMenu(event);
309 event.consume(true); // Consume event now to prevent document from handling the async menu 309 event.consume(true); // Consume event now to prevent document from handling the async menu
310 var target = event.target.enclosingNodeOrSelfWithClass('CodeMirror-gutter-el t'); 310 var target = event.target.enclosingNodeOrSelfWithClass('CodeMirror-gutter-el t');
311 var promise; 311 var promise;
312 if (target) { 312 if (target) {
313 promise = this._delegate.populateLineGutterContextMenu(contextMenu, parseI nt(target.textContent, 10) - 1); 313 promise = this._delegate.populateLineGutterContextMenu(contextMenu, parseI nt(target.textContent, 10) - 1);
314 } else { 314 } else {
315 var textSelection = this.selection(); 315 var textSelection = this.selection();
316 promise = 316 promise =
317 this._delegate.populateTextAreaContextMenu(contextMenu, textSelection. startLine, textSelection.startColumn); 317 this._delegate.populateTextAreaContextMenu(contextMenu, textSelection. startLine, textSelection.startColumn);
318 } 318 }
319 promise.then(showAsync.bind(this)); 319 promise.then(showAsync.bind(this));
320 320
321 /** 321 /**
322 * @this {WebInspector.SourcesTextEditor} 322 * @this {SourceFrame.SourcesTextEditor}
323 */ 323 */
324 function showAsync() { 324 function showAsync() {
325 contextMenu.appendApplicableItems(this); 325 contextMenu.appendApplicableItems(this);
326 contextMenu.show(); 326 contextMenu.show();
327 } 327 }
328 } 328 }
329 329
330 /** 330 /**
331 * @override 331 * @override
332 * @param {!WebInspector.TextRange} range 332 * @param {!Common.TextRange} range
333 * @param {string} text 333 * @param {string} text
334 * @param {string=} origin 334 * @param {string=} origin
335 * @return {!WebInspector.TextRange} 335 * @return {!Common.TextRange}
336 */ 336 */
337 editRange(range, text, origin) { 337 editRange(range, text, origin) {
338 var newRange = super.editRange(range, text, origin); 338 var newRange = super.editRange(range, text, origin);
339 this.dispatchEventToListeners( 339 this.dispatchEventToListeners(
340 WebInspector.SourcesTextEditor.Events.TextChanged, {oldRange: range, new Range: newRange}); 340 SourceFrame.SourcesTextEditor.Events.TextChanged, {oldRange: range, newR ange: newRange});
341 341
342 if (WebInspector.moduleSetting('textEditorAutoDetectIndent').get()) 342 if (Common.moduleSetting('textEditorAutoDetectIndent').get())
343 this._onUpdateEditorIndentation(); 343 this._onUpdateEditorIndentation();
344 344
345 return newRange; 345 return newRange;
346 } 346 }
347 347
348 _onUpdateEditorIndentation() { 348 _onUpdateEditorIndentation() {
349 this._setEditorIndentation(WebInspector.CodeMirrorUtils.pullLines( 349 this._setEditorIndentation(TextEditor.CodeMirrorUtils.pullLines(
350 this.codeMirror(), WebInspector.SourcesTextEditor.LinesToScanForIndentat ionGuessing)); 350 this.codeMirror(), SourceFrame.SourcesTextEditor.LinesToScanForIndentati onGuessing));
351 } 351 }
352 352
353 /** 353 /**
354 * @param {!Array.<string>} lines 354 * @param {!Array.<string>} lines
355 */ 355 */
356 _setEditorIndentation(lines) { 356 _setEditorIndentation(lines) {
357 var extraKeys = {}; 357 var extraKeys = {};
358 var indent = WebInspector.moduleSetting('textEditorIndent').get(); 358 var indent = Common.moduleSetting('textEditorIndent').get();
359 if (WebInspector.moduleSetting('textEditorAutoDetectIndent').get()) 359 if (Common.moduleSetting('textEditorAutoDetectIndent').get())
360 indent = WebInspector.SourcesTextEditor._guessIndentationLevel(lines); 360 indent = SourceFrame.SourcesTextEditor._guessIndentationLevel(lines);
361 361
362 if (indent === WebInspector.TextUtils.Indent.TabCharacter) { 362 if (indent === Common.TextUtils.Indent.TabCharacter) {
363 this.codeMirror().setOption('indentWithTabs', true); 363 this.codeMirror().setOption('indentWithTabs', true);
364 this.codeMirror().setOption('indentUnit', 4); 364 this.codeMirror().setOption('indentUnit', 4);
365 } else { 365 } else {
366 this.codeMirror().setOption('indentWithTabs', false); 366 this.codeMirror().setOption('indentWithTabs', false);
367 this.codeMirror().setOption('indentUnit', indent.length); 367 this.codeMirror().setOption('indentUnit', indent.length);
368 extraKeys.Tab = function(codeMirror) { 368 extraKeys.Tab = function(codeMirror) {
369 if (codeMirror.somethingSelected()) 369 if (codeMirror.somethingSelected())
370 return CodeMirror.Pass; 370 return CodeMirror.Pass;
371 var pos = codeMirror.getCursor('head'); 371 var pos = codeMirror.getCursor('head');
372 codeMirror.replaceRange(indent.substring(pos.ch % indent.length), codeMi rror.getCursor()); 372 codeMirror.replaceRange(indent.substring(pos.ch % indent.length), codeMi rror.getCursor());
(...skipping 12 matching lines...) Expand all
385 } 385 }
386 386
387 _onAutoAppendedSpaces() { 387 _onAutoAppendedSpaces() {
388 this._autoAppendedSpaces = this._autoAppendedSpaces || []; 388 this._autoAppendedSpaces = this._autoAppendedSpaces || [];
389 389
390 for (var i = 0; i < this._autoAppendedSpaces.length; ++i) { 390 for (var i = 0; i < this._autoAppendedSpaces.length; ++i) {
391 var position = this._autoAppendedSpaces[i].resolve(); 391 var position = this._autoAppendedSpaces[i].resolve();
392 if (!position) 392 if (!position)
393 continue; 393 continue;
394 var line = this.line(position.lineNumber); 394 var line = this.line(position.lineNumber);
395 if (line.length === position.columnNumber && WebInspector.TextUtils.lineIn dent(line).length === line.length) 395 if (line.length === position.columnNumber && Common.TextUtils.lineIndent(l ine).length === line.length)
396 this.codeMirror().replaceRange( 396 this.codeMirror().replaceRange(
397 '', new CodeMirror.Pos(position.lineNumber, 0), 397 '', new CodeMirror.Pos(position.lineNumber, 0),
398 new CodeMirror.Pos(position.lineNumber, position.columnNumber)); 398 new CodeMirror.Pos(position.lineNumber, position.columnNumber));
399 } 399 }
400 400
401 this._autoAppendedSpaces = []; 401 this._autoAppendedSpaces = [];
402 var selections = this.selections(); 402 var selections = this.selections();
403 for (var i = 0; i < selections.length; ++i) { 403 for (var i = 0; i < selections.length; ++i) {
404 var selection = selections[i]; 404 var selection = selections[i];
405 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn)); 405 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.star tLine, selection.startColumn));
406 } 406 }
407 } 407 }
408 408
409 /** 409 /**
410 * @param {!CodeMirror} codeMirror 410 * @param {!CodeMirror} codeMirror
411 * @param {!Array.<!CodeMirror.ChangeObject>} changes 411 * @param {!Array.<!CodeMirror.ChangeObject>} changes
412 */ 412 */
413 _fireTextChanged(codeMirror, changes) { 413 _fireTextChanged(codeMirror, changes) {
414 if (!changes.length || this._muteTextChangedEvent) 414 if (!changes.length || this._muteTextChangedEvent)
415 return; 415 return;
416 var edits = []; 416 var edits = [];
417 var currentEdit; 417 var currentEdit;
418 418
419 for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) { 419 for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) {
420 var changeObject = changes[changeIndex]; 420 var changeObject = changes[changeIndex];
421 var edit = WebInspector.CodeMirrorUtils.changeObjectToEditOperation(change Object); 421 var edit = TextEditor.CodeMirrorUtils.changeObjectToEditOperation(changeOb ject);
422 if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) { 422 if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) {
423 currentEdit.newRange = edit.newRange; 423 currentEdit.newRange = edit.newRange;
424 } else { 424 } else {
425 currentEdit = edit; 425 currentEdit = edit;
426 edits.push(currentEdit); 426 edits.push(currentEdit);
427 } 427 }
428 } 428 }
429 429
430 for (var i = 0; i < edits.length; ++i) 430 for (var i = 0; i < edits.length; ++i)
431 this.dispatchEventToListeners(WebInspector.SourcesTextEditor.Events.TextCh anged, edits[i]); 431 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.TextCha nged, edits[i]);
432 } 432 }
433 433
434 _cursorActivity() { 434 _cursorActivity() {
435 if (!this._isSearchActive()) 435 if (!this._isSearchActive())
436 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter)); 436 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens .bind(this._tokenHighlighter));
437 437
438 var start = this.codeMirror().getCursor('anchor'); 438 var start = this.codeMirror().getCursor('anchor');
439 var end = this.codeMirror().getCursor('head'); 439 var end = this.codeMirror().getCursor('head');
440 this.dispatchEventToListeners( 440 this.dispatchEventToListeners(
441 WebInspector.SourcesTextEditor.Events.SelectionChanged, WebInspector.Cod eMirrorUtils.toRange(start, end)); 441 SourceFrame.SourcesTextEditor.Events.SelectionChanged, TextEditor.CodeMi rrorUtils.toRange(start, end));
442 } 442 }
443 443
444 /** 444 /**
445 * @param {?WebInspector.TextRange} from 445 * @param {?Common.TextRange} from
446 * @param {?WebInspector.TextRange} to 446 * @param {?Common.TextRange} to
447 */ 447 */
448 _reportJump(from, to) { 448 _reportJump(from, to) {
449 if (from && to && from.equal(to)) 449 if (from && to && from.equal(to))
450 return; 450 return;
451 this.dispatchEventToListeners(WebInspector.SourcesTextEditor.Events.JumpHapp ened, {from: from, to: to}); 451 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.JumpHappe ned, {from: from, to: to});
452 } 452 }
453 453
454 _scroll() { 454 _scroll() {
455 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror().get ScrollInfo().top, 'local'); 455 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror().get ScrollInfo().top, 'local');
456 this.dispatchEventToListeners(WebInspector.SourcesTextEditor.Events.ScrollCh anged, topmostLineNumber); 456 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.ScrollCha nged, topmostLineNumber);
457 } 457 }
458 458
459 _focus() { 459 _focus() {
460 this.dispatchEventToListeners(WebInspector.SourcesTextEditor.Events.EditorFo cused); 460 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.EditorFoc used);
461 } 461 }
462 462
463 _blur() { 463 _blur() {
464 this.dispatchEventToListeners(WebInspector.SourcesTextEditor.Events.EditorBl urred); 464 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.EditorBlu rred);
465 } 465 }
466 466
467 /** 467 /**
468 * @param {!CodeMirror} codeMirror 468 * @param {!CodeMirror} codeMirror
469 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}>} } selection 469 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}>} } selection
470 */ 470 */
471 _fireBeforeSelectionChanged(codeMirror, selection) { 471 _fireBeforeSelectionChanged(codeMirror, selection) {
472 if (!this._isHandlingMouseDownEvent) 472 if (!this._isHandlingMouseDownEvent)
473 return; 473 return;
474 if (!selection.ranges.length) 474 if (!selection.ranges.length)
475 return; 475 return;
476 476
477 var primarySelection = selection.ranges[0]; 477 var primarySelection = selection.ranges[0];
478 this._reportJump( 478 this._reportJump(
479 this.selection(), WebInspector.CodeMirrorUtils.toRange(primarySelection. anchor, primarySelection.head)); 479 this.selection(), TextEditor.CodeMirrorUtils.toRange(primarySelection.an chor, primarySelection.head));
480 } 480 }
481 481
482 /** 482 /**
483 * @override 483 * @override
484 */ 484 */
485 dispose() { 485 dispose() {
486 super.dispose(); 486 super.dispose();
487 WebInspector.moduleSetting('textEditorIndent').removeChangeListener(this._on UpdateEditorIndentation, this); 487 Common.moduleSetting('textEditorIndent').removeChangeListener(this._onUpdate EditorIndentation, this);
488 WebInspector.moduleSetting('textEditorAutoDetectIndent') 488 Common.moduleSetting('textEditorAutoDetectIndent')
489 .removeChangeListener(this._onUpdateEditorIndentation, this); 489 .removeChangeListener(this._onUpdateEditorIndentation, this);
490 WebInspector.moduleSetting('showWhitespacesInEditor').removeChangeListener(t his._updateWhitespace, this); 490 Common.moduleSetting('showWhitespacesInEditor').removeChangeListener(this._u pdateWhitespace, this);
491 } 491 }
492 492
493 /** 493 /**
494 * @override 494 * @override
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, WebInspector.SourcesTextEditor.LinesToScanForI ndentationGuessing)); 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 /** 505 /**
506 * @override 506 * @override
507 * @param {string} mimeType 507 * @param {string} mimeType
508 * @return {!Promise} 508 * @return {!Promise}
509 */ 509 */
510 setMimeType(mimeType) { 510 setMimeType(mimeType) {
511 this._mimeType = mimeType; 511 this._mimeType = mimeType;
512 return super.setMimeType(mimeType).then( 512 return super.setMimeType(mimeType).then(
513 () => this._codeMirror.setOption('mode', this._applyWhitespaceMimetype(m imeType))); 513 () => this._codeMirror.setOption('mode', this._applyWhitespaceMimetype(m imeType)));
514 } 514 }
515 515
516 _updateWhitespace() { 516 _updateWhitespace() {
517 if (this._mimeType) 517 if (this._mimeType)
518 this.setMimeType(this._mimeType); 518 this.setMimeType(this._mimeType);
519 } 519 }
520 520
521 /** 521 /**
522 * @param {string} mimeType 522 * @param {string} mimeType
523 * @return {string} 523 * @return {string}
524 */ 524 */
525 _applyWhitespaceMimetype(mimeType) { 525 _applyWhitespaceMimetype(mimeType) {
526 this._setupWhitespaceHighlight(); 526 this._setupWhitespaceHighlight();
527 var whitespaceMode = WebInspector.moduleSetting('showWhitespacesInEditor').g et(); 527 var whitespaceMode = Common.moduleSetting('showWhitespacesInEditor').get();
528 this.element.classList.toggle('show-whitespaces', whitespaceMode === 'all'); 528 this.element.classList.toggle('show-whitespaces', whitespaceMode === 'all');
529 529
530 if (whitespaceMode === 'all') 530 if (whitespaceMode === 'all')
531 return this._allWhitespaceOverlayMode(mimeType); 531 return this._allWhitespaceOverlayMode(mimeType);
532 else if (whitespaceMode === 'trailing') 532 else if (whitespaceMode === 'trailing')
533 return this._trailingWhitespaceOverlayMode(mimeType); 533 return this._trailingWhitespaceOverlayMode(mimeType);
534 534
535 return mimeType; 535 return mimeType;
536 } 536 }
537 537
538 /** 538 /**
539 * @param {string} mimeType 539 * @param {string} mimeType
540 * @return {string} 540 * @return {string}
541 */ 541 */
542 _allWhitespaceOverlayMode(mimeType) { 542 _allWhitespaceOverlayMode(mimeType) {
543 var modeName = CodeMirror.mimeModes[mimeType] ? 543 var modeName = CodeMirror.mimeModes[mimeType] ?
544 (CodeMirror.mimeModes[mimeType].name || CodeMirror.mimeModes[mimeType]) : 544 (CodeMirror.mimeModes[mimeType].name || CodeMirror.mimeModes[mimeType]) :
545 CodeMirror.mimeModes['text/plain']; 545 CodeMirror.mimeModes['text/plain'];
546 modeName += '+all-whitespaces'; 546 modeName += '+all-whitespaces';
547 if (CodeMirror.modes[modeName]) 547 if (CodeMirror.modes[modeName])
548 return modeName; 548 return modeName;
549 549
550 function modeConstructor(config, parserConfig) { 550 function modeConstructor(config, parserConfig) {
551 function nextToken(stream) { 551 function nextToken(stream) {
552 if (stream.peek() === ' ') { 552 if (stream.peek() === ' ') {
553 var spaces = 0; 553 var spaces = 0;
554 while (spaces < WebInspector.SourcesTextEditor.MaximumNumberOfWhitespa cesPerSingleSpan && 554 while (spaces < SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespac esPerSingleSpan &&
555 stream.peek() === ' ') { 555 stream.peek() === ' ') {
556 ++spaces; 556 ++spaces;
557 stream.next(); 557 stream.next();
558 } 558 }
559 return 'whitespace whitespace-' + spaces; 559 return 'whitespace whitespace-' + spaces;
560 } 560 }
561 while (!stream.eol() && stream.peek() !== ' ') 561 while (!stream.eol() && stream.peek() !== ' ')
562 stream.next(); 562 stream.next();
563 return null; 563 return null;
564 } 564 }
(...skipping 28 matching lines...) Expand all
593 } 593 }
594 var whitespaceMode = {token: nextToken}; 594 var whitespaceMode = {token: nextToken};
595 return CodeMirror.overlayMode(CodeMirror.getMode(config, mimeType), whites paceMode, false); 595 return CodeMirror.overlayMode(CodeMirror.getMode(config, mimeType), whites paceMode, false);
596 } 596 }
597 CodeMirror.defineMode(modeName, modeConstructor); 597 CodeMirror.defineMode(modeName, modeConstructor);
598 return modeName; 598 return modeName;
599 } 599 }
600 600
601 _setupWhitespaceHighlight() { 601 _setupWhitespaceHighlight() {
602 var doc = this.element.ownerDocument; 602 var doc = this.element.ownerDocument;
603 if (doc._codeMirrorWhitespaceStyleInjected || !WebInspector.moduleSetting('s howWhitespacesInEditor').get()) 603 if (doc._codeMirrorWhitespaceStyleInjected || !Common.moduleSetting('showWhi tespacesInEditor').get())
604 return; 604 return;
605 doc._codeMirrorWhitespaceStyleInjected = true; 605 doc._codeMirrorWhitespaceStyleInjected = true;
606 const classBase = '.show-whitespaces .CodeMirror .cm-whitespace-'; 606 const classBase = '.show-whitespaces .CodeMirror .cm-whitespace-';
607 const spaceChar = '·'; 607 const spaceChar = '·';
608 var spaceChars = ''; 608 var spaceChars = '';
609 var rules = ''; 609 var rules = '';
610 for (var i = 1; i <= WebInspector.SourcesTextEditor.MaximumNumberOfWhitespac esPerSingleSpan; ++i) { 610 for (var i = 1; i <= SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespace sPerSingleSpan; ++i) {
611 spaceChars += spaceChar; 611 spaceChars += spaceChar;
612 var rule = classBase + i + '::before { content: \'' + spaceChars + '\';}\n '; 612 var rule = classBase + i + '::before { content: \'' + spaceChars + '\';}\n ';
613 rules += rule; 613 rules += rule;
614 } 614 }
615 var style = doc.createElement('style'); 615 var style = doc.createElement('style');
616 style.textContent = rules; 616 style.textContent = rules;
617 doc.head.appendChild(style); 617 doc.head.appendChild(style);
618 } 618 }
619 }; 619 };
620 620
621 /** @typedef {{lineNumber: number, event: !Event}} */ 621 /** @typedef {{lineNumber: number, event: !Event}} */
622 WebInspector.SourcesTextEditor.GutterClickEventData; 622 SourceFrame.SourcesTextEditor.GutterClickEventData;
623 623
624 /** @enum {symbol} */ 624 /** @enum {symbol} */
625 WebInspector.SourcesTextEditor.Events = { 625 SourceFrame.SourcesTextEditor.Events = {
626 GutterClick: Symbol('GutterClick'), 626 GutterClick: Symbol('GutterClick'),
627 TextChanged: Symbol('TextChanged'), 627 TextChanged: Symbol('TextChanged'),
628 SelectionChanged: Symbol('SelectionChanged'), 628 SelectionChanged: Symbol('SelectionChanged'),
629 ScrollChanged: Symbol('ScrollChanged'), 629 ScrollChanged: Symbol('ScrollChanged'),
630 EditorFocused: Symbol('EditorFocused'), 630 EditorFocused: Symbol('EditorFocused'),
631 EditorBlurred: Symbol('EditorBlurred'), 631 EditorBlurred: Symbol('EditorBlurred'),
632 JumpHappened: Symbol('JumpHappened') 632 JumpHappened: Symbol('JumpHappened')
633 }; 633 };
634 634
635 /** 635 /**
636 * @interface 636 * @interface
637 */ 637 */
638 WebInspector.SourcesTextEditorDelegate = function() {}; 638 SourceFrame.SourcesTextEditorDelegate = function() {};
639 WebInspector.SourcesTextEditorDelegate.prototype = { 639 SourceFrame.SourcesTextEditorDelegate.prototype = {
640 /** 640 /**
641 * @param {!WebInspector.ContextMenu} contextMenu 641 * @param {!UI.ContextMenu} contextMenu
642 * @param {number} lineNumber 642 * @param {number} lineNumber
643 * @return {!Promise} 643 * @return {!Promise}
644 */ 644 */
645 populateLineGutterContextMenu: function(contextMenu, lineNumber) {}, 645 populateLineGutterContextMenu: function(contextMenu, lineNumber) {},
646 646
647 /** 647 /**
648 * @param {!WebInspector.ContextMenu} contextMenu 648 * @param {!UI.ContextMenu} contextMenu
649 * @param {number} lineNumber 649 * @param {number} lineNumber
650 * @param {number} columnNumber 650 * @param {number} columnNumber
651 * @return {!Promise} 651 * @return {!Promise}
652 */ 652 */
653 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) { }, 653 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) { },
654 }; 654 };
655 655
656 /** 656 /**
657 * @param {!CodeMirror} codeMirror 657 * @param {!CodeMirror} codeMirror
658 */ 658 */
659 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) { 659 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) {
660 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); 660 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror));
661 function innerSmartNewlineAndIndent(codeMirror) { 661 function innerSmartNewlineAndIndent(codeMirror) {
662 var selections = codeMirror.listSelections(); 662 var selections = codeMirror.listSelections();
663 var replacements = []; 663 var replacements = [];
664 for (var i = 0; i < selections.length; ++i) { 664 for (var i = 0; i < selections.length; ++i) {
665 var selection = selections[i]; 665 var selection = selections[i];
666 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? select ion.head : selection.anchor; 666 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? select ion.head : selection.anchor;
667 var line = codeMirror.getLine(cur.line); 667 var line = codeMirror.getLine(cur.line);
668 var indent = WebInspector.TextUtils.lineIndent(line); 668 var indent = Common.TextUtils.lineIndent(line);
669 replacements.push('\n' + indent.substring(0, Math.min(cur.ch, indent.lengt h))); 669 replacements.push('\n' + indent.substring(0, Math.min(cur.ch, indent.lengt h)));
670 } 670 }
671 codeMirror.replaceSelections(replacements); 671 codeMirror.replaceSelections(replacements);
672 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); 672 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces();
673 } 673 }
674 }; 674 };
675 675
676 /** 676 /**
677 * @return {!Object|undefined} 677 * @return {!Object|undefined}
678 */ 678 */
679 CodeMirror.commands.sourcesDismiss = function(codemirror) { 679 CodeMirror.commands.sourcesDismiss = function(codemirror) {
680 if (codemirror.listSelections().length === 1 && codemirror._codeMirrorTextEdit or._isSearchActive()) 680 if (codemirror.listSelections().length === 1 && codemirror._codeMirrorTextEdit or._isSearchActive())
681 return CodeMirror.Pass; 681 return CodeMirror.Pass;
682 return CodeMirror.commands.dismiss(codemirror); 682 return CodeMirror.commands.dismiss(codemirror);
683 }; 683 };
684 684
685 WebInspector.SourcesTextEditor._BlockIndentController = { 685 SourceFrame.SourcesTextEditor._BlockIndentController = {
686 name: 'blockIndentKeymap', 686 name: 'blockIndentKeymap',
687 687
688 /** 688 /**
689 * @return {*} 689 * @return {*}
690 */ 690 */
691 Enter: function(codeMirror) { 691 Enter: function(codeMirror) {
692 var selections = codeMirror.listSelections(); 692 var selections = codeMirror.listSelections();
693 var replacements = []; 693 var replacements = [];
694 var allSelectionsAreCollapsedBlocks = false; 694 var allSelectionsAreCollapsedBlocks = false;
695 for (var i = 0; i < selections.length; ++i) { 695 for (var i = 0; i < selections.length; ++i) {
696 var selection = selections[i]; 696 var selection = selections[i];
697 var start = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? sele ction.head : selection.anchor; 697 var start = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? sele ction.head : selection.anchor;
698 var line = codeMirror.getLine(start.line); 698 var line = codeMirror.getLine(start.line);
699 var indent = WebInspector.TextUtils.lineIndent(line); 699 var indent = Common.TextUtils.lineIndent(line);
700 var indentToInsert = '\n' + indent + codeMirror._codeMirrorTextEditor.inde nt(); 700 var indentToInsert = '\n' + indent + codeMirror._codeMirrorTextEditor.inde nt();
701 var isCollapsedBlock = false; 701 var isCollapsedBlock = false;
702 if (selection.head.ch === 0) 702 if (selection.head.ch === 0)
703 return CodeMirror.Pass; 703 return CodeMirror.Pass;
704 if (line.substr(selection.head.ch - 1, 2) === '{}') { 704 if (line.substr(selection.head.ch - 1, 2) === '{}') {
705 indentToInsert += '\n' + indent; 705 indentToInsert += '\n' + indent;
706 isCollapsedBlock = true; 706 isCollapsedBlock = true;
707 } else if (line.substr(selection.head.ch - 1, 1) !== '{') { 707 } else if (line.substr(selection.head.ch - 1, 1) !== '{') {
708 return CodeMirror.Pass; 708 return CodeMirror.Pass;
709 } 709 }
(...skipping 23 matching lines...) Expand all
733 * @return {*} 733 * @return {*}
734 */ 734 */
735 '\'}\'': function(codeMirror) { 735 '\'}\'': function(codeMirror) {
736 if (codeMirror.somethingSelected()) 736 if (codeMirror.somethingSelected())
737 return CodeMirror.Pass; 737 return CodeMirror.Pass;
738 var selections = codeMirror.listSelections(); 738 var selections = codeMirror.listSelections();
739 var replacements = []; 739 var replacements = [];
740 for (var i = 0; i < selections.length; ++i) { 740 for (var i = 0; i < selections.length; ++i) {
741 var selection = selections[i]; 741 var selection = selections[i];
742 var line = codeMirror.getLine(selection.head.line); 742 var line = codeMirror.getLine(selection.head.line);
743 if (line !== WebInspector.TextUtils.lineIndent(line)) 743 if (line !== Common.TextUtils.lineIndent(line))
744 return CodeMirror.Pass; 744 return CodeMirror.Pass;
745 replacements.push('}'); 745 replacements.push('}');
746 } 746 }
747 codeMirror.replaceSelections(replacements); 747 codeMirror.replaceSelections(replacements);
748 selections = codeMirror.listSelections(); 748 selections = codeMirror.listSelections();
749 replacements = []; 749 replacements = [];
750 var updatedSelections = []; 750 var updatedSelections = [];
751 for (var i = 0; i < selections.length; ++i) { 751 for (var i = 0; i < selections.length; ++i) {
752 var selection = selections[i]; 752 var selection = selections[i];
753 var matchingBracket = codeMirror.findMatchingBracket(selection.head); 753 var matchingBracket = codeMirror.findMatchingBracket(selection.head);
754 if (!matchingBracket || !matchingBracket.match) 754 if (!matchingBracket || !matchingBracket.match)
755 return; 755 return;
756 updatedSelections.push({head: selection.head, anchor: new CodeMirror.Pos(s election.head.line, 0)}); 756 updatedSelections.push({head: selection.head, anchor: new CodeMirror.Pos(s election.head.line, 0)});
757 var line = codeMirror.getLine(matchingBracket.to.line); 757 var line = codeMirror.getLine(matchingBracket.to.line);
758 var indent = WebInspector.TextUtils.lineIndent(line); 758 var indent = Common.TextUtils.lineIndent(line);
759 replacements.push(indent + '}'); 759 replacements.push(indent + '}');
760 } 760 }
761 codeMirror.setSelections(updatedSelections); 761 codeMirror.setSelections(updatedSelections);
762 codeMirror.replaceSelections(replacements); 762 codeMirror.replaceSelections(replacements);
763 } 763 }
764 }; 764 };
765 765
766 766
767 /** 767 /**
768 * @unrestricted 768 * @unrestricted
769 */ 769 */
770 WebInspector.SourcesTextEditor.TokenHighlighter = class { 770 SourceFrame.SourcesTextEditor.TokenHighlighter = class {
771 /** 771 /**
772 * @param {!WebInspector.SourcesTextEditor} textEditor 772 * @param {!SourceFrame.SourcesTextEditor} textEditor
773 * @param {!CodeMirror} codeMirror 773 * @param {!CodeMirror} codeMirror
774 */ 774 */
775 constructor(textEditor, codeMirror) { 775 constructor(textEditor, codeMirror) {
776 this._textEditor = textEditor; 776 this._textEditor = textEditor;
777 this._codeMirror = codeMirror; 777 this._codeMirror = codeMirror;
778 } 778 }
779 779
780 /** 780 /**
781 * @param {!RegExp} regex 781 * @param {!RegExp} regex
782 * @param {?WebInspector.TextRange} range 782 * @param {?Common.TextRange} range
783 */ 783 */
784 highlightSearchResults(regex, range) { 784 highlightSearchResults(regex, range) {
785 var oldRegex = this._highlightRegex; 785 var oldRegex = this._highlightRegex;
786 this._highlightRegex = regex; 786 this._highlightRegex = regex;
787 this._highlightRange = range; 787 this._highlightRange = range;
788 if (this._searchResultMarker) { 788 if (this._searchResultMarker) {
789 this._searchResultMarker.clear(); 789 this._searchResultMarker.clear();
790 delete this._searchResultMarker; 790 delete this._searchResultMarker;
791 } 791 }
792 if (this._highlightDescriptor && this._highlightDescriptor.selectionStart) 792 if (this._highlightDescriptor && this._highlightDescriptor.selectionStart)
793 this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart. line, 'wrap', 'cm-line-with-selection'); 793 this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart. line, 'wrap', 'cm-line-with-selection');
794 var selectionStart = this._highlightRange ? 794 var selectionStart = this._highlightRange ?
795 new CodeMirror.Pos(this._highlightRange.startLine, this._highlightRange. startColumn) : 795 new CodeMirror.Pos(this._highlightRange.startLine, this._highlightRange. startColumn) :
796 null; 796 null;
797 if (selectionStart) 797 if (selectionStart)
798 this._codeMirror.addLineClass(selectionStart.line, 'wrap', 'cm-line-with-s election'); 798 this._codeMirror.addLineClass(selectionStart.line, 'wrap', 'cm-line-with-s election');
799 if (oldRegex && this._highlightRegex.toString() === oldRegex.toString()) { 799 if (oldRegex && this._highlightRegex.toString() === oldRegex.toString()) {
800 // Do not re-add overlay mode if regex did not change for better performan ce. 800 // Do not re-add overlay mode if regex did not change for better performan ce.
801 if (this._highlightDescriptor) 801 if (this._highlightDescriptor)
802 this._highlightDescriptor.selectionStart = selectionStart; 802 this._highlightDescriptor.selectionStart = selectionStart;
803 } else { 803 } else {
804 this._removeHighlight(); 804 this._removeHighlight();
805 this._setHighlighter(this._searchHighlighter.bind(this, this._highlightReg ex), selectionStart); 805 this._setHighlighter(this._searchHighlighter.bind(this, this._highlightReg ex), selectionStart);
806 } 806 }
807 if (this._highlightRange) { 807 if (this._highlightRange) {
808 var pos = WebInspector.CodeMirrorUtils.toPos(this._highlightRange); 808 var pos = TextEditor.CodeMirrorUtils.toPos(this._highlightRange);
809 this._searchResultMarker = this._codeMirror.markText(pos.start, pos.end, { className: 'cm-column-with-selection'}); 809 this._searchResultMarker = this._codeMirror.markText(pos.start, pos.end, { className: 'cm-column-with-selection'});
810 } 810 }
811 } 811 }
812 812
813 /** 813 /**
814 * @return {!RegExp|undefined} 814 * @return {!RegExp|undefined}
815 */ 815 */
816 highlightedRegex() { 816 highlightedRegex() {
817 return this._highlightRegex; 817 return this._highlightRegex;
818 } 818 }
(...skipping 22 matching lines...) Expand all
841 } 841 }
842 842
843 /** 843 /**
844 * @param {string} selectedText 844 * @param {string} selectedText
845 * @param {number} lineNumber 845 * @param {number} lineNumber
846 * @param {number} startColumn 846 * @param {number} startColumn
847 * @param {number} endColumn 847 * @param {number} endColumn
848 */ 848 */
849 _isWord(selectedText, lineNumber, startColumn, endColumn) { 849 _isWord(selectedText, lineNumber, startColumn, endColumn) {
850 var line = this._codeMirror.getLine(lineNumber); 850 var line = this._codeMirror.getLine(lineNumber);
851 var leftBound = startColumn === 0 || !WebInspector.TextUtils.isWordChar(line .charAt(startColumn - 1)); 851 var leftBound = startColumn === 0 || !Common.TextUtils.isWordChar(line.charA t(startColumn - 1));
852 var rightBound = endColumn === line.length || !WebInspector.TextUtils.isWord Char(line.charAt(endColumn)); 852 var rightBound = endColumn === line.length || !Common.TextUtils.isWordChar(l ine.charAt(endColumn));
853 return leftBound && rightBound && WebInspector.TextUtils.isWord(selectedText ); 853 return leftBound && rightBound && Common.TextUtils.isWord(selectedText);
854 } 854 }
855 855
856 _removeHighlight() { 856 _removeHighlight() {
857 if (this._highlightDescriptor) { 857 if (this._highlightDescriptor) {
858 this._codeMirror.removeOverlay(this._highlightDescriptor.overlay); 858 this._codeMirror.removeOverlay(this._highlightDescriptor.overlay);
859 delete this._highlightDescriptor; 859 delete this._highlightDescriptor;
860 } 860 }
861 } 861 }
862 862
863 /** 863 /**
(...skipping 28 matching lines...) Expand all
892 } 892 }
893 } 893 }
894 894
895 /** 895 /**
896 * @param {string} token 896 * @param {string} token
897 * @param {!CodeMirror.Pos} selectionStart 897 * @param {!CodeMirror.Pos} selectionStart
898 * @param {!CodeMirror.StringStream} stream 898 * @param {!CodeMirror.StringStream} stream
899 */ 899 */
900 _tokenHighlighter(token, selectionStart, stream) { 900 _tokenHighlighter(token, selectionStart, stream) {
901 var tokenFirstChar = token.charAt(0); 901 var tokenFirstChar = token.charAt(0);
902 if (stream.match(token) && (stream.eol() || !WebInspector.TextUtils.isWordCh ar(stream.peek()))) 902 if (stream.match(token) && (stream.eol() || !Common.TextUtils.isWordChar(str eam.peek())))
903 return stream.column() === selectionStart.ch ? 'token-highlight column-wit h-selection' : 'token-highlight'; 903 return stream.column() === selectionStart.ch ? 'token-highlight column-wit h-selection' : 'token-highlight';
904 var eatenChar; 904 var eatenChar;
905 do { 905 do {
906 eatenChar = stream.next(); 906 eatenChar = stream.next();
907 } while (eatenChar && (WebInspector.TextUtils.isWordChar(eatenChar) || strea m.peek() !== tokenFirstChar)); 907 } while (eatenChar && (Common.TextUtils.isWordChar(eatenChar) || stream.peek () !== tokenFirstChar));
908 } 908 }
909 909
910 /** 910 /**
911 * @param {function(!CodeMirror.StringStream)} highlighter 911 * @param {function(!CodeMirror.StringStream)} highlighter
912 * @param {?CodeMirror.Pos} selectionStart 912 * @param {?CodeMirror.Pos} selectionStart
913 */ 913 */
914 _setHighlighter(highlighter, selectionStart) { 914 _setHighlighter(highlighter, selectionStart) {
915 var overlayMode = {token: highlighter}; 915 var overlayMode = {token: highlighter};
916 this._codeMirror.addOverlay(overlayMode); 916 this._codeMirror.addOverlay(overlayMode);
917 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start}; 917 this._highlightDescriptor = {overlay: overlayMode, selectionStart: selection Start};
918 } 918 }
919 }; 919 };
920 920
921 WebInspector.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000; 921 SourceFrame.SourcesTextEditor.LinesToScanForIndentationGuessing = 1000;
922 WebInspector.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; 922 SourceFrame.SourcesTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698