Created
April 7, 2016 15:46
-
-
Save jbeuckm/33250b18ec4ad298b903cfd15f89e2cf to your computer and use it in GitHub Desktop.
A Brackets extension to insert a promise-returning function stub.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | |
/*global define, $, brackets */ | |
define(function (require, exports, module) { | |
"use strict"; | |
var CommandManager = brackets.getModule("command/CommandManager"), | |
EditorManager = brackets.getModule("editor/EditorManager"), | |
Menus = brackets.getModule("command/Menus"); | |
function handlePromiseFunction() { | |
var editor = EditorManager.getFocusedEditor(); | |
if (editor) { | |
var insertionPos = editor.getCursorPos(); | |
editor.document.replaceRange("\ | |
function (){\n\ | |
var def = Q.defer();\n\ | |
\n\ | |
def.resolve();\n\ | |
\n\ | |
def.reject(err);\n\ | |
\n\ | |
return def.promise;\n\ | |
}\n", insertionPos); | |
} | |
} | |
var PF_COMMAND_ID = "promisefunction.insert"; | |
CommandManager.register("Promise Function", PF_COMMAND_ID, handlePromiseFunction); | |
var menu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU); | |
menu.addMenuItem(PF_COMMAND_ID); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment