Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement undo/redo when changing the content of the textarea #6

Open
cnicodeme opened this issue Mar 17, 2014 · 0 comments
Open

Implement undo/redo when changing the content of the textarea #6

cnicodeme opened this issue Mar 17, 2014 · 0 comments

Comments

@cnicodeme
Copy link

Hi! :)

Great plugin, I'm gonna use it for my project, but I think it's missing something really interesting : the ability to undo/redo (ctrl+z / ctrl+shit+z) from the natural work of the browser.

Let me explain

If you write on a textarea, and then hit ctrl+z, you'll do a undo changes (based on your browser).

But if you do a insert/replace from your code, and then hit ctrl+z, it won't work.

The idea behind it is to not change the val() of the textarea, but use the builtin changes of the browser, like this :

var element = document.getElementById('someTextarea');
var text = 'This text will be inserted in the textarea';
var event = document.createEvent('TextEvent');

event.initTextEvent('textInput', true, true, null, text);
element.dispatchEvent(event); // fire the event on the the textarea

(source: http://stackoverflow.com/questions/7553430/javascript-textarea-undo-redo)

Drawback: this does not work in IE9 and Firefox :/
(Maybe i'm asking for an unicorn feature ?)

Here's a possible implementation :
http://stackoverflow.com/questions/19814465/is-it-possible-to-insert-text-in-textarea-and-update-undo-redo-queue

And for IE (11) : http://stackoverflow.com/questions/20124212/internet-explorer-alternative-to-document-execcommandinserttext-for-tex

In case you have some spare time! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant