-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
46 lines (40 loc) · 2.12 KB
/
main.js
File metadata and controls
46 lines (40 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*!
* Brackets html-comment-button 0.1
* Dreamweaver style comments button for wrapping selected text in html comments without using your keyboard
*
* @author Reece Griffin
* @license none - steal this software!
*/
define( function( require, exports, module ) {
'use strict';
var AppInit = brackets.getModule( 'utils/AppInit' ),
Document = brackets.getModule( 'document/Document' ),
Editor = brackets.getModule( 'editor/Editor' ),
EditorManager = brackets.getModule( 'editor/EditorManager' ),
CommandManager = brackets.getModule( 'command/CommandManager' ),
Commands = brackets.getModule( 'command/Commands' ),
ExtensionUtils = brackets.getModule( 'utils/ExtensionUtils' ),
$todoIcon = $( '<a href="#" title="Add/remove HTML comment to/from selection." id="html-comment-button"></a>' );
ExtensionUtils.loadStyleSheet( module, 'html-comment-button.css' );
// Register extension.
CommandManager.register( "Add / Remove HTML Comment", "com.reecegriffin.html-comment-button.docomment", doComment );
function doComment(){
var ed = EditorManager.getCurrentFullEditor();
var selection = ed.getSelection(), doc = ed.document,r;
if((selection.start.line == selection.end.line) && (selection.start.ch == selection.end.ch)){//no current selection
return;
}
if((ed.getSelectedText().trim().indexOf("<!--") == 0) && (ed.getSelectedText().trim().lastIndexOf("-->") == (ed.getSelectedText().trim().length-3))){//remove an existing comment
r=ed.getSelectedText().substring(ed.getSelectedText().indexOf("<!--")+4, ed.getSelectedText().lastIndexOf("-->"));
doc.replaceRange(r, selection.start, selection.end);
}else{
doc.replaceRange("<!--"+ed.getSelectedText()+"-->", selection.start, selection.end);
}
}
AppInit.appReady( function() {
// Add listener for toolbar icon..
$todoIcon.click( function() {
CommandManager.execute( "com.reecegriffin.html-comment-button.docomment" );
} ).appendTo( '#main-toolbar .buttons' );
} );
});