amitkarmakar
amitkarmakar

Reputation: 1243

Modify undo/redo behaviour on a textarea using jquery

I need to handle the events undo and redo myself when a user selects undo/redo from context menu or presses ctrl z in a textarea. How can i prevent the default behavior and add custom behavior.

Upvotes: 2

Views: 1530

Answers (1)

elclanrs
elclanrs

Reputation: 94101

You can detect ctrl+z on keyup() with:

var ctrlZ = e.ctrlKey && e.which === 90
if (ctrlZ) { ... } 

And context menu on mousedown() with:

var rightClick = e.which === 2
if (rightClick) { ... }

Upvotes: 4

Related Questions