Nijesh W
Nijesh W

Reputation: 57

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.

Upvotes: 1

Views: 1941

Answers (3)

chavy
chavy

Reputation: 1068

Found the answer for RMB right here

editor.container.addEventListener("contextmenu", function(e) {
    e.preventDefault();
    alert('success!');
    return false;
}, false);

Upvotes: 0

a user
a user

Reputation: 24104

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)

Upvotes: 3

Rainb
Rainb

Reputation: 2465

You can benefit from this issue on github https://github.com/ajaxorg/ace/issues/266

To hide cursor and line highlights

editor.setOptions({
    readOnly: true,
    highlightActiveLine: false,
    highlightGutterLine: false
})

editor.renderer.$cursorLayer.element.style.opacity=0 to make editor non tabbable

editor.textInput.getElement().tabIndex=-1

or

editor.textInput.getElement().disabled=true

to disable all shortcuts

editor.commands.commmandKeyBinding={}

Upvotes: 0

Related Questions