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

Unified Diff: Source/devtools/front_end/documentation/DocumentationView.js

Issue 471583003: DevTools: [Documentation] Add property token autodetection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sources-patch
Patch Set: Comments addressed Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/documentation/DocumentationView.js
diff --git a/Source/devtools/front_end/documentation/DocumentationView.js b/Source/devtools/front_end/documentation/DocumentationView.js
index 5dfded75637a6a6759327cd9b48241db3b7df469..1024dc4b97fc88f9e99110d361d7de190d79dc2a 100644
--- a/Source/devtools/front_end/documentation/DocumentationView.js
+++ b/Source/devtools/front_end/documentation/DocumentationView.js
@@ -45,21 +45,38 @@ WebInspector.DocumentationView.ContextMenuProvider.prototype = {
if (!(target instanceof WebInspector.CodeMirrorTextEditor))
return;
var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (target);
- var selection = textEditor.selection();
- if (!selection || selection.isEmpty() || selection.startLine !== selection.endLine)
- return;
- var selectedText = textEditor.copyRange(selection);
var urlProvider = new WebInspector.DocumentationURLProvider();
- var descriptors = urlProvider.itemDescriptors(selectedText);
+ var propertyName;
apavlov 2014/08/14 13:44:56 The new code should now become a new method due to
semeny 2014/08/14 14:23:11 Done.
+ var descriptors;
+ var textSelection = textEditor.selection().normalize();
+
+ if (!textSelection.isEmpty() && textSelection.startLine === textSelection.endLine) {
apavlov 2014/08/14 13:44:55 Add if (textSelection.startLine !== textSelection.
semeny 2014/08/14 14:23:11 Done.
+ propertyName = textEditor.copyRange(textSelection);
+ } else {
+ var token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn);
+ var line = textEditor.line(textSelection.startLine);
+ if (token) {
+ var tokenText = line.substring(token.startColumn, token.endColumn);
+ descriptors = urlProvider.itemDescriptors(tokenText);
+ }
+ if (!token || !descriptors.length) {
+ token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn - 1);
+ if (!token)
+ return;
+ }
+ propertyName = line.substring(token.startColumn, token.endColumn);
+ }
+ if (!descriptors || !descriptors.length)
+ descriptors = urlProvider.itemDescriptors(propertyName);
apavlov 2014/08/14 13:44:55 Assuming the new code is inside a new method, let'
semeny 2014/08/14 14:23:11 Done.
if (!descriptors.length)
return;
if (descriptors.length === 1) {
var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show documentation for %s.%s" : "Show Documentation for %s.%s";
- contextMenu.appendItem(WebInspector.UIString(formatString, descriptors[0].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[0].url));
+ contextMenu.appendItem(WebInspector.UIString(formatString, descriptors[0].name, propertyName), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[0].url));
return;
}
var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Documentation for..."));
for (var i = 0; i < descriptors.length; ++i)
- subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[i].url));
+ subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, propertyName), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[i].url));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698