diff --git a/README.md b/README.md index 9249886..b81c868 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Brackets Commands Quick Search ============================== Use the keyboard to quickly search for commands and run them: -1. Press Ctrl+Alt+? (โŒƒโŒ˜? on Mac) +1. Press Ctrl+Shift+P (โ‡งโŒ˜P on Mac)
(or invoke regular Quick Open and type a "?") 2. Start typing (part of) the name of a command 3. Use arrow keys to select the one you want (or skip this to use the topmost result) @@ -28,4 +28,4 @@ To install extensions: MIT-licensed -- see `main.js` for details. ### Compatibility -Brackets Sprint 16 or newer (or Adobe Edge Code Preview 2 or newer). \ No newline at end of file +Brackets Sprint 16 or newer (or Adobe Edge Code Preview 2 or newer). diff --git a/main.js b/main.js index a3521fb..d298cf3 100644 --- a/main.js +++ b/main.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2012 Peter Flynn. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,7 +26,7 @@ define(function (require, exports, module) { "use strict"; - + // Brackets modules var CommandManager = brackets.getModule("command/CommandManager"), Commands = brackets.getModule("command/Commands"), @@ -35,34 +35,34 @@ define(function (require, exports, module) { EditorManager = brackets.getModule("editor/EditorManager"), QuickOpen = brackets.getModule("search/QuickOpen"), StringUtils = brackets.getModule("utils/StringUtils"); - - + + /** @type {Array.<{ id:string, name:string }>} */ var _commandList; - + /** * Editor that should be focused when executing the command (that had focus before opening search bar) * @type {Editor} */ var whichEditor; - - + + function ensureCommandList() { if (_commandList) { return; } _commandList = []; - + // We don't know which of these commands have no required arguments. But we can safely // assume that any commands attached to menus or keyboard shortcuts fit the bill. var ids = CommandManager.getAll(); - + // Get list of all top-level menu bar menus // Ignore context menus since it seems less safe to assume those commands can be run in isolation var menuIds = $.map(Menus.AppMenuBar, function (menuConstVal, menuConstName) { return menuConstVal; }); - + // Filter command list accordingly ids.forEach(function (id) { var noArgsOk = false; @@ -88,34 +88,34 @@ define(function (require, exports, module) { } }); } - + function done() { // No cleanup - keep cached list of commands for next invocation } - + /** * @param {string} query User query/filter string * @return {Array.} Sorted and filtered results that match the query */ function search(query, matcher) { ensureCommandList(); - + query = query.substr(1); // lose the "?" prefix - + var stringMatch = (matcher && matcher.match) ? matcher.match.bind(matcher) : QuickOpen.stringMatch; - + // Filter and rank how good each match is var filteredList = $.map(_commandList, function (commandInfo) { - + // TODO: filter out disabled commands? - + var searchResult = stringMatch(commandInfo.name, query); if (searchResult) { searchResult.id = commandInfo.id; } return searchResult; }); - + // Sort based on ranking & basic alphabetical order QuickOpen.basicMatchSort(filteredList); @@ -138,7 +138,7 @@ define(function (require, exports, module) { function itemSelect(selectedItem) { // Many commands are focus-sensitive, so we have to carefully make sure that focus is restored to // the (correct) editor before running the command - + // First wait for Quick Open to restore focus to the master editor setTimeout(function () { // Now set focus on the correct editor (which might be an inline editor) @@ -146,25 +146,25 @@ define(function (require, exports, module) { whichEditor.focus(); whichEditor = null; } - + // One more timeout to wait for focus to move to that editor setTimeout(function () { CommandManager.execute(selectedItem.id); }, 0); }, 0); } - - + + /** * Similar to default formatting, but with added text showing keybinding - * + * * @param {SearchResult} fileEntry * @param {string} query * @return {string} */ function resultFormatter(item, query) { var displayName = QuickOpen.highlightMatch(item); - + // Show shortcut on right of item // TODO: display multiple shortcuts // TODO: display which menu it's in also @@ -174,8 +174,8 @@ define(function (require, exports, module) { return "
  • " + displayName + "" + shortcut + "
  • "; } - - + + // Register as a new Quick Open mode QuickOpen.addQuickOpenPlugin( { @@ -191,23 +191,20 @@ define(function (require, exports, module) { resultsFormatter: resultFormatter } ); - + function beginSearchForCommands() { whichEditor = EditorManager.getFocusedEditor(); - + // Begin Quick Open in our search mode QuickOpen.beginSearch("?"); } - + // Register command as shortcut to launch this Quick Open mode var SEARCH_COMMAND_ID = "pflynn.searchCommands"; CommandManager.register("Search Commands", SEARCH_COMMAND_ID, beginSearchForCommands); - + var menu = Menus.getMenu(Menus.AppMenuBar.HELP_MENU); menu.addMenuDivider(Menus.FIRST); - menu.addMenuItem(SEARCH_COMMAND_ID, [ - {key: "Ctrl-Alt-/", displayKey: "Ctrl-Alt-?", platform: "win"}, - {key: "Ctrl-Cmd-/", displayKey: "Ctrl-Cmd-?", platform: "mac"} - ], Menus.FIRST); + menu.addMenuItem(SEARCH_COMMAND_ID, {key: "Ctrl-Shift-P", displayKey: "Ctrl-Shift-P"}, Menus.FIRST); }); diff --git a/package.json b/package.json index 5b44f10..d392b4c 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,5 @@ "author": "Peter Flynn", "version": "1.0.5", "engines": { "brackets": ">=0.16" }, - "description": "Search and execute commands by typing part of their name, similar to Quicksilver (or Sublime's Ctrl+Shift+P 'Command Palette' or Eclipse's Ctrl+3). Press Ctrl+Alt+? (\u2303\u2318? on Mac) to launch." -} \ No newline at end of file + "description": "Search and execute commands by typing part of their name, similar to Quicksilver (or Sublime's Ctrl+Shift+P 'Command Palette' or Eclipse's Ctrl+3). Press Ctrl+Shift+P (\u21E7\u2318P on Mac) to launch." +}