mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Changed Jump-To-Definition, as requested -- modeled on QuickEdit:
- Now can register multiple jump-to-definition providers (only one, so far).
- Moved jump-to-definition menu setup to top level.
- Added jump-to-definition to floating right-click menu. [ Note: we may not want
this unless there is a provider registered for the current mode, but that's how
QuickEdit does it. We can fix both at the same time if we decide to. Also note
that if we want to change the right-click menu for this, one could argue that we
should also change the top level menu for the same reason. ]
This commit is contained in:
1 parent
e664a00d09
commit
43b5b735be
6 files changed
+93
-20
No files matched your search
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"jumptoDefinition": [
|
||||
"Ctrl-J"
|
||||
]
|
||||
}
|
||||
@@ -36,6 +36,7 @@ define(function (require, exports, module) {
|
||||
Strings = brackets.getModule("strings"),
|
||||
AppInit = brackets.getModule("utils/AppInit"),
|
||||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
|
||||
PerfUtils = brackets.getModule("utils/PerfUtils"),
|
||||
StringUtils = brackets.getModule("utils/StringUtils"),
|
||||
StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
LanguageManager = brackets.getModule("language/LanguageManager"),
|
||||
@@ -45,8 +46,6 @@ define(function (require, exports, module) {
|
||||
Session = require("Session"),
|
||||
Acorn = require("thirdparty/acorn/acorn");
|
||||
|
||||
var KeyboardPrefs = JSON.parse(require("text!keyboard.json"));
|
||||
|
||||
var JUMPTO_DEFINITION = "navigate.jumptoDefinition";
|
||||
|
||||
var session = null, // object that encapsulates the current session state
|
||||
@@ -567,8 +566,16 @@ define(function (require, exports, module) {
|
||||
* Handle JumptoDefiniton menu/keyboard command.
|
||||
*/
|
||||
function handleJumpToDefinition() {
|
||||
var offset = session.getOffset(),
|
||||
response = ScopeManager.requestJumptoDef(session, session.editor.document, offset);
|
||||
var offset,
|
||||
response;
|
||||
|
||||
// Only provide jump-to-definition results when cursor is in JavaScript content
|
||||
if (session.editor.getModeForSelection() !== "javascript") {
|
||||
return null;
|
||||
}
|
||||
|
||||
offset = session.getOffset();
|
||||
response = ScopeManager.requestJumptoDef(session, session.editor.document, offset);
|
||||
|
||||
if (response.hasOwnProperty("promise")) {
|
||||
response.promise.done(function (jumpResp) {
|
||||
@@ -585,6 +592,9 @@ define(function (require, exports, module) {
|
||||
} else {
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end, true);
|
||||
}
|
||||
response.resolve(true);
|
||||
} else {
|
||||
response.reject();
|
||||
}
|
||||
|
||||
}).fail(function () {
|
||||
@@ -603,18 +613,9 @@ define(function (require, exports, module) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Register command handler
|
||||
CommandManager.register(Strings.CMD_JUMPTO_DEFINITION, JUMPTO_DEFINITION, handleJumpToDefinition);
|
||||
|
||||
// Register quickEditHelper.
|
||||
brackets._jsCodeHintsHelper = quickEditHelper;
|
||||
|
||||
// Add the menu item
|
||||
var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
|
||||
if (menu) {
|
||||
menu.addMenuItem(JUMPTO_DEFINITION, KeyboardPrefs.jumptoDefinition, Menus.AFTER, Commands.NAVIGATE_GOTO_DEFINITION);
|
||||
}
|
||||
|
||||
ExtensionUtils.loadStyleSheet(module, "styles/brackets-js-hints.css");
|
||||
|
||||
// uninstall/install change listener as the active editor changes
|
||||
@@ -629,6 +630,10 @@ define(function (require, exports, module) {
|
||||
// immediately install the current editor
|
||||
installEditorListeners(EditorManager.getActiveEditor());
|
||||
|
||||
// init
|
||||
EditorManager.registerJumpToDefProvider(handleJumpToDefinition);
|
||||
PerfUtils.createPerfMeasurement("JUMP_TO_DEFINITION", "Jump-To-Definiiton");
|
||||
|
||||
var jsHints = new JSHints();
|
||||
CodeHintManager.registerHintProvider(jsHints, HintUtils.SUPPORTED_LANGUAGES, 0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user