is-undo-redo
Version:
check if a key event is undo or redo
43 lines (27 loc) • 1.13 kB
Markdown
[](http://github.com/badges/stability-badges)
Check if a key event is undo or redo. This uses Cmd+Z or Ctrl+Z for undo, and Cmd+Shift+Z or Ctrl+Shift+Z for redo.
```js
var events = require('dom-events')
var isUndo = require('is-undo-redo').undo
var isRedo = require('is-undo-redo').redo
events.on(element, 'keydown', function(ev) {
if (isUndo(ev)) {
//.. handle undo
} else if (isRedo(ev)) {
//.. handle redo
}
})
```
[](https://nodei.co/npm/is-undo-redo/)
You can specify a `style` string to explicitly allow one keystroke or the other:
- `"mac"` only allows Cmd+Z and Cmd+Shift+Z
- `"windows"` only allows Ctrl+Z and Ctrl+Shift+Z
If no style is specified, both will be accepted.
Returns true if the key event was either undo or redo.
MIT, see [LICENSE.md](http://github.com/mattdesl/is-undo-redo/blob/master/LICENSE.md) for details.