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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 141 |
142 this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighligh ter(this._codeMirror); | 142 this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighligh ter(this._codeMirror); |
143 this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockInd entController(this._codeMirror); | 143 this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockInd entController(this._codeMirror); |
144 this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovemen t(this._codeMirror); | 144 this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovemen t(this._codeMirror); |
145 this._autocompleteController = new WebInspector.CodeMirrorTextEditor.Autocom pleteController(this, this._codeMirror); | 145 this._autocompleteController = new WebInspector.CodeMirrorTextEditor.Autocom pleteController(this, this._codeMirror); |
146 | 146 |
147 this._codeMirror.on("change", this._change.bind(this)); | 147 this._codeMirror.on("change", this._change.bind(this)); |
148 this._codeMirror.on("beforeChange", this._beforeChange.bind(this)); | 148 this._codeMirror.on("beforeChange", this._beforeChange.bind(this)); |
149 this._codeMirror.on("gutterClick", this._gutterClick.bind(this)); | 149 this._codeMirror.on("gutterClick", this._gutterClick.bind(this)); |
150 this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this)); | 150 this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this)); |
151 this._codeMirror.on("beforeSelectionChange", this._beforeSelectionChange.bin d(this)); | |
151 this._codeMirror.on("scroll", this._scroll.bind(this)); | 152 this._codeMirror.on("scroll", this._scroll.bind(this)); |
152 this._codeMirror.on("focus", this._focus.bind(this)); | 153 this._codeMirror.on("focus", this._focus.bind(this)); |
153 this._codeMirror.on("blur", this._blur.bind(this)); | 154 this._codeMirror.on("blur", this._blur.bind(this)); |
154 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f alse); | 155 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), f alse); |
156 this.element.addEventListener("mousedown", function() { | |
vsevik
2013/09/04 09:46:22
FWIW We agreed to allow anonymous function only wh
lushnikov
2014/01/02 14:06:09
Done.
| |
157 this._anticipateJump = true; | |
158 }.bind(this), true); | |
159 this.element.addEventListener("mousedown", function() { | |
vsevik
2013/09/04 09:46:22
ditto.
lushnikov
2014/01/02 14:06:09
Done.
| |
160 delete this._anticipateJump; | |
161 }.bind(this), false); | |
155 | 162 |
156 this.element.addStyleClass("fill"); | 163 this.element.addStyleClass("fill"); |
157 this.element.style.overflow = "hidden"; | 164 this.element.style.overflow = "hidden"; |
158 this.element.firstChild.addStyleClass("source-code"); | 165 this.element.firstChild.addStyleClass("source-code"); |
159 this.element.firstChild.addStyleClass("fill"); | 166 this.element.firstChild.addStyleClass("fill"); |
160 this._elementToWidget = new Map(); | 167 this._elementToWidget = new Map(); |
161 this._nestedUpdatesCounter = 0; | 168 this._nestedUpdatesCounter = 0; |
162 | 169 |
163 this.element.addEventListener("focus", this._handleElementFocus.bind(this), false); | 170 this.element.addEventListener("focus", this._handleElementFocus.bind(this), false); |
164 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru e); | 171 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru e); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 var scrollInfo = codemirror.getScrollInfo(); | 220 var scrollInfo = codemirror.getScrollInfo(); |
214 codemirror.execCommand("redo"); | 221 codemirror.execCommand("redo"); |
215 var cursor = codemirror.getCursor("start"); | 222 var cursor = codemirror.getCursor("start"); |
216 codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); | 223 codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); |
217 } | 224 } |
218 | 225 |
219 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; | 226 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; |
220 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 227 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
221 | 228 |
222 WebInspector.CodeMirrorTextEditor.prototype = { | 229 WebInspector.CodeMirrorTextEditor.prototype = { |
230 willHide: function() | |
231 { | |
232 this._reportJump(this._codeMirror.getCursor("head"), null); | |
233 }, | |
234 | |
223 wasShown: function() | 235 wasShown: function() |
224 { | 236 { |
225 this._codeMirror.refresh(); | 237 this._codeMirror.refresh(); |
238 this._reportJump(null, this._codeMirror.getCursor("head")); | |
226 }, | 239 }, |
227 | 240 |
228 _guessIndentationLevel: function() | 241 _guessIndentationLevel: function() |
229 { | 242 { |
230 var tabRegex = /^\t+/; | 243 var tabRegex = /^\t+/; |
231 var tabLines = 0; | 244 var tabLines = 0; |
232 var indents = {}; | 245 var indents = {}; |
233 function processLine(lineHandle) | 246 function processLine(lineHandle) |
234 { | 247 { |
235 var text = lineHandle.text; | 248 var text = lineHandle.text; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 if (typeof columnNumber !== "number" || columnNumber < 0 || columnNumber > this._codeMirror.getLine(lineNumber).length) | 786 if (typeof columnNumber !== "number" || columnNumber < 0 || columnNumber > this._codeMirror.getLine(lineNumber).length) |
774 columnNumber = 0; | 787 columnNumber = 0; |
775 | 788 |
776 this.clearPositionHighlight(); | 789 this.clearPositionHighlight(); |
777 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); | 790 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); |
778 if (!this._highlightedLine) | 791 if (!this._highlightedLine) |
779 return; | 792 return; |
780 this.revealLine(lineNumber); | 793 this.revealLine(lineNumber); |
781 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight "); | 794 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight "); |
782 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin d(this), 2000); | 795 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin d(this), 2000); |
783 if (!this.readOnly()) | 796 if (!this.readOnly()) { |
784 this._codeMirror.setSelection(new CodeMirror.Pos(lineNumber, columnN umber)); | 797 this._anticipateJump = true; |
798 this.setSelection(WebInspector.TextRange.createFromLocation(lineNumb er, columnNumber)); | |
799 delete this._anticipateJump; | |
800 } | |
785 }, | 801 }, |
786 | 802 |
787 clearPositionHighlight: function() | 803 clearPositionHighlight: function() |
788 { | 804 { |
789 if (this._clearHighlightTimeout) | 805 if (this._clearHighlightTimeout) |
790 clearTimeout(this._clearHighlightTimeout); | 806 clearTimeout(this._clearHighlightTimeout); |
791 delete this._clearHighlightTimeout; | 807 delete this._clearHighlightTimeout; |
792 | 808 |
793 if (this._highlightedLine) | 809 if (this._highlightedLine) |
794 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi ghlight"); | 810 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi ghlight"); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 | 979 |
964 _cursorActivity: function() | 980 _cursorActivity: function() |
965 { | 981 { |
966 var start = this._codeMirror.getCursor("anchor"); | 982 var start = this._codeMirror.getCursor("anchor"); |
967 var end = this._codeMirror.getCursor("head"); | 983 var end = this._codeMirror.getCursor("head"); |
968 this._delegate.selectionChanged(this._toRange(start, end)); | 984 this._delegate.selectionChanged(this._toRange(start, end)); |
969 if (!this._tokenHighlighter.highlightedRegex()) | 985 if (!this._tokenHighlighter.highlightedRegex()) |
970 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter)); | 986 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter)); |
971 }, | 987 }, |
972 | 988 |
989 /** | |
990 * @param {CodeMirror} codeMirror | |
991 * @param {{head: CodeMirror.Pos, anchor: CodeMirror.Pos}} selection | |
992 */ | |
993 _beforeSelectionChange: function(codeMirror, selection) | |
994 { | |
995 if (!this._anticipateJump) | |
996 return; | |
997 this._reportJump(codeMirror.getCursor("head"), selection.head) | |
vsevik
2013/09/04 09:46:22
; is missing
lushnikov
2014/01/02 14:06:09
Done.
| |
998 }, | |
999 | |
1000 /** | |
1001 * @param {?CodeMirror.Pos} from | |
1002 * @param {?CodeMirror.Pos} to | |
1003 */ | |
1004 _reportJump: function(from, to) | |
1005 { | |
1006 if (from && to && from.line === to.line && from.ch === to.ch) | |
1007 return; | |
1008 var fromHandle = from ? new WebInspector.CodeMirrorPositionHandle(this._ codeMirror, from) : null; | |
1009 var toHandle = to ? new WebInspector.CodeMirrorPositionHandle(this._code Mirror, to) : null; | |
1010 this._delegate.onJumpToPosition(fromHandle, toHandle); | |
1011 }, | |
1012 | |
973 _scroll: function() | 1013 _scroll: function() |
974 { | 1014 { |
975 if (this._scrollTimer) | 1015 if (this._scrollTimer) |
976 clearTimeout(this._scrollTimer); | 1016 clearTimeout(this._scrollTimer); |
977 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g etScrollInfo().top, "local"); | 1017 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g etScrollInfo().top, "local"); |
978 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d elegate, topmostLineNumber), 100); | 1018 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d elegate, topmostLineNumber), 100); |
979 }, | 1019 }, |
980 | 1020 |
981 _focus: function() | 1021 _focus: function() |
982 { | 1022 { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 _toRange: function(start, end) | 1198 _toRange: function(start, end) |
1159 { | 1199 { |
1160 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch ); | 1200 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch ); |
1161 }, | 1201 }, |
1162 | 1202 |
1163 __proto__: WebInspector.View.prototype | 1203 __proto__: WebInspector.View.prototype |
1164 } | 1204 } |
1165 | 1205 |
1166 /** | 1206 /** |
1167 * @constructor | 1207 * @constructor |
1208 * @implements {WebInspector.TextEditorPositionHandle} | |
1209 * @param {CodeMirror} codeMirror | |
1210 * @param {CodeMirror.Pos} pos | |
1211 */ | |
1212 WebInspector.CodeMirrorPositionHandle = function(codeMirror, pos) | |
1213 { | |
1214 this._codeMirror = codeMirror; | |
1215 this._lineHandle = codeMirror.getLineHandle(pos.line); | |
1216 this._columnNumber = pos.ch; | |
1217 } | |
1218 | |
1219 WebInspector.CodeMirrorPositionHandle.prototype = { | |
1220 /** | |
1221 * @return {?{lineNumber: number, columnNumber: number}} | |
1222 */ | |
1223 resolve: function() | |
1224 { | |
1225 var lineNumber = this._codeMirror.getLineNumber(this._lineHandle); | |
1226 if (typeof lineNumber !== "number") | |
1227 return null; | |
1228 return { | |
1229 lineNumber: lineNumber, | |
1230 columnNumber: this._columnNumber | |
1231 }; | |
1232 }, | |
1233 | |
1234 /** | |
1235 * @param {WebInspector.TextEditorPositionHandle} positionHandle | |
1236 * @return {boolean} | |
1237 */ | |
1238 equal: function(positionHandle) | |
1239 { | |
1240 return positionHandle._lineHandle === this._lineHandle && positionHandle ._columnNumber == this._columnNumber && | |
vsevik
2013/09/04 09:46:22
No need to split this line, but I'd name the param
lushnikov
2014/01/02 14:06:09
I love "_lineHandle" more - that's not too verbose
| |
1241 positionHandle._codeMirror === this._codeMirror; | |
1242 } | |
1243 } | |
1244 | |
1245 /** | |
1246 * @constructor | |
1168 * @param {CodeMirror} codeMirror | 1247 * @param {CodeMirror} codeMirror |
1169 */ | 1248 */ |
1170 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) | 1249 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) |
1171 { | 1250 { |
1172 this._codeMirror = codeMirror; | 1251 this._codeMirror = codeMirror; |
1173 } | 1252 } |
1174 | 1253 |
1175 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { | 1254 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { |
1176 /** | 1255 /** |
1177 * @param {RegExp} regex | 1256 * @param {RegExp} regex |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1558 * @param {number} line | 1637 * @param {number} line |
1559 * @param {number} column | 1638 * @param {number} column |
1560 * @return {AnchorBox} | 1639 * @return {AnchorBox} |
1561 */ | 1640 */ |
1562 _anchorBoxForPosition: function(line, column) | 1641 _anchorBoxForPosition: function(line, column) |
1563 { | 1642 { |
1564 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ; | 1643 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ; |
1565 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height) : null; | 1644 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height) : null; |
1566 }, | 1645 }, |
1567 } | 1646 } |
OLD | NEW |