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

Side by Side Diff: Source/devtools/front_end/CodeMirrorTextEditor.js

Issue 23474010: DevTools: "Jump between editing locations" experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline this patch Created 6 years, 11 months 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 | Annotate | Revision Log
OLDNEW
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
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._isHandlingMouseDownEvent = 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl ightLength) 339 if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighl ightLength)
330 this.setSelection(range); 340 this.setSelection(range);
331 else 341 else
332 this.setSelection(WebInspector.TextRange.createFromLocation( range.startLine, range.startColumn)); 342 this.setSelection(WebInspector.TextRange.createFromLocation( range.startLine, range.startColumn));
333 } else { 343 } else {
334 // Collapse selection to end on search start so that we jump to next occurence on the first enter press. 344 // Collapse selection to end on search start so that we jump to next occurence on the first enter press.
335 this.setSelection(this.selection().collapseToEnd()); 345 this.setSelection(this.selection().collapseToEnd());
336 } 346 }
337 this._tokenHighlighter.highlightSearchResults(regex, range); 347 this._tokenHighlighter.highlightSearchResults(regex, range);
338 } 348 }
349 if (!this._selectionBeforeSearch)
350 this._selectionBeforeSearch = this.selection();
339 this._codeMirror.operation(innerHighlightRegex.bind(this)); 351 this._codeMirror.operation(innerHighlightRegex.bind(this));
340 }, 352 },
341 353
342 cancelSearchResultsHighlight: function() 354 cancelSearchResultsHighlight: function()
343 { 355 {
344 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedToken s.bind(this._tokenHighlighter)); 356 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedToken s.bind(this._tokenHighlighter));
357 if (this._selectionBeforeSearch) {
358 this._reportJump(this._selectionBeforeSearch, this.selection());
359 delete this._selectionBeforeSearch;
360 }
345 }, 361 },
346 362
347 undo: function() 363 undo: function()
348 { 364 {
349 this._codeMirror.undo(); 365 this._codeMirror.undo();
350 }, 366 },
351 367
352 redo: function() 368 redo: function()
353 { 369 {
354 this._codeMirror.redo(); 370 this._codeMirror.redo();
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 columnNumber = 0; 816 columnNumber = 0;
801 817
802 this.clearPositionHighlight(); 818 this.clearPositionHighlight();
803 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); 819 this._highlightedLine = this._codeMirror.getLineHandle(lineNumber);
804 if (!this._highlightedLine) 820 if (!this._highlightedLine)
805 return; 821 return;
806 this.revealLine(lineNumber); 822 this.revealLine(lineNumber);
807 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight "); 823 this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight ");
808 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin d(this), 2000); 824 this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bin d(this), 2000);
809 if (!this.readOnly()) 825 if (!this.readOnly())
810 this._codeMirror.setSelection(new CodeMirror.Pos(lineNumber, columnN umber)); 826 this.setSelection(WebInspector.TextRange.createFromLocation(lineNumb er, columnNumber));
811 }, 827 },
812 828
813 clearPositionHighlight: function() 829 clearPositionHighlight: function()
814 { 830 {
815 if (this._clearHighlightTimeout) 831 if (this._clearHighlightTimeout)
816 clearTimeout(this._clearHighlightTimeout); 832 clearTimeout(this._clearHighlightTimeout);
817 delete this._clearHighlightTimeout; 833 delete this._clearHighlightTimeout;
818 834
819 if (this._highlightedLine) 835 if (this._highlightedLine)
820 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi ghlight"); 836 this._codeMirror.removeLineClass(this._highlightedLine, null, "cm-hi ghlight");
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 1002
987 _cursorActivity: function() 1003 _cursorActivity: function()
988 { 1004 {
989 var start = this._codeMirror.getCursor("anchor"); 1005 var start = this._codeMirror.getCursor("anchor");
990 var end = this._codeMirror.getCursor("head"); 1006 var end = this._codeMirror.getCursor("head");
991 this._delegate.selectionChanged(this._toRange(start, end)); 1007 this._delegate.selectionChanged(this._toRange(start, end));
992 if (!this._tokenHighlighter.highlightedRegex()) 1008 if (!this._tokenHighlighter.highlightedRegex())
993 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter)); 1009 this._codeMirror.operation(this._tokenHighlighter.highlightSelectedT okens.bind(this._tokenHighlighter));
994 }, 1010 },
995 1011
1012 /**
1013 * @param {!CodeMirror} codeMirror
1014 * @param {!{head: !CodeMirror.Pos, anchor: !CodeMirror.Pos}} selection
1015 */
1016 _beforeSelectionChange: function(codeMirror, selection)
1017 {
1018 if (!this._isHandlingMouseDownEvent)
1019 return;
1020 this._reportJump(this.selection(), this._toRange(selection.anchor, selec tion.head));
1021 },
1022
1023 /**
1024 * @param {?WebInspector.TextRange} from
1025 * @param {?WebInspector.TextRange} to
1026 */
1027 _reportJump: function(from, to)
1028 {
1029 if (from && to && from.equal(to))
1030 return;
1031 this._delegate.onJumpToPosition(from, to);
1032 },
1033
996 _scroll: function() 1034 _scroll: function()
997 { 1035 {
998 if (this._scrollTimer) 1036 if (this._scrollTimer)
999 clearTimeout(this._scrollTimer); 1037 clearTimeout(this._scrollTimer);
1000 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g etScrollInfo().top, "local"); 1038 var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.g etScrollInfo().top, "local");
1001 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d elegate, topmostLineNumber), 100); 1039 this._scrollTimer = setTimeout(this._delegate.scrollChanged.bind(this._d elegate, topmostLineNumber), 100);
1002 }, 1040 },
1003 1041
1004 _focus: function() 1042 _focus: function()
1005 { 1043 {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 start: new CodeMirror.Pos(range.startLine, range.startColumn), 1214 start: new CodeMirror.Pos(range.startLine, range.startColumn),
1177 end: new CodeMirror.Pos(range.endLine, range.endColumn) 1215 end: new CodeMirror.Pos(range.endLine, range.endColumn)
1178 } 1216 }
1179 }, 1217 },
1180 1218
1181 _toRange: function(start, end) 1219 _toRange: function(start, end)
1182 { 1220 {
1183 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch ); 1221 return new WebInspector.TextRange(start.line, start.ch, end.line, end.ch );
1184 }, 1222 },
1185 1223
1224 /**
1225 * @param {number} lineNumber
1226 * @param {number} columnNumber
1227 * @return {!WebInspector.TextEditorPositionHandle}
1228 */
1229 textEditorPositionHandle: function(lineNumber, columnNumber)
1230 {
1231 return new WebInspector.CodeMirrorPositionHandle(this._codeMirror, new C odeMirror.Pos(lineNumber, columnNumber));
1232 },
1233
1186 __proto__: WebInspector.View.prototype 1234 __proto__: WebInspector.View.prototype
1187 } 1235 }
1188 1236
1189 /** 1237 /**
1190 * @constructor 1238 * @constructor
1239 * @implements {WebInspector.TextEditorPositionHandle}
1240 * @param {!CodeMirror} codeMirror
1241 * @param {!CodeMirror.Pos} pos
1242 */
1243 WebInspector.CodeMirrorPositionHandle = function(codeMirror, pos)
1244 {
1245 this._codeMirror = codeMirror;
1246 this._lineHandle = codeMirror.getLineHandle(pos.line);
1247 this._columnNumber = pos.ch;
1248 }
1249
1250 WebInspector.CodeMirrorPositionHandle.prototype = {
1251 /**
1252 * @return {?{lineNumber: number, columnNumber: number}}
1253 */
1254 resolve: function()
1255 {
1256 var lineNumber = this._codeMirror.getLineNumber(this._lineHandle);
1257 if (typeof lineNumber !== "number")
1258 return null;
1259 return {
1260 lineNumber: lineNumber,
1261 columnNumber: this._columnNumber
1262 };
1263 },
1264
1265 /**
1266 * @param {!WebInspector.TextEditorPositionHandle} positionHandle
1267 * @return {boolean}
1268 */
1269 equal: function(positionHandle)
1270 {
1271 return positionHandle._lineHandle === this._lineHandle && positionHandle ._columnNumber == this._columnNumber && positionHandle._codeMirror === this._cod eMirror;
1272 }
1273 }
1274
1275 /**
1276 * @constructor
1191 * @param {!CodeMirror} codeMirror 1277 * @param {!CodeMirror} codeMirror
1192 */ 1278 */
1193 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) 1279 WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror)
1194 { 1280 {
1195 this._codeMirror = codeMirror; 1281 this._codeMirror = codeMirror;
1196 } 1282 }
1197 1283
1198 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { 1284 WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = {
1199 /** 1285 /**
1200 * @param {!RegExp} regex 1286 * @param {!RegExp} regex
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 * @param {number} line 1677 * @param {number} line
1592 * @param {number} column 1678 * @param {number} column
1593 * @return {?AnchorBox} 1679 * @return {?AnchorBox}
1594 */ 1680 */
1595 _anchorBoxForPosition: function(line, column) 1681 _anchorBoxForPosition: function(line, column)
1596 { 1682 {
1597 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ; 1683 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ;
1598 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height) : null; 1684 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height) : null;
1599 }, 1685 },
1600 } 1686 }
OLDNEW
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/EditingLocationHistoryManager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698