├── .gitignore ├── CHANGELOG.md ├── spec ├── test.html └── wrap-in-tag-spec.coffee ├── images └── screenshot.gif ├── package.json ├── keymaps └── wrap-in-tag.cson ├── menus └── wrap-in-tag.cson ├── README.md ├── LICENSE.md └── lib └── wrap-in-tag.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.0 - First Release 2 | * Initial release 3 | -------------------------------------------------------------------------------- /spec/test.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. 2 | -------------------------------------------------------------------------------- /images/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanusart/atom-wrap-in-tag/HEAD/images/screenshot.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atom-wrap-in-tag", 3 | "main": "./lib/wrap-in-tag", 4 | "version": "0.6.1", 5 | "description": "Wrap tag around selection", 6 | "keywords": [], 7 | "activationCommands": { 8 | "atom-workspace": "wrap-in-tag:wrap" 9 | }, 10 | "repository": "https://github.com/sanusart/atom-wrap-in-tag", 11 | "license": "MIT", 12 | "engines": { 13 | "atom": ">=1.0.0 <2.0.0" 14 | }, 15 | "dependencies": {} 16 | } 17 | -------------------------------------------------------------------------------- /keymaps/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://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/ 10 | 'atom-workspace': 11 | 'alt-shift-w': 'wrap-in-tag:wrap' 12 | -------------------------------------------------------------------------------- /menus/wrap-in-tag.cson: -------------------------------------------------------------------------------- 1 | # See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details 2 | 'context-menu': 3 | 'atom-text-editor': [ 4 | { 5 | 'label': 'Wrap in tag' 6 | 'command': 'wrap-in-tag:wrap' 7 | } 8 | ] 9 | 'menu': [ 10 | { 11 | 'label': 'Packages' 12 | 'submenu': [ 13 | 'label': 'Wrap in tag' 14 | 'submenu': [ 15 | { 16 | 'label': 'Wrap' 17 | 'command': 'wrap-in-tag:wrap' 18 | } 19 | ] 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Atom wrap in tag 2 | 3 | > :rotating_light: **NOTE!** This plug-inis no longer maintained. It probably works and PRs probably will be merged, but I do not use Atom anymore (sorry). If anyone want to maintain this, I'll be happy to give commit rights or transfer it. 4 | 5 | Simplest package for [Atom](https://atom.io/) that wraps tag around selection - similar functionality found on other editors like PhpStorm, SublimeText, TextMate etc. 6 | 7 | Just select a word or phrase and hit Alt + Shift + w 8 | 9 | Hit spacebar key to continue typing attribute after the opening tag. 10 | 11 | ## Installation 12 | 13 | `apm install atom-wrap-in-tag` 14 | 15 | or find _atom-wrap-in-tag_ in **Settings** > **Install** tab 16 | 17 |  18 | 19 | ### License: 20 | 21 | MIT 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Sasha Khamkov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/wrap-in-tag-spec.coffee: -------------------------------------------------------------------------------- 1 | describe "atom wrap in tag", -> 2 | 3 | [workspaceElement, activationPromise] = [] 4 | 5 | packageLoaded = (callback) -> 6 | atom.commands.dispatch(workspaceElement, 'wrap-in-tag:wrap') 7 | waitsForPromise -> activationPromise 8 | runs(callback) 9 | 10 | beforeEach -> 11 | 12 | activationPromise = atom.packages.activatePackage('atom-wrap-in-tag') 13 | workspaceElement = atom.views.getView(atom.workspace) 14 | jasmine.attachToDOM(workspaceElement) 15 | 16 | waitsForPromise -> 17 | atom.workspace.open './test.html' 18 | 19 | it 'Should check if "atom-wrap-in-tag" package is loaded', -> 20 | packageLoaded -> 21 | expect(atom.packages.loadedPackages["atom-wrap-in-tag"]).toBeDefined() 22 | 23 | describe "When file is loaded", -> 24 | it "should have test.html opened in an editor", -> 25 | expect(atom.workspace.getActiveTextEditor().getText().trim()).toBe """ 26 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. 27 | """ 28 | 29 | describe "When file have selection", -> 30 | it "Should have 'ipsum dolor' selected", -> 31 | atom.workspace.getActiveTextEditor().setSelectedBufferRange [[0, 6], [0, 17]] 32 | atom.commands.dispatch atom.views.getView(atom.workspace), 'wrap-in-tag:wrap' 33 | expect(atom.workspace.getActiveTextEditor().getText().trim()).toBe """ 34 | Lorem
ipsum dolor
sit amet, consectetur adipiscing elit. 35 | """ 36 | -------------------------------------------------------------------------------- /lib/wrap-in-tag.coffee: -------------------------------------------------------------------------------- 1 | module.exports = 2 | 3 | activate: (state) -> 4 | 5 | atom.commands.add 'atom-workspace', 'wrap-in-tag:wrap': => @wrap() 6 | 7 | wrap: -> 8 | if editor = atom.workspace.getActiveTextEditor() 9 | editor.getSelections().map((item) -> wrapSelection(editor, item)) 10 | 11 | wrapSelection = (editor, selection) -> 12 | tag = 'p' 13 | text = selection.getText() 14 | tagRangePos = selection.getBufferRange() 15 | 16 | newText = ['<', tag, '>', text, '', tag, '>'].join('') 17 | 18 | range = 19 | start: 20 | from: [tagRangePos.start.row, tagRangePos.start.column+1] 21 | to: [tagRangePos.start.row, tagRangePos.start.column+2] 22 | end: 23 | from: [tagRangePos.end.row, tagRangePos.end.column+5], 24 | to: [tagRangePos.end.row, tagRangePos.end.column+6] 25 | 26 | if range.end.from[0] > range.start.from[0] 27 | range.end.from[1] = range.end.from[1] - 3 28 | range.end.to[1] = range.end.to[1] - 3 29 | 30 | newStartTagSelectRange = [range.start.from, range.start.to] 31 | newEndTagSelectRange = [range.end.from, range.end.to] 32 | 33 | selection.insertText(newText) 34 | selection.cursor.setBufferPosition([tagRangePos.start.row, tagRangePos.start.column+1]) 35 | editor.addSelectionForBufferRange(newStartTagSelectRange) 36 | endTagSelection = editor.addSelectionForBufferRange(newEndTagSelectRange) 37 | 38 | editorView = atom.views.getView editor 39 | editorView.addEventListener 'keydown', (event) -> 40 | if event.keyCode is 32 41 | endTagSelection.cursor.marker.destroy() 42 | @removeEventListener 'keydown', arguments.callee; 43 | --------------------------------------------------------------------------------