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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 /** | 59 /** |
60 * @param {!Array.<string>} lines | 60 * @param {!Array.<string>} lines |
61 * @return {string} | 61 * @return {string} |
62 */ | 62 */ |
63 static _guessIndentationLevel(lines) { | 63 static _guessIndentationLevel(lines) { |
64 var tabRegex = /^\t+/; | 64 var tabRegex = /^\t+/; |
65 var tabLines = 0; | 65 var tabLines = 0; |
66 var indents = {}; | 66 var indents = {}; |
67 for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) { | 67 for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) { |
68 var text = lines[lineNumber]; | 68 var text = lines[lineNumber]; |
69 if (text.length === 0 || !Common.TextUtils.isSpaceChar(text[0])) | 69 if (text.length === 0 || !TextUtils.TextUtils.isSpaceChar(text[0])) |
70 continue; | 70 continue; |
71 if (tabRegex.test(text)) { | 71 if (tabRegex.test(text)) { |
72 ++tabLines; | 72 ++tabLines; |
73 continue; | 73 continue; |
74 } | 74 } |
75 var i = 0; | 75 var i = 0; |
76 while (i < text.length && Common.TextUtils.isSpaceChar(text[i])) | 76 while (i < text.length && TextUtils.TextUtils.isSpaceChar(text[i])) |
77 ++i; | 77 ++i; |
78 if (i % 2 !== 0) | 78 if (i % 2 !== 0) |
79 continue; | 79 continue; |
80 indents[i] = 1 + (indents[i] || 0); | 80 indents[i] = 1 + (indents[i] || 0); |
81 } | 81 } |
82 var linesCountPerIndentThreshold = 3 * lines.length / 100; | 82 var linesCountPerIndentThreshold = 3 * lines.length / 100; |
83 if (tabLines && tabLines > linesCountPerIndentThreshold) | 83 if (tabLines && tabLines > linesCountPerIndentThreshold) |
84 return '\t'; | 84 return '\t'; |
85 var minimumIndent = Infinity; | 85 var minimumIndent = Infinity; |
86 for (var i in indents) { | 86 for (var i in indents) { |
(...skipping 19 matching lines...) Expand all Loading... |
106 * @override | 106 * @override |
107 * @param {number} lineNumber | 107 * @param {number} lineNumber |
108 */ | 108 */ |
109 scrollToLine(lineNumber) { | 109 scrollToLine(lineNumber) { |
110 super.scrollToLine(lineNumber); | 110 super.scrollToLine(lineNumber); |
111 this._scroll(); | 111 this._scroll(); |
112 } | 112 } |
113 | 113 |
114 /** | 114 /** |
115 * @param {!RegExp} regex | 115 * @param {!RegExp} regex |
116 * @param {?Common.TextRange} range | 116 * @param {?TextUtils.TextRange} range |
117 */ | 117 */ |
118 highlightSearchResults(regex, range) { | 118 highlightSearchResults(regex, range) { |
119 /** | 119 /** |
120 * @this {TextEditor.CodeMirrorTextEditor} | 120 * @this {TextEditor.CodeMirrorTextEditor} |
121 */ | 121 */ |
122 function innerHighlightRegex() { | 122 function innerHighlightRegex() { |
123 if (range) { | 123 if (range) { |
124 this.scrollLineIntoView(range.startLine); | 124 this.scrollLineIntoView(range.startLine); |
125 if (range.endColumn > TextEditor.CodeMirrorTextEditor.maxHighlightLength
) | 125 if (range.endColumn > TextEditor.CodeMirrorTextEditor.maxHighlightLength
) |
126 this.setSelection(range); | 126 this.setSelection(range); |
127 else | 127 else |
128 this.setSelection(Common.TextRange.createFromLocation(range.startLine,
range.startColumn)); | 128 this.setSelection(TextUtils.TextRange.createFromLocation(range.startLi
ne, range.startColumn)); |
129 } | 129 } |
130 this._tokenHighlighter.highlightSearchResults(regex, range); | 130 this._tokenHighlighter.highlightSearchResults(regex, range); |
131 } | 131 } |
132 | 132 |
133 if (!this._selectionBeforeSearch) | 133 if (!this._selectionBeforeSearch) |
134 this._selectionBeforeSearch = this.selection(); | 134 this._selectionBeforeSearch = this.selection(); |
135 | 135 |
136 this.codeMirror().operation(innerHighlightRegex.bind(this)); | 136 this.codeMirror().operation(innerHighlightRegex.bind(this)); |
137 } | 137 } |
138 | 138 |
139 cancelSearchResultsHighlight() { | 139 cancelSearchResultsHighlight() { |
140 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens.b
ind(this._tokenHighlighter)); | 140 this.codeMirror().operation(this._tokenHighlighter.highlightSelectedTokens.b
ind(this._tokenHighlighter)); |
141 | 141 |
142 if (this._selectionBeforeSearch) { | 142 if (this._selectionBeforeSearch) { |
143 this._reportJump(this._selectionBeforeSearch, this.selection()); | 143 this._reportJump(this._selectionBeforeSearch, this.selection()); |
144 delete this._selectionBeforeSearch; | 144 delete this._selectionBeforeSearch; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * @param {!Object} highlightDescriptor | 149 * @param {!Object} highlightDescriptor |
150 */ | 150 */ |
151 removeHighlight(highlightDescriptor) { | 151 removeHighlight(highlightDescriptor) { |
152 highlightDescriptor.clear(); | 152 highlightDescriptor.clear(); |
153 } | 153 } |
154 | 154 |
155 /** | 155 /** |
156 * @param {!Common.TextRange} range | 156 * @param {!TextUtils.TextRange} range |
157 * @param {string} cssClass | 157 * @param {string} cssClass |
158 * @return {!Object} | 158 * @return {!Object} |
159 */ | 159 */ |
160 highlightRange(range, cssClass) { | 160 highlightRange(range, cssClass) { |
161 cssClass = 'CodeMirror-persist-highlight ' + cssClass; | 161 cssClass = 'CodeMirror-persist-highlight ' + cssClass; |
162 var pos = TextEditor.CodeMirrorUtils.toPos(range); | 162 var pos = TextEditor.CodeMirrorUtils.toPos(range); |
163 ++pos.end.ch; | 163 ++pos.end.ch; |
164 return this.codeMirror().markText( | 164 return this.codeMirror().markText( |
165 pos.start, pos.end, {className: cssClass, startStyle: cssClass + '-start
', endStyle: cssClass + '-end'}); | 165 pos.start, pos.end, {className: cssClass, startStyle: cssClass + '-start
', endStyle: cssClass + '-end'}); |
166 } | 166 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 * @this {SourceFrame.SourcesTextEditor} | 292 * @this {SourceFrame.SourcesTextEditor} |
293 */ | 293 */ |
294 function showAsync() { | 294 function showAsync() { |
295 contextMenu.appendApplicableItems(this); | 295 contextMenu.appendApplicableItems(this); |
296 contextMenu.show(); | 296 contextMenu.show(); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 /** | 300 /** |
301 * @override | 301 * @override |
302 * @param {!Common.TextRange} range | 302 * @param {!TextUtils.TextRange} range |
303 * @param {string} text | 303 * @param {string} text |
304 * @param {string=} origin | 304 * @param {string=} origin |
305 * @return {!Common.TextRange} | 305 * @return {!TextUtils.TextRange} |
306 */ | 306 */ |
307 editRange(range, text, origin) { | 307 editRange(range, text, origin) { |
308 var newRange = super.editRange(range, text, origin); | 308 var newRange = super.editRange(range, text, origin); |
309 this.dispatchEventToListeners( | 309 this.dispatchEventToListeners( |
310 SourceFrame.SourcesTextEditor.Events.TextChanged, {oldRange: range, newR
ange: newRange}); | 310 SourceFrame.SourcesTextEditor.Events.TextChanged, {oldRange: range, newR
ange: newRange}); |
311 | 311 |
312 if (Common.moduleSetting('textEditorAutoDetectIndent').get()) | 312 if (Common.moduleSetting('textEditorAutoDetectIndent').get()) |
313 this._onUpdateEditorIndentation(); | 313 this._onUpdateEditorIndentation(); |
314 | 314 |
315 return newRange; | 315 return newRange; |
316 } | 316 } |
317 | 317 |
318 _onUpdateEditorIndentation() { | 318 _onUpdateEditorIndentation() { |
319 this._setEditorIndentation(TextEditor.CodeMirrorUtils.pullLines( | 319 this._setEditorIndentation(TextEditor.CodeMirrorUtils.pullLines( |
320 this.codeMirror(), SourceFrame.SourcesTextEditor.LinesToScanForIndentati
onGuessing)); | 320 this.codeMirror(), SourceFrame.SourcesTextEditor.LinesToScanForIndentati
onGuessing)); |
321 } | 321 } |
322 | 322 |
323 /** | 323 /** |
324 * @param {!Array.<string>} lines | 324 * @param {!Array.<string>} lines |
325 */ | 325 */ |
326 _setEditorIndentation(lines) { | 326 _setEditorIndentation(lines) { |
327 var extraKeys = {}; | 327 var extraKeys = {}; |
328 var indent = Common.moduleSetting('textEditorIndent').get(); | 328 var indent = Common.moduleSetting('textEditorIndent').get(); |
329 if (Common.moduleSetting('textEditorAutoDetectIndent').get()) | 329 if (Common.moduleSetting('textEditorAutoDetectIndent').get()) |
330 indent = SourceFrame.SourcesTextEditor._guessIndentationLevel(lines); | 330 indent = SourceFrame.SourcesTextEditor._guessIndentationLevel(lines); |
331 | 331 |
332 if (indent === Common.TextUtils.Indent.TabCharacter) { | 332 if (indent === TextUtils.TextUtils.Indent.TabCharacter) { |
333 this.codeMirror().setOption('indentWithTabs', true); | 333 this.codeMirror().setOption('indentWithTabs', true); |
334 this.codeMirror().setOption('indentUnit', 4); | 334 this.codeMirror().setOption('indentUnit', 4); |
335 } else { | 335 } else { |
336 this.codeMirror().setOption('indentWithTabs', false); | 336 this.codeMirror().setOption('indentWithTabs', false); |
337 this.codeMirror().setOption('indentUnit', indent.length); | 337 this.codeMirror().setOption('indentUnit', indent.length); |
338 extraKeys.Tab = function(codeMirror) { | 338 extraKeys.Tab = function(codeMirror) { |
339 if (codeMirror.somethingSelected()) | 339 if (codeMirror.somethingSelected()) |
340 return CodeMirror.Pass; | 340 return CodeMirror.Pass; |
341 var pos = codeMirror.getCursor('head'); | 341 var pos = codeMirror.getCursor('head'); |
342 codeMirror.replaceRange(indent.substring(pos.ch % indent.length), codeMi
rror.getCursor()); | 342 codeMirror.replaceRange(indent.substring(pos.ch % indent.length), codeMi
rror.getCursor()); |
(...skipping 12 matching lines...) Expand all Loading... |
355 } | 355 } |
356 | 356 |
357 _onAutoAppendedSpaces() { | 357 _onAutoAppendedSpaces() { |
358 this._autoAppendedSpaces = this._autoAppendedSpaces || []; | 358 this._autoAppendedSpaces = this._autoAppendedSpaces || []; |
359 | 359 |
360 for (var i = 0; i < this._autoAppendedSpaces.length; ++i) { | 360 for (var i = 0; i < this._autoAppendedSpaces.length; ++i) { |
361 var position = this._autoAppendedSpaces[i].resolve(); | 361 var position = this._autoAppendedSpaces[i].resolve(); |
362 if (!position) | 362 if (!position) |
363 continue; | 363 continue; |
364 var line = this.line(position.lineNumber); | 364 var line = this.line(position.lineNumber); |
365 if (line.length === position.columnNumber && Common.TextUtils.lineIndent(l
ine).length === line.length) { | 365 if (line.length === position.columnNumber && TextUtils.TextUtils.lineInden
t(line).length === line.length) { |
366 this.codeMirror().replaceRange( | 366 this.codeMirror().replaceRange( |
367 '', new CodeMirror.Pos(position.lineNumber, 0), | 367 '', new CodeMirror.Pos(position.lineNumber, 0), |
368 new CodeMirror.Pos(position.lineNumber, position.columnNumber)); | 368 new CodeMirror.Pos(position.lineNumber, position.columnNumber)); |
369 } | 369 } |
370 } | 370 } |
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]; |
(...skipping 30 matching lines...) Expand all Loading... |
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)); |
413 } | 413 } |
414 | 414 |
415 /** | 415 /** |
416 * @param {?Common.TextRange} from | 416 * @param {?TextUtils.TextRange} from |
417 * @param {?Common.TextRange} to | 417 * @param {?TextUtils.TextRange} to |
418 */ | 418 */ |
419 _reportJump(from, to) { | 419 _reportJump(from, to) { |
420 if (from && to && from.equal(to)) | 420 if (from && to && from.equal(to)) |
421 return; | 421 return; |
422 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.JumpHappe
ned, {from: from, to: to}); | 422 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.JumpHappe
ned, {from: from, to: to}); |
423 } | 423 } |
424 | 424 |
425 _scroll() { | 425 _scroll() { |
426 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror().get
ScrollInfo().top, 'local'); | 426 var topmostLineNumber = this.codeMirror().lineAtHeight(this.codeMirror().get
ScrollInfo().top, 'local'); |
427 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.ScrollCha
nged, topmostLineNumber); | 427 this.dispatchEventToListeners(SourceFrame.SourcesTextEditor.Events.ScrollCha
nged, topmostLineNumber); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 */ | 616 */ |
617 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) { | 617 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) { |
618 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); | 618 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); |
619 function innerSmartNewlineAndIndent(codeMirror) { | 619 function innerSmartNewlineAndIndent(codeMirror) { |
620 var selections = codeMirror.listSelections(); | 620 var selections = codeMirror.listSelections(); |
621 var replacements = []; | 621 var replacements = []; |
622 for (var i = 0; i < selections.length; ++i) { | 622 for (var i = 0; i < selections.length; ++i) { |
623 var selection = selections[i]; | 623 var selection = selections[i]; |
624 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? select
ion.head : selection.anchor; | 624 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? select
ion.head : selection.anchor; |
625 var line = codeMirror.getLine(cur.line); | 625 var line = codeMirror.getLine(cur.line); |
626 var indent = Common.TextUtils.lineIndent(line); | 626 var indent = TextUtils.TextUtils.lineIndent(line); |
627 replacements.push('\n' + indent.substring(0, Math.min(cur.ch, indent.lengt
h))); | 627 replacements.push('\n' + indent.substring(0, Math.min(cur.ch, indent.lengt
h))); |
628 } | 628 } |
629 codeMirror.replaceSelections(replacements); | 629 codeMirror.replaceSelections(replacements); |
630 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); | 630 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); |
631 } | 631 } |
632 }; | 632 }; |
633 | 633 |
634 /** | 634 /** |
635 * @return {!Object|undefined} | 635 * @return {!Object|undefined} |
636 */ | 636 */ |
(...skipping 10 matching lines...) Expand all Loading... |
647 * @return {*} | 647 * @return {*} |
648 */ | 648 */ |
649 Enter: function(codeMirror) { | 649 Enter: function(codeMirror) { |
650 var selections = codeMirror.listSelections(); | 650 var selections = codeMirror.listSelections(); |
651 var replacements = []; | 651 var replacements = []; |
652 var allSelectionsAreCollapsedBlocks = false; | 652 var allSelectionsAreCollapsedBlocks = false; |
653 for (var i = 0; i < selections.length; ++i) { | 653 for (var i = 0; i < selections.length; ++i) { |
654 var selection = selections[i]; | 654 var selection = selections[i]; |
655 var start = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? sele
ction.head : selection.anchor; | 655 var start = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? sele
ction.head : selection.anchor; |
656 var line = codeMirror.getLine(start.line); | 656 var line = codeMirror.getLine(start.line); |
657 var indent = Common.TextUtils.lineIndent(line); | 657 var indent = TextUtils.TextUtils.lineIndent(line); |
658 var indentToInsert = '\n' + indent + codeMirror._codeMirrorTextEditor.inde
nt(); | 658 var indentToInsert = '\n' + indent + codeMirror._codeMirrorTextEditor.inde
nt(); |
659 var isCollapsedBlock = false; | 659 var isCollapsedBlock = false; |
660 if (selection.head.ch === 0) | 660 if (selection.head.ch === 0) |
661 return CodeMirror.Pass; | 661 return CodeMirror.Pass; |
662 if (line.substr(selection.head.ch - 1, 2) === '{}') { | 662 if (line.substr(selection.head.ch - 1, 2) === '{}') { |
663 indentToInsert += '\n' + indent; | 663 indentToInsert += '\n' + indent; |
664 isCollapsedBlock = true; | 664 isCollapsedBlock = true; |
665 } else if (line.substr(selection.head.ch - 1, 1) !== '{') { | 665 } else if (line.substr(selection.head.ch - 1, 1) !== '{') { |
666 return CodeMirror.Pass; | 666 return CodeMirror.Pass; |
667 } | 667 } |
(...skipping 23 matching lines...) Expand all Loading... |
691 * @return {*} | 691 * @return {*} |
692 */ | 692 */ |
693 '\'}\'': function(codeMirror) { | 693 '\'}\'': function(codeMirror) { |
694 if (codeMirror.somethingSelected()) | 694 if (codeMirror.somethingSelected()) |
695 return CodeMirror.Pass; | 695 return CodeMirror.Pass; |
696 var selections = codeMirror.listSelections(); | 696 var selections = codeMirror.listSelections(); |
697 var replacements = []; | 697 var replacements = []; |
698 for (var i = 0; i < selections.length; ++i) { | 698 for (var i = 0; i < selections.length; ++i) { |
699 var selection = selections[i]; | 699 var selection = selections[i]; |
700 var line = codeMirror.getLine(selection.head.line); | 700 var line = codeMirror.getLine(selection.head.line); |
701 if (line !== Common.TextUtils.lineIndent(line)) | 701 if (line !== TextUtils.TextUtils.lineIndent(line)) |
702 return CodeMirror.Pass; | 702 return CodeMirror.Pass; |
703 replacements.push('}'); | 703 replacements.push('}'); |
704 } | 704 } |
705 codeMirror.replaceSelections(replacements); | 705 codeMirror.replaceSelections(replacements); |
706 selections = codeMirror.listSelections(); | 706 selections = codeMirror.listSelections(); |
707 replacements = []; | 707 replacements = []; |
708 var updatedSelections = []; | 708 var updatedSelections = []; |
709 for (var i = 0; i < selections.length; ++i) { | 709 for (var i = 0; i < selections.length; ++i) { |
710 var selection = selections[i]; | 710 var selection = selections[i]; |
711 var matchingBracket = codeMirror.findMatchingBracket(selection.head); | 711 var matchingBracket = codeMirror.findMatchingBracket(selection.head); |
712 if (!matchingBracket || !matchingBracket.match) | 712 if (!matchingBracket || !matchingBracket.match) |
713 return; | 713 return; |
714 updatedSelections.push({head: selection.head, anchor: new CodeMirror.Pos(s
election.head.line, 0)}); | 714 updatedSelections.push({head: selection.head, anchor: new CodeMirror.Pos(s
election.head.line, 0)}); |
715 var line = codeMirror.getLine(matchingBracket.to.line); | 715 var line = codeMirror.getLine(matchingBracket.to.line); |
716 var indent = Common.TextUtils.lineIndent(line); | 716 var indent = TextUtils.TextUtils.lineIndent(line); |
717 replacements.push(indent + '}'); | 717 replacements.push(indent + '}'); |
718 } | 718 } |
719 codeMirror.setSelections(updatedSelections); | 719 codeMirror.setSelections(updatedSelections); |
720 codeMirror.replaceSelections(replacements); | 720 codeMirror.replaceSelections(replacements); |
721 } | 721 } |
722 }; | 722 }; |
723 | 723 |
724 | 724 |
725 /** | 725 /** |
726 * @unrestricted | 726 * @unrestricted |
727 */ | 727 */ |
728 SourceFrame.SourcesTextEditor.TokenHighlighter = class { | 728 SourceFrame.SourcesTextEditor.TokenHighlighter = class { |
729 /** | 729 /** |
730 * @param {!SourceFrame.SourcesTextEditor} textEditor | 730 * @param {!SourceFrame.SourcesTextEditor} textEditor |
731 * @param {!CodeMirror} codeMirror | 731 * @param {!CodeMirror} codeMirror |
732 */ | 732 */ |
733 constructor(textEditor, codeMirror) { | 733 constructor(textEditor, codeMirror) { |
734 this._textEditor = textEditor; | 734 this._textEditor = textEditor; |
735 this._codeMirror = codeMirror; | 735 this._codeMirror = codeMirror; |
736 } | 736 } |
737 | 737 |
738 /** | 738 /** |
739 * @param {!RegExp} regex | 739 * @param {!RegExp} regex |
740 * @param {?Common.TextRange} range | 740 * @param {?TextUtils.TextRange} range |
741 */ | 741 */ |
742 highlightSearchResults(regex, range) { | 742 highlightSearchResults(regex, range) { |
743 var oldRegex = this._highlightRegex; | 743 var oldRegex = this._highlightRegex; |
744 this._highlightRegex = regex; | 744 this._highlightRegex = regex; |
745 this._highlightRange = range; | 745 this._highlightRange = range; |
746 if (this._searchResultMarker) { | 746 if (this._searchResultMarker) { |
747 this._searchResultMarker.clear(); | 747 this._searchResultMarker.clear(); |
748 delete this._searchResultMarker; | 748 delete this._searchResultMarker; |
749 } | 749 } |
750 if (this._highlightDescriptor && this._highlightDescriptor.selectionStart) | 750 if (this._highlightDescriptor && this._highlightDescriptor.selectionStart) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 } | 799 } |
800 | 800 |
801 /** | 801 /** |
802 * @param {string} selectedText | 802 * @param {string} selectedText |
803 * @param {number} lineNumber | 803 * @param {number} lineNumber |
804 * @param {number} startColumn | 804 * @param {number} startColumn |
805 * @param {number} endColumn | 805 * @param {number} endColumn |
806 */ | 806 */ |
807 _isWord(selectedText, lineNumber, startColumn, endColumn) { | 807 _isWord(selectedText, lineNumber, startColumn, endColumn) { |
808 var line = this._codeMirror.getLine(lineNumber); | 808 var line = this._codeMirror.getLine(lineNumber); |
809 var leftBound = startColumn === 0 || !Common.TextUtils.isWordChar(line.charA
t(startColumn - 1)); | 809 var leftBound = startColumn === 0 || !TextUtils.TextUtils.isWordChar(line.ch
arAt(startColumn - 1)); |
810 var rightBound = endColumn === line.length || !Common.TextUtils.isWordChar(l
ine.charAt(endColumn)); | 810 var rightBound = endColumn === line.length || !TextUtils.TextUtils.isWordCha
r(line.charAt(endColumn)); |
811 return leftBound && rightBound && Common.TextUtils.isWord(selectedText); | 811 return leftBound && rightBound && TextUtils.TextUtils.isWord(selectedText); |
812 } | 812 } |
813 | 813 |
814 _removeHighlight() { | 814 _removeHighlight() { |
815 if (this._highlightDescriptor) { | 815 if (this._highlightDescriptor) { |
816 this._codeMirror.removeOverlay(this._highlightDescriptor.overlay); | 816 this._codeMirror.removeOverlay(this._highlightDescriptor.overlay); |
817 delete this._highlightDescriptor; | 817 delete this._highlightDescriptor; |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 /** | 821 /** |
(...skipping 28 matching lines...) Expand all Loading... |
850 } | 850 } |
851 } | 851 } |
852 | 852 |
853 /** | 853 /** |
854 * @param {string} token | 854 * @param {string} token |
855 * @param {!CodeMirror.Pos} selectionStart | 855 * @param {!CodeMirror.Pos} selectionStart |
856 * @param {!CodeMirror.StringStream} stream | 856 * @param {!CodeMirror.StringStream} stream |
857 */ | 857 */ |
858 _tokenHighlighter(token, selectionStart, stream) { | 858 _tokenHighlighter(token, selectionStart, stream) { |
859 var tokenFirstChar = token.charAt(0); | 859 var tokenFirstChar = token.charAt(0); |
860 if (stream.match(token) && (stream.eol() || !Common.TextUtils.isWordChar(str
eam.peek()))) | 860 if (stream.match(token) && (stream.eol() || !TextUtils.TextUtils.isWordChar(
stream.peek()))) |
861 return stream.column() === selectionStart.ch ? 'token-highlight column-wit
h-selection' : 'token-highlight'; | 861 return stream.column() === selectionStart.ch ? 'token-highlight column-wit
h-selection' : 'token-highlight'; |
862 var eatenChar; | 862 var eatenChar; |
863 do | 863 do |
864 eatenChar = stream.next(); | 864 eatenChar = stream.next(); |
865 while (eatenChar && (Common.TextUtils.isWordChar(eatenChar) || stream.peek()
!== tokenFirstChar)); | 865 while (eatenChar && (TextUtils.TextUtils.isWordChar(eatenChar) || stream.pee
k() !== tokenFirstChar)); |
866 } | 866 } |
867 | 867 |
868 /** | 868 /** |
869 * @param {function(!CodeMirror.StringStream)} highlighter | 869 * @param {function(!CodeMirror.StringStream)} highlighter |
870 * @param {?CodeMirror.Pos} selectionStart | 870 * @param {?CodeMirror.Pos} selectionStart |
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 |