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

Unified Diff: Source/devtools/front_end/sources/SourcesView.js

Issue 378273004: DevTools: Add a shortcut for switching between files with the same name and different extensions. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comments addressed Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/sources/SourcesView.js
diff --git a/Source/devtools/front_end/sources/SourcesView.js b/Source/devtools/front_end/sources/SourcesView.js
index f8ac80b41438939408b0982e74a5a5e6bc6b799e..9168eaf1f758c5272b4c622ec327b9ec663b165c 100644
--- a/Source/devtools/front_end/sources/SourcesView.js
+++ b/Source/devtools/front_end/sources/SourcesView.js
@@ -130,6 +130,18 @@ WebInspector.SourcesView.prototype = {
event.consume(true);
},
+ wasShown: function()
+ {
+ WebInspector.VBox.prototype.wasShown.call(this);
+ WebInspector.context.setFlavor(WebInspector.SourcesView, this);
+ },
+
+ willHide: function()
+ {
+ WebInspector.context.setFlavor(WebInspector.SourcesView, null);
+ WebInspector.VBox.prototype.willHide.call(this);
+ },
+
/**
* @return {!Element}
*/
@@ -700,3 +712,68 @@ WebInspector.SourcesView.EditorAction.prototype = {
*/
button: function(sourcesView) { }
}
+
+/**
+ * @constructor
+ * @implements {WebInspector.ActionDelegate}
+ */
+WebInspector.SourcesView.SwitchFileActionDelegate = function()
+{
+}
+
+/**
+ * @param {!WebInspector.UISourceCode} currentUISourceCode
+ * @return {?WebInspector.UISourceCode}
+ */
+WebInspector.SourcesView.SwitchFileActionDelegate._nextFile = function(currentUISourceCode)
+{
+ /**
+ * @param {string} name
+ * @return {string}
+ */
+ function fileNamePrefix(name)
+ {
+ var lastDotIndex = name.lastIndexOf(".");
+ var namePrefix = name.substr(0, lastDotIndex !== -1 ? lastDotIndex : name.length);
+ return namePrefix.toLowerCase();
+ }
+
+ var uiSourceCodes = currentUISourceCode.project().uiSourceCodes();
+ var candidates = [];
+ var path = currentUISourceCode.parentPath();
+ var name = currentUISourceCode.name();
+ var namePrefix = fileNamePrefix(name);
+ for (var i = 0; i < uiSourceCodes.length; ++i) {
+ var uiSourceCode = uiSourceCodes[i];
+ if (path !== uiSourceCode.parentPath())
+ continue;
+ if (fileNamePrefix(uiSourceCode.name()) === namePrefix)
+ candidates.push(uiSourceCode.name());
+ }
+ candidates.sort(String.naturalOrderComparator);
+ var index = mod(candidates.indexOf(name) + 1, candidates.length);
+ var fullPath = (path ? path + "/" : "") + candidates[index];
+ var nextUISourceCode = currentUISourceCode.project().uiSourceCode(fullPath);
+ return nextUISourceCode !== currentUISourceCode ? nextUISourceCode : null;
+},
+
+
+WebInspector.SourcesView.SwitchFileActionDelegate.prototype = {
+ /**
+ * @return {boolean}
+ */
+ handleAction: function()
+ {
+ var sourcesView = WebInspector.context.flavor(WebInspector.SourcesView);
+ if (!sourcesView)
+ return false;
+ var currentUISourceCode = sourcesView.currentUISourceCode();
+ if (!currentUISourceCode)
+ return true;
+ var nextUISourceCode = WebInspector.SourcesView.SwitchFileActionDelegate._nextFile(currentUISourceCode);
+ if (!nextUISourceCode)
+ return true;
+ sourcesView.showSourceLocation(nextUISourceCode);
+ return true;
+ }
+}
« no previous file with comments | « Source/devtools/front_end/components/ShortcutsScreen.js ('k') | Source/devtools/front_end/sources/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698