I am trying to make an undo function in a textarea as I find the native one on IE "Have to use it at work" to be lacking.
The idea is to push to the array anytime the user presses space, backspace, delete, or they right click the mouse. Where I am having trouble is navigating through the array "history" with the Z key. I was thinking that if I make a counter increment every time the Z key is pressed then minus that from array.length it would allow me to move through the history.
Here is a JSFiddle I made for testing http://jsfiddle.net/synthet1c/5fqe3/2/
here is the part of the script I am having issues with
//keypress listener script
var pos = undo.length - 1
if(key_code == "90"){
var counter = 0
counter++;
var newCount = pos - counter;
e.preventDefault();
id("myTextarea").value = undo[newCount] + " ";
id('counter').innerHTML = counter;
}
Also any ideas on only pushing just the last word into the array when pressing spacebar to save on memory would be great.