Search code examples
angulartypescriptace-editor

How to disable Copy, Paste and Droping text in ng2-ace-editor


Is there is any way to disable Copy, Paste and Dropping text in ng2-ace-editor. https://github.com/fxmontigny/ng2-ace-editor This is the one I have used in my angular 5 app.


Solution

  • to disable clipboard add the following command:

    editor.commands.addCommand({
        name: "breakTheEditor", 
        bindKey: "ctrl-c|ctrl-v|ctrl-x|ctrl-shift-v|shift-del|cmd-c|cmd-v|cmd-x", 
        exec: function() {} 
    });
    

    to disable dragging use

    ![
        "dragenter", "dragover", "dragend", "dragstart", "dragleave", "drop"
    ].forEach(function(eventName) {
        editor.container.addEventListener(eventName, function(e) {
            e.stopPropagation()
        }, true)
    });
    editor.setOption("dragEnabled", false)