sieukrem / jn-npp-plugin

Plugin for Notepad++ allowing you to automate some tasks using JavaScript
https://github.com/sieukrem/jn-npp-plugin/wiki
110 stars 24 forks source link

How to set shortcut to menu item? #55

Closed yanggeorge closed 7 years ago

yanggeorge commented 7 years ago

I have added a new Menu Item to treat JSON escape and un-escape. jn is very good. But I can not find how to set shortcut for my cmd. Can you help me ?

escape_json_string = function (str) {
    return str
        .replace(/[\\]/g, "\\\\")
        .replace(/[\"]/g, "\\\"")
        .replace(/[\/]/g, "\\/")
        .replace(/[\b]/g, "\\b")
        .replace(/[\f]/g, "\\f")
        .replace(/[\n]/g, "\\n")
        .replace(/[\r]/g, "\\r")
        .replace(/[\t]/g, "\\t");
};
unEscape_json_string = function (str) {
    return str
        .replace(/\\\\/g, "\\")
        .replace(/\\"/g, "\"")
        .replace(/\\\//g, "\/")
        .replace(/\\b/g, "\b")
        .replace(/\\f/g, "\f")
        .replace(/\\n/g, "\n")
        .replace(/\\r/g, "\r")
        .replace(/\\t/g, "\t");
};

var escape_unEscape_json_str = Editor.addMenu('JSON-Escape/UnEscape');
escape_unEscape_json_str.addItem({
    text:'Escape',
    cmd:function(){
        var un_escape_text = Editor.currentView.text;
        var escape_text = escape_json_string(un_escape_text);
        Editor.currentView.text = escape_text;
    }
});

escape_unEscape_json_str.addItem({
    text:'UnEscape',
    cmd: function () {
        var escape_text = Editor.currentView.text;
        var un_escape_text = unEscape_json_string(escape_text);
        Editor.currentView.text = un_escape_text;
    }
});
sieukrem commented 7 years ago

You can find here an example

yanggeorge commented 7 years ago

Excellent! Thanks!