OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 this._nestedUpdatesCounter = 0; | 175 this._nestedUpdatesCounter = 0; |
176 | 176 |
177 this.element.addEventListener("focus", this._handleElementFocus.bind(this), false); | 177 this.element.addEventListener("focus", this._handleElementFocus.bind(this), false); |
178 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru e); | 178 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru e); |
179 this.element.addEventListener("keydown", this._handlePostKeyDown.bind(this), false); | 179 this.element.addEventListener("keydown", this._handlePostKeyDown.bind(this), false); |
180 this.element.tabIndex = 0; | 180 this.element.tabIndex = 0; |
181 | 181 |
182 this._setupWhitespaceHighlight(); | 182 this._setupWhitespaceHighlight(); |
183 } | 183 } |
184 | 184 |
185 /** @typedef {{canceled: boolean, from: CodeMirror.Pos, to: CodeMirror.Pos, text : string, origin: string, cancel: function()}} */ | 185 /** @typedef {{canceled: boolean, from: !CodeMirror.Pos, to: !CodeMirror.Pos, te xt: string, origin: string, cancel: function()}} */ |
186 WebInspector.CodeMirrorTextEditor.BeforeChangeObject; | 186 WebInspector.CodeMirrorTextEditor.BeforeChangeObject; |
187 | 187 |
188 /** @typedef {{from: CodeMirror.Pos, to: CodeMirror.Pos, origin: string, text: ! Array.<string>, removed: !Array.<string>}} */ | 188 /** @typedef {{from: !CodeMirror.Pos, to: !CodeMirror.Pos, origin: string, text: !Array.<string>, removed: !Array.<string>}} */ |
189 WebInspector.CodeMirrorTextEditor.ChangeObject; | 189 WebInspector.CodeMirrorTextEditor.ChangeObject; |
190 | 190 |
191 WebInspector.CodeMirrorTextEditor.maxHighlightLength = 1000; | 191 WebInspector.CodeMirrorTextEditor.maxHighlightLength = 1000; |
192 | 192 |
193 /** | 193 /** |
194 * @param {!CodeMirror} codeMirror | 194 * @param {!CodeMirror} codeMirror |
195 */ | 195 */ |
196 WebInspector.CodeMirrorTextEditor.autocompleteCommand = function(codeMirror) | 196 WebInspector.CodeMirrorTextEditor.autocompleteCommand = function(codeMirror) |
197 { | 197 { |
198 codeMirror._codeMirrorTextEditor._autocompleteController.autocomplete(); | 198 codeMirror._codeMirrorTextEditor._autocompleteController.autocomplete(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 257 |
258 CodeMirror.commands.redoAndReveal = function(codemirror) | 258 CodeMirror.commands.redoAndReveal = function(codemirror) |
259 { | 259 { |
260 var scrollInfo = codemirror.getScrollInfo(); | 260 var scrollInfo = codemirror.getScrollInfo(); |
261 codemirror.execCommand("redo"); | 261 codemirror.execCommand("redo"); |
262 var cursor = codemirror.getCursor("start"); | 262 var cursor = codemirror.getCursor("start"); |
263 codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); | 263 codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); |
264 codemirror._codeMirrorTextEditor._autocompleteController.finishAutocomplete( ); | 264 codemirror._codeMirrorTextEditor._autocompleteController.finishAutocomplete( ); |
265 } | 265 } |
266 | 266 |
267 CodeMirror.commands.dismissMultipleSelections = function(codemirror) | 267 CodeMirror.commands.dismissMultipleSelections = function(codemirror) |
pfeldman
2014/04/14 13:00:34
Annotate?
| |
268 { | 268 { |
269 if (codemirror.getSelections().length <= 1) | 269 var selections = codemirror.listSelections(); |
270 return CodeMirror.Pass; | 270 var selection = selections[0]; |
271 var range = codemirror.listSelections()[0]; | 271 if (selections.length === 1) { |
272 codemirror.setSelection(range.anchor, range.head, {scroll: false}); | 272 if (WebInspector.CodeMirrorUtils.toRange(selection.anchor, selection.hea d).isEmpty()) |
273 codemirror._codeMirrorTextEditor._revealLine(range.anchor.line); | 273 return CodeMirror.Pass; |
274 codemirror.setSelection(selection.anchor, selection.anchor, {scroll: fal se}); | |
275 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); | |
276 return; | |
277 } | |
278 | |
279 codemirror.setSelection(selection.anchor, selection.head, {scroll: false}); | |
280 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); | |
274 } | 281 } |
275 | 282 |
276 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; | 283 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; |
277 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 284 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
278 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; | 285 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; |
279 | 286 |
280 WebInspector.CodeMirrorTextEditor.prototype = { | 287 WebInspector.CodeMirrorTextEditor.prototype = { |
281 _enableBracketMatchingIfNeeded: function() | 288 _enableBracketMatchingIfNeeded: function() |
282 { | 289 { |
283 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false); | 290 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 coordinatesToCursorPosition: function(x, y) | 486 coordinatesToCursorPosition: function(x, y) |
480 { | 487 { |
481 var element = document.elementFromPoint(x, y); | 488 var element = document.elementFromPoint(x, y); |
482 if (!element || !element.isSelfOrDescendant(this._codeMirror.getWrapperE lement())) | 489 if (!element || !element.isSelfOrDescendant(this._codeMirror.getWrapperE lement())) |
483 return null; | 490 return null; |
484 var gutterBox = this._codeMirror.getGutterElement().boxInWindow(); | 491 var gutterBox = this._codeMirror.getGutterElement().boxInWindow(); |
485 if (x >= gutterBox.x && x <= gutterBox.x + gutterBox.width && | 492 if (x >= gutterBox.x && x <= gutterBox.x + gutterBox.width && |
486 y >= gutterBox.y && y <= gutterBox.y + gutterBox.height) | 493 y >= gutterBox.y && y <= gutterBox.y + gutterBox.height) |
487 return null; | 494 return null; |
488 var coords = this._codeMirror.coordsChar({left: x, top: y}); | 495 var coords = this._codeMirror.coordsChar({left: x, top: y}); |
489 return this._toRange(coords, coords); | 496 return WebInspector.CodeMirrorUtils.toRange(coords, coords); |
490 }, | 497 }, |
491 | 498 |
492 /** | 499 /** |
493 * @param {number} lineNumber | 500 * @param {number} lineNumber |
494 * @param {number} column | 501 * @param {number} column |
495 * @return {?{startColumn: number, endColumn: number, type: string}} | 502 * @return {?{startColumn: number, endColumn: number, type: string}} |
496 */ | 503 */ |
497 tokenAtTextPosition: function(lineNumber, column) | 504 tokenAtTextPosition: function(lineNumber, column) |
498 { | 505 { |
499 if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) | 506 if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) |
500 return null; | 507 return null; |
501 var token = this._codeMirror.getTokenAt(new CodeMirror.Pos(lineNumber, ( column || 0) + 1)); | 508 var token = this._codeMirror.getTokenAt(new CodeMirror.Pos(lineNumber, ( column || 0) + 1)); |
502 if (!token || !token.type) | 509 if (!token || !token.type) |
503 return null; | 510 return null; |
504 return { | 511 return { |
505 startColumn: token.start, | 512 startColumn: token.start, |
506 endColumn: token.end - 1, | 513 endColumn: token.end - 1, |
507 type: token.type | 514 type: token.type |
508 }; | 515 }; |
509 }, | 516 }, |
510 | 517 |
511 /** | 518 /** |
512 * @param {!WebInspector.TextRange} textRange | 519 * @param {!WebInspector.TextRange} textRange |
513 * @return {string} | 520 * @return {string} |
514 */ | 521 */ |
515 copyRange: function(textRange) | 522 copyRange: function(textRange) |
516 { | 523 { |
517 var pos = this._toPos(textRange.normalize()); | 524 var pos = WebInspector.CodeMirrorUtils.toPos(textRange.normalize()); |
518 return this._codeMirror.getRange(pos.start, pos.end); | 525 return this._codeMirror.getRange(pos.start, pos.end); |
519 }, | 526 }, |
520 | 527 |
521 /** | 528 /** |
522 * @return {boolean} | 529 * @return {boolean} |
523 */ | 530 */ |
524 isClean: function() | 531 isClean: function() |
525 { | 532 { |
526 return this._codeMirror.isClean(); | 533 return this._codeMirror.isClean(); |
527 }, | 534 }, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 }, | 646 }, |
640 | 647 |
641 /** | 648 /** |
642 * @param {!WebInspector.TextRange} range | 649 * @param {!WebInspector.TextRange} range |
643 * @param {string} cssClass | 650 * @param {string} cssClass |
644 * @return {!Object} | 651 * @return {!Object} |
645 */ | 652 */ |
646 highlightRange: function(range, cssClass) | 653 highlightRange: function(range, cssClass) |
647 { | 654 { |
648 cssClass = "CodeMirror-persist-highlight " + cssClass; | 655 cssClass = "CodeMirror-persist-highlight " + cssClass; |
649 var pos = this._toPos(range); | 656 var pos = WebInspector.CodeMirrorUtils.toPos(range); |
650 ++pos.end.ch; | 657 ++pos.end.ch; |
651 return this._codeMirror.markText(pos.start, pos.end, { | 658 return this._codeMirror.markText(pos.start, pos.end, { |
652 className: cssClass, | 659 className: cssClass, |
653 startStyle: cssClass + "-start", | 660 startStyle: cssClass + "-start", |
654 endStyle: cssClass + "-end" | 661 endStyle: cssClass + "-end" |
655 }); | 662 }); |
656 }, | 663 }, |
657 | 664 |
658 /** | 665 /** |
659 * @return {!Element} | 666 * @return {!Element} |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 this._resizeEditor(); | 893 this._resizeEditor(); |
887 }, | 894 }, |
888 | 895 |
889 /** | 896 /** |
890 * @param {!WebInspector.TextRange} range | 897 * @param {!WebInspector.TextRange} range |
891 * @param {string} text | 898 * @param {string} text |
892 * @return {!WebInspector.TextRange} | 899 * @return {!WebInspector.TextRange} |
893 */ | 900 */ |
894 editRange: function(range, text) | 901 editRange: function(range, text) |
895 { | 902 { |
896 var pos = this._toPos(range); | 903 var pos = WebInspector.CodeMirrorUtils.toPos(range); |
897 this._codeMirror.replaceRange(text, pos.start, pos.end); | 904 this._codeMirror.replaceRange(text, pos.start, pos.end); |
898 var newRange = this._toRange(pos.start, this._codeMirror.posFromIndex(th is._codeMirror.indexFromPos(pos.start) + text.length)); | 905 var newRange = WebInspector.CodeMirrorUtils.toRange(pos.start, this._cod eMirror.posFromIndex(this._codeMirror.indexFromPos(pos.start) + text.length)); |
899 this._delegate.onTextChanged(range, newRange); | 906 this._delegate.onTextChanged(range, newRange); |
900 if (WebInspector.settings.textEditorAutoDetectIndent.get()) | 907 if (WebInspector.settings.textEditorAutoDetectIndent.get()) |
901 this._updateEditorIndentation(); | 908 this._updateEditorIndentation(); |
902 return newRange; | 909 return newRange; |
903 }, | 910 }, |
904 | 911 |
905 /** | 912 /** |
906 * @param {number} lineNumber | 913 * @param {number} lineNumber |
907 * @param {number} column | 914 * @param {number} column |
908 * @param {function(string):boolean} isWordChar | 915 * @param {function(string):boolean} isWordChar |
(...skipping 13 matching lines...) Expand all Loading... | |
922 ++wordEnd; | 929 ++wordEnd; |
923 return new WebInspector.TextRange(lineNumber, wordStart, lineNumber, wor dEnd); | 930 return new WebInspector.TextRange(lineNumber, wordStart, lineNumber, wor dEnd); |
924 }, | 931 }, |
925 | 932 |
926 /** | 933 /** |
927 * @param {!WebInspector.CodeMirrorTextEditor.ChangeObject} changeObject | 934 * @param {!WebInspector.CodeMirrorTextEditor.ChangeObject} changeObject |
928 * @return {{oldRange: !WebInspector.TextRange, newRange: !WebInspector.Text Range}} | 935 * @return {{oldRange: !WebInspector.TextRange, newRange: !WebInspector.Text Range}} |
929 */ | 936 */ |
930 _changeObjectToEditOperation: function(changeObject) | 937 _changeObjectToEditOperation: function(changeObject) |
931 { | 938 { |
932 var oldRange = this._toRange(changeObject.from, changeObject.to); | 939 var oldRange = WebInspector.CodeMirrorUtils.toRange(changeObject.from, c hangeObject.to); |
933 var newRange = oldRange.clone(); | 940 var newRange = oldRange.clone(); |
934 var linesAdded = changeObject.text.length; | 941 var linesAdded = changeObject.text.length; |
935 if (linesAdded === 0) { | 942 if (linesAdded === 0) { |
936 newRange.endLine = newRange.startLine; | 943 newRange.endLine = newRange.startLine; |
937 newRange.endColumn = newRange.startColumn; | 944 newRange.endColumn = newRange.startColumn; |
938 } else if (linesAdded === 1) { | 945 } else if (linesAdded === 1) { |
939 newRange.endLine = newRange.startLine; | 946 newRange.endLine = newRange.startLine; |
940 newRange.endColumn = newRange.startColumn + changeObject.text[0].len gth; | 947 newRange.endColumn = newRange.startColumn + changeObject.text[0].len gth; |
941 } else { | 948 } else { |
942 newRange.endLine = newRange.startLine + linesAdded - 1; | 949 newRange.endLine = newRange.startLine + linesAdded - 1; |
(...skipping 29 matching lines...) Expand all Loading... | |
972 var editInfo = this._changeObjectToEditOperation(changeObject); | 979 var editInfo = this._changeObjectToEditOperation(changeObject); |
973 if (!this._muteTextChangedEvent) | 980 if (!this._muteTextChangedEvent) |
974 this._delegate.onTextChanged(editInfo.oldRange, editInfo.newRang e); | 981 this._delegate.onTextChanged(editInfo.oldRange, editInfo.newRang e); |
975 } | 982 } |
976 }, | 983 }, |
977 | 984 |
978 _cursorActivity: function() | 985 _cursorActivity: function() |
979 { | 986 { |
980 var start = this._codeMirror.getCursor("anchor"); | 987 var start = this._codeMirror.getCursor("anchor"); |
981 var end = this._codeMirror.getCursor("head"); | 988 var end = this._codeMirror.getCursor("head"); |
982 this._delegate.selectionChanged(this._toRange(start, end)); | 989 this._delegate.selectionChanged(WebInspector.CodeMirrorUtils.toRange(sta rt, end)); |
983 if (!this._tokenHighlighter.highlightedRegex()) | 990 if (!this._tokenHighlighter.highlightedRegex()) |
984 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter)); | 991 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter)); |
985 }, | 992 }, |
986 | 993 |
987 /** | 994 /** |
988 * @param {!CodeMirror} codeMirror | 995 * @param {!CodeMirror} codeMirror |
989 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos} >}} selection | 996 * @param {{ranges: !Array.<{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos} >}} selection |
990 */ | 997 */ |
991 _beforeSelectionChange: function(codeMirror, selection) | 998 _beforeSelectionChange: function(codeMirror, selection) |
992 { | 999 { |
993 this._selectNextOccurrenceController.selectionWillChange(); | 1000 this._selectNextOccurrenceController.selectionWillChange(); |
994 if (!this._isHandlingMouseDownEvent) | 1001 if (!this._isHandlingMouseDownEvent) |
995 return; | 1002 return; |
996 if (!selection.ranges.length) | 1003 if (!selection.ranges.length) |
997 return; | 1004 return; |
998 var primarySelection = selection.ranges[0]; | 1005 var primarySelection = selection.ranges[0]; |
999 this._reportJump(this.selection(), this._toRange(primarySelection.anchor , primarySelection.head)); | 1006 this._reportJump(this.selection(), WebInspector.CodeMirrorUtils.toRange( primarySelection.anchor, primarySelection.head)); |
1000 }, | 1007 }, |
1001 | 1008 |
1002 /** | 1009 /** |
1003 * @param {?WebInspector.TextRange} from | 1010 * @param {?WebInspector.TextRange} from |
1004 * @param {?WebInspector.TextRange} to | 1011 * @param {?WebInspector.TextRange} to |
1005 */ | 1012 */ |
1006 _reportJump: function(from, to) | 1013 _reportJump: function(from, to) |
1007 { | 1014 { |
1008 if (from && to && from.equal(to)) | 1015 if (from && to && from.equal(to)) |
1009 return; | 1016 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1051 }, | 1058 }, |
1052 | 1059 |
1053 /** | 1060 /** |
1054 * @return {!WebInspector.TextRange} | 1061 * @return {!WebInspector.TextRange} |
1055 */ | 1062 */ |
1056 selection: function() | 1063 selection: function() |
1057 { | 1064 { |
1058 var start = this._codeMirror.getCursor("anchor"); | 1065 var start = this._codeMirror.getCursor("anchor"); |
1059 var end = this._codeMirror.getCursor("head"); | 1066 var end = this._codeMirror.getCursor("head"); |
1060 | 1067 |
1061 return this._toRange(start, end); | 1068 return WebInspector.CodeMirrorUtils.toRange(start, end); |
1062 }, | 1069 }, |
1063 | 1070 |
1064 /** | 1071 /** |
1065 * @return {!Array.<!WebInspector.TextRange>} | 1072 * @return {!Array.<!WebInspector.TextRange>} |
1066 */ | 1073 */ |
1067 selections: function() | 1074 selections: function() |
1068 { | 1075 { |
1069 var selectionList = this._codeMirror.listSelections(); | 1076 var selectionList = this._codeMirror.listSelections(); |
1070 var result = []; | 1077 var result = []; |
1071 for (var i = 0; i < selectionList.length; ++i) { | 1078 for (var i = 0; i < selectionList.length; ++i) { |
1072 var selection = selectionList[i]; | 1079 var selection = selectionList[i]; |
1073 result.push(this._toRange(selection.anchor, selection.head)); | 1080 result.push(WebInspector.CodeMirrorUtils.toRange(selection.anchor, s election.head)); |
1074 } | 1081 } |
1075 return result; | 1082 return result; |
1076 }, | 1083 }, |
1077 | 1084 |
1078 /** | 1085 /** |
1079 * @return {?WebInspector.TextRange} | 1086 * @return {?WebInspector.TextRange} |
1080 */ | 1087 */ |
1081 lastSelection: function() | 1088 lastSelection: function() |
1082 { | 1089 { |
1083 return this._lastSelection; | 1090 return this._lastSelection; |
1084 }, | 1091 }, |
1085 | 1092 |
1086 /** | 1093 /** |
1087 * @param {!WebInspector.TextRange} textRange | 1094 * @param {!WebInspector.TextRange} textRange |
1088 */ | 1095 */ |
1089 setSelection: function(textRange) | 1096 setSelection: function(textRange) |
1090 { | 1097 { |
1091 this._lastSelection = textRange; | 1098 this._lastSelection = textRange; |
1092 var pos = this._toPos(textRange); | 1099 var pos = WebInspector.CodeMirrorUtils.toPos(textRange); |
1093 this._codeMirror.setSelection(pos.start, pos.end); | 1100 this._codeMirror.setSelection(pos.start, pos.end); |
1094 }, | 1101 }, |
1095 | 1102 |
1096 /** | 1103 /** |
1097 * @param {!Array.<!WebInspector.TextRange>} ranges | 1104 * @param {!Array.<!WebInspector.TextRange>} ranges |
1098 * @param {number=} primarySelectionIndex | 1105 * @param {number=} primarySelectionIndex |
1099 */ | 1106 */ |
1100 setSelections: function(ranges, primarySelectionIndex) | 1107 setSelections: function(ranges, primarySelectionIndex) |
1101 { | 1108 { |
1102 var selections = []; | 1109 var selections = []; |
1103 for (var i = 0; i < ranges.length; ++i) { | 1110 for (var i = 0; i < ranges.length; ++i) { |
1104 var selection = this._toPos(ranges[i]); | 1111 var selection = WebInspector.CodeMirrorUtils.toPos(ranges[i]); |
1105 selections.push({ | 1112 selections.push({ |
1106 anchor: selection.start, | 1113 anchor: selection.start, |
1107 head: selection.end | 1114 head: selection.end |
1108 }); | 1115 }); |
1109 } | 1116 } |
1110 primarySelectionIndex = primarySelectionIndex || 0; | 1117 primarySelectionIndex = primarySelectionIndex || 0; |
1111 this._codeMirror.setSelections(selections, primarySelectionIndex, { scro ll: false }); | 1118 this._codeMirror.setSelections(selections, primarySelectionIndex, { scro ll: false }); |
1112 }, | 1119 }, |
1113 | 1120 |
1114 /** | 1121 /** |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 return this._codeMirror.getValue().replace(/\n/g, this._lineSeparator); | 1154 return this._codeMirror.getValue().replace(/\n/g, this._lineSeparator); |
1148 }, | 1155 }, |
1149 | 1156 |
1150 /** | 1157 /** |
1151 * @return {!WebInspector.TextRange} | 1158 * @return {!WebInspector.TextRange} |
1152 */ | 1159 */ |
1153 range: function() | 1160 range: function() |
1154 { | 1161 { |
1155 var lineCount = this.linesCount; | 1162 var lineCount = this.linesCount; |
1156 var lastLine = this._codeMirror.getLine(lineCount - 1); | 1163 var lastLine = this._codeMirror.getLine(lineCount - 1); |
1157 return this._toRange(new CodeMirror.Pos(0, 0), new CodeMirror.Pos(lineCo unt - 1, lastLine.length)); | 1164 return WebInspector.CodeMirrorUtils.toRange(new CodeMirror.Pos(0, 0), ne w CodeMirror.Pos(lineCount - 1, lastLine.length)); |
1158 }, | 1165 }, |
1159 | 1166 |
1160 /** | 1167 /** |
1161 * @param {number} lineNumber | 1168 * @param {number} lineNumber |
1162 * @return {string} | 1169 * @return {string} |
1163 */ | 1170 */ |
1164 line: function(lineNumber) | 1171 line: function(lineNumber) |
1165 { | 1172 { |
1166 return this._codeMirror.getLine(lineNumber); | 1173 return this._codeMirror.getLine(lineNumber); |
1167 }, | 1174 }, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 removeAttribute: function(line, name) | 1215 removeAttribute: function(line, name) |
1209 { | 1216 { |
1210 if (line < 0 || line >= this._codeMirror.lineCount()) | 1217 if (line < 0 || line >= this._codeMirror.lineCount()) |
1211 return; | 1218 return; |
1212 var handle = this._codeMirror.getLineHandle(line); | 1219 var handle = this._codeMirror.getLineHandle(line); |
1213 if (handle && handle.attributes) | 1220 if (handle && handle.attributes) |
1214 delete handle.attributes[name]; | 1221 delete handle.attributes[name]; |
1215 }, | 1222 }, |
1216 | 1223 |
1217 /** | 1224 /** |
1218 * @param {!WebInspector.TextRange} range | |
1219 * @return {!{start: !CodeMirror.Pos, end: !CodeMirror.Pos}} | |
1220 */ | |
1221 _toPos: function(range) | |
1222 { | |
1223 return { | |
1224 start: new CodeMirror.Pos(range.startLine, range.startColumn), | |
1225 end: new CodeMirror.Pos(range.endLine, range.endColumn) | |
1226 } | |
1227 }, | |
1228 | |
1229 _toRange: function(start, end) | |
1230 { | |
1231 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch ); | |
1232 }, | |
1233 | |
1234 /** | |
1235 * @param {number} lineNumber | 1225 * @param {number} lineNumber |
1236 * @param {number} columnNumber | 1226 * @param {number} columnNumber |
1237 * @return {!WebInspector.TextEditorPositionHandle} | 1227 * @return {!WebInspector.TextEditorPositionHandle} |
1238 */ | 1228 */ |
1239 textEditorPositionHandle: function(lineNumber, columnNumber) | 1229 textEditorPositionHandle: function(lineNumber, columnNumber) |
1240 { | 1230 { |
1241 return new WebInspector.CodeMirrorPositionHandle(this._codeMirror, new C odeMirror.Pos(lineNumber, columnNumber)); | 1231 return new WebInspector.CodeMirrorPositionHandle(this._codeMirror, new C odeMirror.Pos(lineNumber, columnNumber)); |
1242 }, | 1232 }, |
1243 | 1233 |
1244 __proto__: WebInspector.VBox.prototype | 1234 __proto__: WebInspector.VBox.prototype |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line- with-selection"); | 1304 this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line- with-selection"); |
1315 if (this._highlightRegex === oldRegex) { | 1305 if (this._highlightRegex === oldRegex) { |
1316 // Do not re-add overlay mode if regex did not change for better per formance. | 1306 // Do not re-add overlay mode if regex did not change for better per formance. |
1317 if (this._highlightDescriptor) | 1307 if (this._highlightDescriptor) |
1318 this._highlightDescriptor.selectionStart = selectionStart; | 1308 this._highlightDescriptor.selectionStart = selectionStart; |
1319 } else { | 1309 } else { |
1320 this._removeHighlight(); | 1310 this._removeHighlight(); |
1321 this._setHighlighter(this._searchHighlighter.bind(this, this._highli ghtRegex), selectionStart); | 1311 this._setHighlighter(this._searchHighlighter.bind(this, this._highli ghtRegex), selectionStart); |
1322 } | 1312 } |
1323 if (this._highlightRange) { | 1313 if (this._highlightRange) { |
1324 var pos = WebInspector.CodeMirrorTextEditor.prototype._toPos(this._h ighlightRange); | 1314 var pos = WebInspector.CodeMirrorUtils.toPos(this._highlightRange); |
1325 this._searchResultMarker = this._codeMirror.markText(pos.start, pos. end, {className: "cm-column-with-selection"}); | 1315 this._searchResultMarker = this._codeMirror.markText(pos.start, pos. end, {className: "cm-column-with-selection"}); |
1326 } | 1316 } |
1327 }, | 1317 }, |
1328 | 1318 |
1329 /** | 1319 /** |
1330 * @return {!RegExp|undefined} | 1320 * @return {!RegExp|undefined} |
1331 */ | 1321 */ |
1332 highlightedRegex: function() | 1322 highlightedRegex: function() |
1333 { | 1323 { |
1334 return this._highlightRegex; | 1324 return this._highlightRegex; |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2136 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; | 2126 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; |
2137 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); | 2127 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); |
2138 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; | 2128 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; |
2139 if (!foregroundColorRule && !backgroundColorRule) | 2129 if (!foregroundColorRule && !backgroundColorRule) |
2140 return; | 2130 return; |
2141 | 2131 |
2142 var style = document.createElement("style"); | 2132 var style = document.createElement("style"); |
2143 style.textContent = backgroundColorRule + foregroundColorRule; | 2133 style.textContent = backgroundColorRule + foregroundColorRule; |
2144 document.head.appendChild(style); | 2134 document.head.appendChild(style); |
2145 })(); | 2135 })(); |
OLD | NEW |