Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 */ | 8 */ |
| 9 WebInspector.DocumentationView = function() | 9 WebInspector.DocumentationView = function() |
| 10 { | 10 { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 /** | 38 /** |
| 39 * @param {!Event} event | 39 * @param {!Event} event |
| 40 * @param {!WebInspector.ContextMenu} contextMenu | 40 * @param {!WebInspector.ContextMenu} contextMenu |
| 41 * @param {!Object} target | 41 * @param {!Object} target |
| 42 */ | 42 */ |
| 43 appendApplicableItems: function(event, contextMenu, target) | 43 appendApplicableItems: function(event, contextMenu, target) |
| 44 { | 44 { |
| 45 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) | 45 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) |
| 46 return; | 46 return; |
| 47 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); | 47 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); |
| 48 var selection = textEditor.selection(); | |
| 49 if (!selection || selection.isEmpty() || selection.startLine !== selecti on.endLine) | |
| 50 return; | |
| 51 var selectedText = textEditor.copyRange(selection); | |
| 52 var urlProvider = new WebInspector.DocumentationURLProvider(); | 48 var urlProvider = new WebInspector.DocumentationURLProvider(); |
| 53 var descriptors = urlProvider.itemDescriptors(selectedText); | 49 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.
| |
| 50 var descriptors; | |
| 51 var textSelection = textEditor.selection().normalize(); | |
| 52 | |
| 53 if (!textSelection.isEmpty() && textSelection.startLine === textSelectio n.endLine) { | |
|
apavlov
2014/08/14 13:44:55
Add
if (textSelection.startLine !== textSelection.
semeny
2014/08/14 14:23:11
Done.
| |
| 54 propertyName = textEditor.copyRange(textSelection); | |
| 55 } else { | |
| 56 var token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn); | |
| 57 var line = textEditor.line(textSelection.startLine); | |
| 58 if (token) { | |
| 59 var tokenText = line.substring(token.startColumn, token.endColum n); | |
| 60 descriptors = urlProvider.itemDescriptors(tokenText); | |
| 61 } | |
| 62 if (!token || !descriptors.length) { | |
| 63 token = textEditor.tokenAtTextPosition(textSelection.startLine, textSelection.startColumn - 1); | |
| 64 if (!token) | |
| 65 return; | |
| 66 } | |
| 67 propertyName = line.substring(token.startColumn, token.endColumn); | |
| 68 } | |
| 69 if (!descriptors || !descriptors.length) | |
| 70 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.
| |
| 54 if (!descriptors.length) | 71 if (!descriptors.length) |
| 55 return; | 72 return; |
| 56 if (descriptors.length === 1) { | 73 if (descriptors.length === 1) { |
| 57 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; | 74 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; |
| 58 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.b ind(null, descriptors[0].url)); | 75 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name, propertyName), WebInspector.DocumentationView.showDocumentationURL.b ind(null, descriptors[0].url)); |
| 59 return; | 76 return; |
| 60 } | 77 } |
| 61 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); | 78 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); |
| 62 for (var i = 0; i < descriptors.length; ++i) | 79 for (var i = 0; i < descriptors.length; ++i) |
| 63 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, de scriptors[i].url)); | 80 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, propertyName), WebInspector.DocumentationView.showDocumentationURL.bind(null, de scriptors[i].url)); |
| 64 } | 81 } |
| 65 } | 82 } |
| OLD | NEW |