Skip to content

Copy and paste only from Ace editor #5068

Answered by nightwing
krishnagogada asked this question in Q&A
Discussion options

You must be logged in to vote

You can use paste and copy events

var lastCopiedText = ""
editor.on("paste", function(e) {
    if (lastCopiedText != e.text) {
        alert(`
             An attempt to paste text not copied from the editor is detected.
             And it will not be tolerated!
             Use browser developer tools to circumvent this annoyance.
        `)
    }
    e.text = lastCopiedText
})
editor.on("copy", function(e) {
    lastCopiedText = e.text
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by krishnagogada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants