开发者

undo/redo event binding

开发者 https://www.devze.com 2023-01-27 06:03 出处:网络
I found some interesting javascript undo managers and –of course– we have the one that will be eventually implemented in the browser with HTML5.

I found some interesting javascript undo managers and –of course– we have the one that will be eventually implemented in the browser with HTML5.

Now, what I'm not sure about is how to capture user actions meant to trigger 'undo' with jQuery to drive the UndoManager:

  • Ctrl+Z, Ctrl+Shift+Z
  • Cmd+Z, Cmd+Shift+Z
  • User clicking on the Edit>Undo or Edit>Redo menu in their browsers

My first stab at it would be this:

function keypress(e){
  if (e.metaKey) {
    Collage.console(e);
    switch(e.keyCode){
    case 122: // Mac
      if (e.shiftKey) {
        undoManager.redo(e);
      } else {
        undoManager.undo(e);
      }
    case 26: // PC
      if (e.shiftKey) {
        undoManager.redo(e);
      } else {
        undoManager.undo(e);
      }
    }
  }
};

$('#my-thing-with-undos').bind('keypress', keypress);

but how do I ensure that the (modern) browser's Edit menu keeps up with the program?

I really don't want the brows开发者_JAVA技巧er to attempt to figure out what and how to undo in that region or, at least, not to perform an edit to it (it's a contenteditable = true region).


I don't think you can trigger default browser events...

that in mind use an array to store ever keystroke of a particular time. e.g.

if i type "hello world " which in a second or if i continuesly keep typing keep recording the characters. when the users stops typing more than a second then push it to an array that way u have more control of the changes.

another thing is that this is a bad feeling. but im sure that 26 and 122 does not stand for ctrl + z most likely it's for the z it self or the control.

0

精彩评论

暂无评论...
验证码 换一张
取 消