-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
36 lines (27 loc) · 1.47 KB
/
main.js
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
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */
define(function (require, exports, module) {
"use strict";
var CommandManager = brackets.getModule("command/CommandManager"),
NodeDomain = brackets.getModule("utils/NodeDomain"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Menus = brackets.getModule("command/Menus"),
EditorManager = brackets.getModule('editor/EditorManager');
var escape = new NodeDomain("escape-html", ExtensionUtils.getModulePath(module, "node/escapeHtmlDomain"));
// Function to run when the menu item is clicked
function handleEscaping() {
let editor = EditorManager.getFocusedEditor();
let selections = editor.getSelections();
selections.forEach((selection)=>{
let text = editor.document.getRange(selection.start, selection.end);
if (!text || !text.length) return;
escape.exec("escapeHtml", text).done((result) => {
editor.document.replaceRange(result, selection.start, selection.end);
});
});
}
var MY_COMMAND_ID = "aqeelat.escapeHtml"; // package-style naming to avoid collisions
CommandManager.register("Escape HTML", MY_COMMAND_ID, handleEscaping);
var menu = Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
menu.addMenuItem(MY_COMMAND_ID);
});