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

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..0cc330a44fd0cf80a9adc3ff18f4cc65f1f3d75c 100644
--- a/Source/devtools/front_end/documentation/DocumentationView.js
+++ b/Source/devtools/front_end/documentation/DocumentationView.js
@@ -45,21 +45,35 @@ 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;
+ var textSelection = textEditor.selection().normalize();
+
+ if (textSelection && !textSelection.isEmpty() && textSelection.startLine === textSelection.endLine) {
apavlov 2014/08/14 12:49:52 Please remove the first conjunct, since textSelect
semeny 2014/08/14 13:17:30 Done.
+ propertyName = textEditor.copyRange(textSelection);
+ } else {
+ var token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn);
+ var line = textEditor.line(textSelection.startLine);
+ var tokenText = line.substring(token.startColumn, token.endColumn);
+ if (!token || !urlProvider.itemDescriptors(tokenText).length) {
apavlov 2014/08/14 12:49:52 Let's avoid multiple itemDescriptors() invocations
semeny 2014/08/14 13:17:30 Done.
+ if (textSelection.startColumn > 0)
+ token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn - 1);
+ if (!token)
+ return;
+ }
+ propertyName = line.substring(token.startColumn, token.endColumn);
+ }
+
+ var descriptors = urlProvider.itemDescriptors(propertyName);
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