Permalink
Browse files

added test runner and updated readme

  • Loading branch information...
1 parent 65f98cd commit a5a192e4c2d6c22ba66b19389f889a3ff267ca44 @pedelman committed Apr 7, 2013
Showing with 2,718 additions and 38 deletions.
  1. +8 −16 README.md
  2. BIN brackets_surround.gif
  3. +41 −22 main.js
  4. +18 −0 surround-input-modal.css
  5. +3 −0 templates/surround-input-modal.html
  6. +244 −0 test/qunit.css
  7. +2,182 −0 test/qunit.js
  8. +139 −0 test/runner.js
  9. +17 −0 test/test.html
  10. +66 −0 test/tests.js
View
@@ -6,19 +6,15 @@ Simply select the text you wish to surround and press ```Ctrl - Shift - J``` or
Install Brackets at: http://download.brackets.io/
-##### Step 1: Clone down the extension repo
-```
-git clone https://github.com/pedelman/brackets-surround.git
-```
-You can also click the download as zip button. Once downloaded, unzip the folder.
+##### Step 1: Click file -> "Install Extension"
-##### Step 2: In Brackets, click "Help"
-Once selected, click the show extension folder.
+Paste in the following URL
-##### Step 3: Copy over the folder into the "user" folder
-Drag the cloned folder into this folder.
+```
+https://github.com/pedelman/brackets-surround.git
+```
-##### Step 4: Restart brackets
+##### Step 2: Restart brackets
Restart Brackets to see the new plugin. To verify the extension was loaded, click "Edit" and you should see a option called "Surround".
### Surround is now installed and ready to go!
@@ -27,7 +23,7 @@ Restart Brackets to see the new plugin. To verify the extension was loaded, clic
#### Easy to add new functionality
-```js
+```
cases = {
'(' : ')',
'{' : '}',
@@ -40,8 +36,4 @@ cases = {
};
```
-Simply add a new key/value to the cases and it will instantly close the key.
-
-#### Example
-
-![brackets surround animation](brackets_surround.gif)
+Simply add a new key/value to the cases and it will instantly close the key.
View
Deleted file not rendered
View
63 main.js
@@ -15,28 +15,30 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
-/*global define, brackets, window */
+/*global define, brackets, window, $, Mustache */
define(function (require, exports, module) {
'use strict';
var CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus"),
EditorManager = brackets.getModule("editor/EditorManager"),
- QuickOpen = brackets.getModule("search/QuickOpen"),
- editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU),
+ ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
+ Dialogs = brackets.getModule("widgets/Dialogs"),
+ surroundHtml = require("text!templates/surround-input-modal.html"),
+ editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU),
COMMAND_ID = "pedelman.surround",
COMMAND_NAME = "Surround",
cases = {
'(' : ')',
'{' : '}',
+ '{{' : '}}',
'<' : '>',
'[' : ']',
'/*' : '*/',
@@ -45,13 +47,15 @@ define(function (require, exports, module) {
'<%=' : '%>'
};
+ ExtensionUtils.loadStyleSheet(module, "surround-input-modal.css");
+
/*
* _getSelectedText()
- * @private
+ * @private
* Returns the text that has been selected in the editor window in focus
*/
function _getSelectedText() {
- return EditorManager.getFocusedEditor().getSelectedText();
+ return EditorManager.getActiveEditor().getSelectedText();
}
/*
@@ -61,7 +65,8 @@ define(function (require, exports, module) {
* @param {String} str
*/
function _replaceActiveSelection(str) {
- EditorManager.getFocusedEditor()._codeMirror.replaceSelection(str);
+ EditorManager.getActiveEditor()._codeMirror.replaceSelection(str);
+ EditorManager.focusEditor();
}
/*
@@ -87,6 +92,9 @@ define(function (require, exports, module) {
function _closeHTML(str) {
var _tag_type = new RegExp("[a-zA-Z0-9]+", ""),
_tag = str.match(_tag_type);
+ if (_tag === "img") {
+ return false;
+ }
return ("</" + _tag + ">");
}
@@ -97,23 +105,34 @@ define(function (require, exports, module) {
*/
function surround() {
var _t = _getSelectedText(),
- _c = window.prompt("Surround Selection With:"),
_output = "";
- if (_c === null) {
- return;
- }
- if (cases[_c] !== undefined) {
- _output = _c + _t + cases[_c];
- } else {
- if (_isHTML(_c)) {
- _output = _c + _t + _closeHTML(_c);
- } else {
- _output = _c + _t + _c;
+ Dialogs.showModalDialogUsingTemplate(surroundHtml);
+
+ $('#surround_input').keypress(function (e) {
+ if (e.which === 13) {
+ e.preventDefault();
+ var _c = $('#surround_input').val();
+ console.log(_c);
+
+ if (_c === null) {
+ return;
+ }
+ if (cases[_c] !== undefined) {
+ _output = _c + _t + cases[_c];
+ } else {
+ if (_isHTML(_c)) {
+ _output = _c + _t + _closeHTML(_c);
+ } else {
+ _output = _c + _t + _c;
+ }
+ }
+ $('.surround_input').fadeOut(300);
+ Dialogs.cancelModalDialogIfOpen('.surround_input');
+ _replaceActiveSelection(_output);
}
- }
- _replaceActiveSelection(_output);
+ });
}
-
+
CommandManager.register(COMMAND_NAME, COMMAND_ID, surround);
editMenu.addMenuItem(COMMAND_ID, "Ctrl-Shift-J");
});
View
@@ -0,0 +1,18 @@
+.surround_input {
+ position: absolute;
+ top: 50%;
+ left: 25%;
+ z-index: 10001;
+ background: #F2F2F2;
+ padding: 10px;
+ border: 1px solid #CCC;
+ border-radius: 6px;
+ box-shadow: 0px 8px 23px rgba(50, 50, 50, 0.35);
+ width: 276px;
+}
+
+.surround_input input {
+ min-width: 260px;
+ padding: 5px;
+ outline: 0;
+}
@@ -0,0 +1,3 @@
+<div class="surround_input">
+ <input type="text" placeholder="Surround Selected text with:" autofocus="true" id="surround_input"/>
+</div>
Oops, something went wrong.

0 comments on commit a5a192e

Please sign in to comment.