Is it possible to check the possibility of pressing ctr + z in Js? that is, if for example you changed something on the page, you can cancel it by pressing ctr + z, how can you track what is in that buffer undo? Here is an example.

<button id="undo" title="ctrl + Z" >Undo</button><button id="redo" title="ctrl + Y" disabled>Redo</button> <div class="phones" contenteditable="true"><span>8 (925) 505-55-55</span> <br /><span>8 (925) 505-55-55</span></div> 

When changing the text, I would like the buttons to change the activity

1 answer 1

You need to create a separate variable var stringBuffer and place text there with each press. If you need the ability to cancel several times, then you need a list where to add a new element to the end with each new text change. To register a change, you need to keep track of situations where the user does not print anything, for example, 2 seconds, and then compare the last element of the list with what the user has on the screen.