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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighligh
ter(this._codeMirror); | 145 this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighligh
ter(this._codeMirror); |
146 this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockInd
entController(this._codeMirror); | 146 this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockInd
entController(this._codeMirror); |
147 this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovemen
t(this._codeMirror); | 147 this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovemen
t(this._codeMirror); |
148 this._autocompleteController = new WebInspector.CodeMirrorTextEditor.Autocom
pleteController(this, this._codeMirror); | 148 this._autocompleteController = new WebInspector.CodeMirrorTextEditor.Autocom
pleteController(this, this._codeMirror); |
149 | 149 |
150 this._codeMirror.on("change", this._change.bind(this)); | 150 this._codeMirror.on("change", this._change.bind(this)); |
151 this._codeMirror.on("beforeChange", this._beforeChange.bind(this)); | 151 this._codeMirror.on("beforeChange", this._beforeChange.bind(this)); |
152 this._codeMirror.on("gutterClick", this._gutterClick.bind(this)); | 152 this._codeMirror.on("gutterClick", this._gutterClick.bind(this)); |
153 this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this)); | 153 this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this)); |
| 154 this._codeMirror.on("beforeSelectionChange", this._beforeSelectionChange.bin
d(this)); |
154 this._codeMirror.on("scroll", this._scroll.bind(this)); | 155 this._codeMirror.on("scroll", this._scroll.bind(this)); |
155 this._codeMirror.on("focus", this._focus.bind(this)); | 156 this._codeMirror.on("focus", this._focus.bind(this)); |
156 this._codeMirror.on("blur", this._blur.bind(this)); | 157 this._codeMirror.on("blur", this._blur.bind(this)); |
157 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f
alse); | 158 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f
alse); |
| 159 /** |
| 160 * @this {WebInspector.CodeMirrorTextEditor} |
| 161 */ |
| 162 function updateAnticipateJumpFlag(value) |
| 163 { |
| 164 this._anticipateJump = value; |
| 165 } |
| 166 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, true), true); |
| 167 this.element.addEventListener("mousedown", updateAnticipateJumpFlag.bind(thi
s, false), false); |
158 | 168 |
159 this.element.classList.add("fill"); | 169 this.element.classList.add("fill"); |
160 this.element.style.overflow = "hidden"; | 170 this.element.style.overflow = "hidden"; |
161 this.element.firstChild.classList.add("source-code"); | 171 this.element.firstChild.classList.add("source-code"); |
162 this.element.firstChild.classList.add("fill"); | 172 this.element.firstChild.classList.add("fill"); |
163 this._elementToWidget = new Map(); | 173 this._elementToWidget = new Map(); |
164 this._nestedUpdatesCounter = 0; | 174 this._nestedUpdatesCounter = 0; |
165 | 175 |
166 this.element.addEventListener("focus", this._handleElementFocus.bind(this),
false); | 176 this.element.addEventListener("focus", this._handleElementFocus.bind(this),
false); |
167 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru
e); | 177 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru
e); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl
ightLength) | 332 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl
ightLength) |
323 this.setSelection(range); | 333 this.setSelection(range); |
324 else | 334 else |
325 this.setSelection(WebInspector.TextRange.createFromLocation(
range.startLine, range.startColumn)); | 335 this.setSelection(WebInspector.TextRange.createFromLocation(
range.startLine, range.startColumn)); |
326 } else { | 336 } else { |
327 // Collapse selection to end on search start so that we jump to
next occurence on the first enter press. | 337 // Collapse selection to end on search start so that we jump to
next occurence on the first enter press. |
328 this.setSelection(this.selection().collapseToEnd()); | 338 this.setSelection(this.selection().collapseToEnd()); |
329 } | 339 } |
330 this._tokenHighlighter.highlightSearchResults(regex, range); | 340 this._tokenHighlighter.highlightSearchResults(regex, range); |
331 } | 341 } |
| 342 if (!this._presearchSelection) |
| 343 this._presearchSelection = this.selection(); |
332 this._codeMirror.operation(innerHighlightRegex.bind(this)); | 344 this._codeMirror.operation(innerHighlightRegex.bind(this)); |
333 }, | 345 }, |
334 | 346 |
335 cancelSearchResultsHighlight: function() | 347 cancelSearchResultsHighlight: function() |
336 { | 348 { |
337 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedToken
s.bind(this._tokenHighlighter)); | 349 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedToken
s.bind(this._tokenHighlighter)); |
| 350 if (this._presearchSelection) { |
| 351 this._reportJump(this._presearchSelection, this.selection()); |
| 352 delete this._presearchSelection; |
| 353 } |
338 }, | 354 }, |
339 | 355 |
340 undo: function() | 356 undo: function() |
341 { | 357 { |
342 this._codeMirror.undo(); | 358 this._codeMirror.undo(); |
343 }, | 359 }, |
344 | 360 |
345 redo: function() | 361 redo: function() |
346 { | 362 { |
347 this._codeMirror.redo(); | 363 this._codeMirror.redo(); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 columnNumber = 0; | 803 columnNumber = 0; |
788 | 804 |
789 this.clearPositionHighlight(); | 805 this.clearPositionHighlight(); |
790 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); | 806 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); |
791 if (!this._highlightedLine) | 807 if (!this._highlightedLine) |
792 return; | 808 return; |
793 this.revealLine(lineNumber); | 809 this.revealLine(lineNumber); |
794 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight
"); | 810 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight
"); |
795 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin
d(this), 2000); | 811 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin
d(this), 2000); |
796 if (!this.readOnly()) | 812 if (!this.readOnly()) |
797 this._codeMirror.setSelection(new CodeMirror.Pos(lineNumber, columnN
umber)); | 813 this.setSelection(WebInspector.TextRange.createFromLocation(lineNumb
er, columnNumber)); |
798 }, | 814 }, |
799 | 815 |
800 clearPositionHighlight: function() | 816 clearPositionHighlight: function() |
801 { | 817 { |
802 if (this._clearHighlightTimeout) | 818 if (this._clearHighlightTimeout) |
803 clearTimeout(this._clearHighlightTimeout); | 819 clearTimeout(this._clearHighlightTimeout); |
804 delete this._clearHighlightTimeout; | 820 delete this._clearHighlightTimeout; |
805 | 821 |
806 if (this._highlightedLine) | 822 if (this._highlightedLine) |
807 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi
ghlight"); | 823 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi
ghlight"); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 | 985 |
970 _cursorActivity: function() | 986 _cursorActivity: function() |
971 { | 987 { |
972 var start = this._codeMirror.getCursor("anchor"); | 988 var start = this._codeMirror.getCursor("anchor"); |
973 var end = this._codeMirror.getCursor("head"); | 989 var end = this._codeMirror.getCursor("head"); |
974 this._delegate.selectionChanged(this._toRange(start, end)); | 990 this._delegate.selectionChanged(this._toRange(start, end)); |
975 if (!this._tokenHighlighter.highlightedRegex()) | 991 if (!this._tokenHighlighter.highlightedRegex()) |
976 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT
okens.bind(this._tokenHighlighter)); | 992 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT
okens.bind(this._tokenHighlighter)); |
977 }, | 993 }, |
978 | 994 |
| 995 /** |
| 996 * @param {!CodeMirror} codeMirror |
| 997 * @param {!{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}} selection |
| 998 */ |
| 999 _beforeSelectionChange: function(codeMirror, selection) |
| 1000 { |
| 1001 if (!this._anticipateJump) |
| 1002 return; |
| 1003 this._reportJump(this.selection(), this._toRange(selection.anchor, selec
tion.head)); |
| 1004 }, |
| 1005 |
| 1006 /** |
| 1007 * @param {?WebInspector.TextRange} from |
| 1008 * @param {?WebInspector.TextRange} to |
| 1009 */ |
| 1010 _reportJump: function(from, to) |
| 1011 { |
| 1012 if (from && to && from.equal(to)) |
| 1013 return; |
| 1014 this._delegate.onJumpToPosition(from, to); |
| 1015 }, |
| 1016 |
979 _scroll: function() | 1017 _scroll: function() |
980 { | 1018 { |
981 if (this._scrollTimer) | 1019 if (this._scrollTimer) |
982 clearTimeout(this._scrollTimer); | 1020 clearTimeout(this._scrollTimer); |
983 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g
etScrollInfo().top, "local"); | 1021 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g
etScrollInfo().top, "local"); |
984 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d
elegate, topmostLineNumber), 100); | 1022 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d
elegate, topmostLineNumber), 100); |
985 }, | 1023 }, |
986 | 1024 |
987 _focus: function() | 1025 _focus: function() |
988 { | 1026 { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 start: new CodeMirror.Pos(range.startLine, range.startColumn), | 1197 start: new CodeMirror.Pos(range.startLine, range.startColumn), |
1160 end: new CodeMirror.Pos(range.endLine, range.endColumn) | 1198 end: new CodeMirror.Pos(range.endLine, range.endColumn) |
1161 } | 1199 } |
1162 }, | 1200 }, |
1163 | 1201 |
1164 _toRange: function(start, end) | 1202 _toRange: function(start, end) |
1165 { | 1203 { |
1166 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch
); | 1204 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch
); |
1167 }, | 1205 }, |
1168 | 1206 |
| 1207 /** |
| 1208 * @param {number} lineNumber |
| 1209 * @param {number} columnNumber |
| 1210 * @return {!WebInspector.TextEditorPositionHandle} |
| 1211 */ |
| 1212 textEditorPositionHandle: function(lineNumber, columnNumber) |
| 1213 { |
| 1214 return new WebInspector.CodeMirrorPositionHandle(this._codeMirror, new C
odeMirror.Pos(lineNumber, columnNumber)); |
| 1215 }, |
| 1216 |
1169 __proto__: WebInspector.View.prototype | 1217 __proto__: WebInspector.View.prototype |
1170 } | 1218 } |
1171 | 1219 |
1172 /** | 1220 /** |
1173 * @constructor | 1221 * @constructor |
| 1222 * @implements {WebInspector.TextEditorPositionHandle} |
| 1223 * @param {!CodeMirror} codeMirror |
| 1224 * @param {!CodeMirror.Pos} pos |
| 1225 */ |
| 1226 WebInspector.CodeMirrorPositionHandle = function(codeMirror, pos) |
| 1227 { |
| 1228 this._codeMirror = codeMirror; |
| 1229 this._lineHandle = codeMirror.getLineHandle(pos.line); |
| 1230 this._columnNumber = pos.ch; |
| 1231 } |
| 1232 |
| 1233 WebInspector.CodeMirrorPositionHandle.prototype = { |
| 1234 /** |
| 1235 * @return {?{lineNumber: number, columnNumber: number}} |
| 1236 */ |
| 1237 resolve: function() |
| 1238 { |
| 1239 var lineNumber = this._codeMirror.getLineNumber(this._lineHandle); |
| 1240 if (typeof lineNumber !== "number") |
| 1241 return null; |
| 1242 return { |
| 1243 lineNumber: lineNumber, |
| 1244 columnNumber: this._columnNumber |
| 1245 }; |
| 1246 }, |
| 1247 |
| 1248 /** |
| 1249 * @param {!WebInspector.TextEditorPositionHandle} positionHandle |
| 1250 * @return {boolean} |
| 1251 */ |
| 1252 equal: function(positionHandle) |
| 1253 { |
| 1254 return positionHandle._lineHandle === this._lineHandle && positionHandle
._columnNumber == this._columnNumber && positionHandle._codeMirror === this._cod
eMirror; |
| 1255 } |
| 1256 } |
| 1257 |
| 1258 /** |
| 1259 * @constructor |
1174 * @param {!CodeMirror} codeMirror | 1260 * @param {!CodeMirror} codeMirror |
1175 */ | 1261 */ |
1176 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) | 1262 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) |
1177 { | 1263 { |
1178 this._codeMirror = codeMirror; | 1264 this._codeMirror = codeMirror; |
1179 } | 1265 } |
1180 | 1266 |
1181 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { | 1267 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { |
1182 /** | 1268 /** |
1183 * @param {!RegExp} regex | 1269 * @param {!RegExp} regex |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 * @param {number} line | 1659 * @param {number} line |
1574 * @param {number} column | 1660 * @param {number} column |
1575 * @return {?AnchorBox} | 1661 * @return {?AnchorBox} |
1576 */ | 1662 */ |
1577 _anchorBoxForPosition: function(line, column) | 1663 _anchorBoxForPosition: function(line, column) |
1578 { | 1664 { |
1579 var metrics = this._textEditor.cursorPositionToCoordinates(line, column)
; | 1665 var metrics = this._textEditor.cursorPositionToCoordinates(line, column)
; |
1580 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height)
: null; | 1666 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height)
: null; |
1581 }, | 1667 }, |
1582 } | 1668 } |
OLD | NEW |