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

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

Issue 23474010: DevTools: "Jump between editing locations" experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline Created 7 years, 3 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 this.sidebarPanes.eventListenerBreakpoints = new WebInspector.EventListenerB reakpointsSidebarPane(); 121 this.sidebarPanes.eventListenerBreakpoints = new WebInspector.EventListenerB reakpointsSidebarPane();
122 122
123 if (Capabilities.canInspectWorkers && !WebInspector.WorkerManager.isWorkerFr ontend()) { 123 if (Capabilities.canInspectWorkers && !WebInspector.WorkerManager.isWorkerFr ontend()) {
124 WorkerAgent.enable(); 124 WorkerAgent.enable();
125 this.sidebarPanes.workerList = new WebInspector.WorkersSidebarPane(WebIn spector.workerManager); 125 this.sidebarPanes.workerList = new WebInspector.WorkersSidebarPane(WebIn spector.workerManager);
126 } 126 }
127 127
128 this.sidebarPanes.callstack.registerShortcuts(this.registerShortcuts.bind(th is)); 128 this.sidebarPanes.callstack.registerShortcuts(this.registerShortcuts.bind(th is));
129 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.GoTo Member, this._showOutlineDialog.bind(this)); 129 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.GoTo Member, this._showOutlineDialog.bind(this));
130 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.Togg leBreakpoint, this._toggleBreakpoint.bind(this)); 130 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.Togg leBreakpoint, this._toggleBreakpoint.bind(this));
131 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.Jump ToPreviousPosition, this._previousPosition.bind(this));
132 this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.Jump ToNextPosition, this._nextPosition.bind(this));
131 133
132 this._pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts -pause-on-exceptions-status-bar-item", 3); 134 this._pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts -pause-on-exceptions-status-bar-item", 3);
133 this._pauseOnExceptionButton.addEventListener("click", this._togglePauseOnEx ceptions, this); 135 this._pauseOnExceptionButton.addEventListener("click", this._togglePauseOnEx ceptions, this);
134 136
135 this._toggleFormatSourceButton = new WebInspector.StatusBarButton(WebInspect or.UIString("Pretty print"), "scripts-toggle-pretty-print-status-bar-item"); 137 this._toggleFormatSourceButton = new WebInspector.StatusBarButton(WebInspect or.UIString("Pretty print"), "scripts-toggle-pretty-print-status-bar-item");
136 this._toggleFormatSourceButton.toggled = false; 138 this._toggleFormatSourceButton.toggled = false;
137 this._toggleFormatSourceButton.addEventListener("click", this._toggleFormatS ource, this); 139 this._toggleFormatSourceButton.addEventListener("click", this._toggleFormatS ource, this);
138 140
139 this._scriptViewStatusBarItemsContainer = document.createElement("div"); 141 this._scriptViewStatusBarItemsContainer = document.createElement("div");
140 this._scriptViewStatusBarItemsContainer.className = "inline-block"; 142 this._scriptViewStatusBarItemsContainer.className = "inline-block";
(...skipping 29 matching lines...) Expand all
170 172
171 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this); 173 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this);
172 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); 174 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this);
173 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._projectWillReset.bind(this), this); 175 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._projectWillReset.bind(this), this);
174 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Event s.GlobalObjectCleared, this._debuggerReset, this); 176 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Event s.GlobalObjectCleared, this._debuggerReset, this);
175 177
176 WebInspector.advancedSearchController.registerSearchScope(new WebInspector.S criptsSearchScope(this._workspace)); 178 WebInspector.advancedSearchController.registerSearchScope(new WebInspector.S criptsSearchScope(this._workspace));
177 179
178 this._boundOnKeyUp = this._onKeyUp.bind(this); 180 this._boundOnKeyUp = this._onKeyUp.bind(this);
179 this._boundOnKeyDown = this._onKeyDown.bind(this); 181 this._boundOnKeyDown = this._onKeyDown.bind(this);
182
183 this._jumpHistoryManager = new WebInspector.ScriptsPanel.JumpHistoryManager( );
180 } 184 }
181 185
182 WebInspector.ScriptsPanel.prototype = { 186 WebInspector.ScriptsPanel.prototype = {
183 get statusBarItems() 187 get statusBarItems()
184 { 188 {
185 return [this._pauseOnExceptionButton.element, this._toggleFormatSourceBu tton.element, this._scriptViewStatusBarItemsContainer]; 189 return [this._pauseOnExceptionButton.element, this._toggleFormatSourceBu tton.element, this._scriptViewStatusBarItemsContainer];
186 }, 190 },
187 191
188 /** 192 /**
189 * @return {?Element} 193 * @return {?Element}
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 this.sidebarPanes.watchExpressions.reset(); 359 this.sidebarPanes.watchExpressions.reset();
356 }, 360 },
357 361
358 _projectWillReset: function(event) 362 _projectWillReset: function(event)
359 { 363 {
360 var project = event.data; 364 var project = event.data;
361 var uiSourceCodes = project.uiSourceCodes(); 365 var uiSourceCodes = project.uiSourceCodes();
362 this._removeUISourceCodes(uiSourceCodes); 366 this._removeUISourceCodes(uiSourceCodes);
363 if (project.type() === WebInspector.projectTypes.Network) 367 if (project.type() === WebInspector.projectTypes.Network)
364 this._editorContainer.reset(); 368 this._editorContainer.reset();
369 this._jumpHistoryManager.dropHistoryEntries(project.id(), null);
vsevik 2013/08/29 10:46:16 move this to _removeUISourceCodes
365 }, 370 },
366 371
367 get visibleView() 372 get visibleView()
368 { 373 {
369 return this._editorContainer.visibleView; 374 return this._editorContainer.visibleView;
370 }, 375 },
371 376
372 _updateScriptViewStatusBarItems: function() 377 _updateScriptViewStatusBarItems: function()
373 { 378 {
374 this._scriptViewStatusBarItemsContainer.removeChildren(); 379 this._scriptViewStatusBarItemsContainer.removeChildren();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (this._currentUISourceCode.project().type() === WebInspector.projectT ypes.Snippets) 460 if (this._currentUISourceCode.project().type() === WebInspector.projectT ypes.Snippets)
456 this._runSnippetButton.element.removeStyleClass("hidden"); 461 this._runSnippetButton.element.removeStyleClass("hidden");
457 else 462 else
458 this._runSnippetButton.element.addStyleClass("hidden"); 463 this._runSnippetButton.element.addStyleClass("hidden");
459 464
460 return sourceFrame; 465 return sourceFrame;
461 }, 466 },
462 467
463 /** 468 /**
464 * @param {WebInspector.UISourceCode} uiSourceCode 469 * @param {WebInspector.UISourceCode} uiSourceCode
470 * @param {WebInspector.TextEditorPositionHandler} from
471 * @param {WebInspector.TextEditorPositionHandler} to
472 */
473 _onJumpToPosition: function(uiSourceCode, from, to)
474 {
475 if (this._searchQuery || !WebInspector.experimentsSettings.jumpToPreviou sLocation.isEnabled())
476 return;
477 if (this._muteJumpToPositionEvent) {
478 if (from)
479 this._jumpHistoryManager.updateEntry(this._historyEntryToUpdate, uiSourceCode.project().id(), uiSourceCode.path(), from);
480 return;
481 }
482 if (from && !this._jumpHistoryManager.empty())
483 this._jumpHistoryManager.updateEntry(this._jumpHistoryManager.curren t(), uiSourceCode.project().id(), uiSourceCode.path(), from);
484 if (to)
485 this._jumpHistoryManager.push(uiSourceCode.project().id(), uiSourceC ode.path(), to);
486 },
487
488 /**
489 * @param {?Event=} event
490 * @return {boolean}
491 */
492 _previousPosition: function(event)
493 {
494 var previous = this._jumpHistoryManager.current();
495 var entry = this._jumpHistoryManager.rollback();
496 if (!entry)
497 return false;
498 this._applyHistoryEntry(previous, entry);
499 return true;
500 },
501
502 /**
503 * @param {?Event=} event
504 * @return {boolean}
505 */
506 _nextPosition: function(event)
507 {
508 var previous = this._jumpHistoryManager.current();
509 var entry = this._jumpHistoryManager.rollover();
510 if (!entry)
511 return false;
512 this._applyHistoryEntry(previous, entry);
513 return true;
514 },
515
516 /**
517 * @param {WebInspector.ScriptsPanel.JumpHistoryEntry} previousEntry
518 * @param {WebInspector.ScriptsPanel.JumpHistoryEntry} newEntry
519 */
520 _applyHistoryEntry: function(previousEntry, newEntry)
521 {
522 var position = newEntry.position.resolve();
523 var uiSourceCode = WebInspector.workspace.project(newEntry.projectId).ui SourceCode(newEntry.path);
524 this._muteJumpToPositionEvent = true;
525 this._historyEntryToUpdate = previousEntry;
526 this._showSourceLocation(uiSourceCode, position.lineNumber, position.col umnNumber);
527 delete this._historyEntryToUpdate;
528 delete this._muteJumpToPositionEvent;
529 },
530
531 /**
532 * @param {WebInspector.UISourceCode} uiSourceCode
465 * @return {WebInspector.SourceFrame} 533 * @return {WebInspector.SourceFrame}
466 */ 534 */
467 _createSourceFrame: function(uiSourceCode) 535 _createSourceFrame: function(uiSourceCode)
468 { 536 {
469 var sourceFrame; 537 var sourceFrame;
470 switch (uiSourceCode.contentType()) { 538 switch (uiSourceCode.contentType()) {
471 case WebInspector.resourceTypes.Script: 539 case WebInspector.resourceTypes.Script:
472 sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceC ode); 540 sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceC ode);
473 break; 541 break;
474 case WebInspector.resourceTypes.Document: 542 case WebInspector.resourceTypes.Document:
475 sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceC ode); 543 sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceC ode);
476 break; 544 break;
477 case WebInspector.resourceTypes.Stylesheet: 545 case WebInspector.resourceTypes.Stylesheet:
478 default: 546 default:
479 sourceFrame = new WebInspector.UISourceCodeFrame(uiSourceCode); 547 sourceFrame = new WebInspector.UISourceCodeFrame(uiSourceCode);
480 break; 548 break;
481 } 549 }
482 this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame); 550 this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame);
551 sourceFrame.setJumpToPositionDelegate(this._onJumpToPosition.bind(this, uiSourceCode));
483 return sourceFrame; 552 return sourceFrame;
484 }, 553 },
485 554
486 /** 555 /**
487 * @param {WebInspector.UISourceCode} uiSourceCode 556 * @param {WebInspector.UISourceCode} uiSourceCode
488 * @return {WebInspector.SourceFrame} 557 * @return {WebInspector.SourceFrame}
489 */ 558 */
490 _getOrCreateSourceFrame: function(uiSourceCode) 559 _getOrCreateSourceFrame: function(uiSourceCode)
491 { 560 {
492 return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._creat eSourceFrame(uiSourceCode); 561 return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._creat eSourceFrame(uiSourceCode);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 }, 628 },
560 629
561 _editorClosed: function(event) 630 _editorClosed: function(event)
562 { 631 {
563 this._navigatorController.hideNavigatorOverlay(); 632 this._navigatorController.hideNavigatorOverlay();
564 var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data) ; 633 var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data) ;
565 634
566 if (this._currentUISourceCode === uiSourceCode) 635 if (this._currentUISourceCode === uiSourceCode)
567 delete this._currentUISourceCode; 636 delete this._currentUISourceCode;
568 637
638 this._jumpHistoryManager.dropHistoryEntries(uiSourceCode.project().id(), uiSourceCode.path());
vsevik 2013/08/29 10:46:16 So you don't need to listen for uiSourceCodeRemove
569 // ScriptsNavigator does not need to update on EditorClosed. 639 // ScriptsNavigator does not need to update on EditorClosed.
570 this._updateScriptViewStatusBarItems(); 640 this._updateScriptViewStatusBarItems();
571 WebInspector.searchController.resetSearch(); 641 WebInspector.searchController.resetSearch();
572 }, 642 },
573 643
574 _editorSelected: function(event) 644 _editorSelected: function(event)
575 { 645 {
576 var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data) ; 646 var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data) ;
577 var sourceFrame = this._showFile(uiSourceCode); 647 var sourceFrame = this._showFile(uiSourceCode);
578 this._navigatorController.hideNavigatorOverlay(); 648 this._navigatorController.hideNavigatorOverlay();
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 } else { 1510 } else {
1441 this._editorFooterElement.addStyleClass("hidden"); 1511 this._editorFooterElement.addStyleClass("hidden");
1442 this._editorFooterElement.removeChildren(); 1512 this._editorFooterElement.removeChildren();
1443 this._editorContentsElement.style.bottom = 0; 1513 this._editorContentsElement.style.bottom = 0;
1444 } 1514 }
1445 this.doResize(); 1515 this.doResize();
1446 }, 1516 },
1447 1517
1448 __proto__: WebInspector.Panel.prototype 1518 __proto__: WebInspector.Panel.prototype
1449 } 1519 }
1520
1521 /**
1522 * @constructor
1523 * @param {string} projectId
1524 * @param {string} path
1525 * @param {WebInspector.TextEditorPositionHandler} position
1526 */
1527 WebInspector.ScriptsPanel.JumpHistoryEntry = function(projectId, path, position)
1528 {
1529 this.projectId = projectId;
1530 this.path = path;
1531 this.position = position;
1532 }
1533
1534 WebInspector.ScriptsPanel.JumpHistoryDepth = 20;
1535
1536 /**
1537 * @constructor
1538 */
1539 WebInspector.ScriptsPanel.JumpHistoryManager = function()
1540 {
1541 this._history = [];
1542 this._index = -1;
1543 }
1544
1545 WebInspector.ScriptsPanel.JumpHistoryManager.prototype = {
vsevik 2013/08/29 10:46:16 Let's extract it to a separate file and delegate r
1546 /**
1547 * @return {boolean}
1548 */
1549 empty: function()
1550 {
1551 return !this._history.length;
1552 },
1553
1554 /**
1555 * @return {WebInspector.ScriptsPanel.JumpHistoryEntry}
1556 */
1557 current: function()
1558 {
1559 if (this.empty())
1560 return null;
1561 return this._history[this._index];
1562 },
1563
1564 /**
1565 * @param {WebInspector.ScriptsPanel.JumpHistoryEntry} entry
1566 * @param {string} projectId
1567 * @param {string} path
1568 * @param {WebInspector.TextEditorPositionHandler} newPosition
1569 */
1570 updateEntry: function(entry, projectId, path, newPosition)
1571 {
1572 if (entry.projectId === projectId && entry.path === path)
1573 entry.position = newPosition;
1574 },
1575
1576 /**
1577 * @param {string} projectId
1578 * @param {string} path
1579 * @param {WebInspector.TextEditorPositionHandler} position
1580 */
1581 push: function(projectId, path, position)
1582 {
1583 if (this._history.length) {
1584 var entry = this._history[this._index];
1585 if (entry.projectId === projectId && entry.path === path && entry.po sition.equal(position))
1586 return;
1587 }
1588 this._history.splice(++this._index, Infinity, new WebInspector.ScriptsPa nel.JumpHistoryEntry(projectId, path, position));
1589 if (this._history.length > WebInspector.ScriptsPanel.JumpHistoryDepth) {
1590 this._history.shift();
1591 --this._index;
1592 }
1593 },
1594
1595 /**
1596 * @param {string} projectId
1597 * @param {?string} path
1598 */
1599 dropHistoryEntries: function(projectId, path)
1600 {
1601 for(var i = this._history.length - 1; i >= 0; --i) {
1602 var entry = this._history[i];
1603 if (entry.projectId === projectId && (!path || entry.path === path)) {
1604 this._history.remove(entry);
1605 if (this._index >= i)
1606 --this._index;
1607 }
1608 }
1609 if (this._index < 0 && this._history.length > 0)
1610 this._index = 0;
1611 },
1612
1613 /**
1614 * @return {?WebInspector.ScriptsPanel.JumpHistoryEntry}
1615 */
1616 rollback: function() {
1617 if (this.empty())
1618 return null;
1619 for (var validEntryIndex = this._index - 1; validEntryIndex >= 0; --vali dEntryIndex) {
1620 if (this._history[validEntryIndex].position.resolve())
1621 break;
1622 }
1623 if (validEntryIndex < 0) {
1624 this._history.splice(0, this._index);
1625 this._index = 0;
1626 return null;
1627 }
1628 this._history.splice(validEntryIndex + 1, this._index - validEntryIndex - 1);
1629 this._index = validEntryIndex;
1630 return this._history[this._index];
1631 },
1632
1633 /**
1634 * @return {?WebInspector.ScriptsPanel.JumpHistoryEntry}
1635 */
1636 rollover: function() {
vsevik 2013/08/29 10:49:29 { on the next line, here and below and above.
1637 if (this.empty())
1638 return null;
1639 for (var validEntryIndex = this._index + 1; validEntryIndex < this._hist ory.length; ++validEntryIndex) {
1640 if (this._history[validEntryIndex].position.resolve())
1641 break;
1642 }
1643 if (validEntryIndex >= this._history.length) {
1644 this._history.splice(this._index + 1);
1645 return null;
1646 }
1647 this._history.splice(this._index + 1, validEntryIndex - this._index - 1) ;
1648 ++this._index;
1649 return this._history[this._index];
1650 }
1651 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/CodeMirrorTextEditor.js ('k') | Source/devtools/front_end/ScriptsPanelDescriptor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698