├── .gitignore ├── README.md ├── menus └── atom-wrap-in-tag.cson ├── keymaps └── atom-wrap-in-tag.cson ├── package.json ├── index.js └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | scratch 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # atom-wrap-in-tag package 2 | 3 | A short description of your package. 4 | 5 | ![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif) 6 | -------------------------------------------------------------------------------- /menus/atom-wrap-in-tag.cson: -------------------------------------------------------------------------------- 1 | # See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details 2 | 'menu': [ 3 | { 4 | 'label': 'Packages' 5 | 'submenu': [ 6 | 'label': 'Wrap In Tag' 7 | 'submenu': [ 8 | { 9 | 'label': 'Wrap' 10 | 'command': 'atom-wrap-in-tag:wrap' 11 | } 12 | ] 13 | ] 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /keymaps/atom-wrap-in-tag.cson: -------------------------------------------------------------------------------- 1 | # Keybindings require three things to be fully defined: A selector that is 2 | # matched against the focused element, the keystroke and the command to 3 | # execute. 4 | # 5 | # Below is a basic keybinding which registers on all platforms by applying to 6 | # the root workspace element. 7 | 8 | # For more detailed documentation see 9 | # https://atom.io/docs/latest/behind-atom-keymaps-in-depth 10 | 'atom-text-editor': 11 | 'ctrl-w': 'wrap-in-tag:wrap' 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atom-wrap-in-tag", 3 | "main": "./lib/atom-wrap-in-tag", 4 | "version": "0.0.1", 5 | "description": "Wrap the selection in an HTML tag", 6 | "keywords": [ 7 | ], 8 | "activationCommands": { 9 | "atom-text-editor": "wrap-in-tag:wrap" 10 | }, 11 | "activationHooks": ["language-html:grammar-used"], 12 | "repository": "https://github.com/atom/atom-wrap-in-tag", 13 | "license": "MIT", 14 | "engines": { 15 | "atom": ">=1.0.0 <2.0.0" 16 | }, 17 | "dependencies": { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | exports.activate = function () { 3 | console.log('activated'); 4 | atom.commands.add('atom-text-editor', { 5 | 'wrap-in-tag:wrap': function () { 6 | wrap(atom.workspace.getActiveTextEditor()); 7 | } 8 | }); 9 | } 10 | 11 | function wrap (editor) { 12 | console.log('wrapping'); 13 | if (!editor) return; 14 | var buffer = editor.getBuffer() 15 | , ranges = editor.getSelectedBufferRanges() 16 | ; 17 | // for each range: 18 | // insert "<>" before and "" after 19 | // position cursors inside those tags 20 | // let user type at those positions 21 | // the hard bit: when the user hits space, you only want to keep the cursors that are in 22 | // the start tag 23 | ranges 24 | .forEach(function (range) { 25 | var start = range.start 26 | , end = range.end 27 | ; 28 | buffer.insert(start, "<>", { undo: true }); 29 | buffer.insert(end, "", { undo: true }); 30 | editor.addCursorAtBufferPosition([start.row, start.column - 1]); 31 | editor.addCursorAtBufferPosition([end.row, end.column + 2]); 32 | }) 33 | ; 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Robin Berjon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | --------------------------------------------------------------------------------