禁用Chrome的文本输入撤消/重做(CTRL + Z / CTRL + Y) [英] Disable Chrome's text input undo/redo (CTRL+Z / CTRL+Y)

查看:248
本文介绍了禁用Chrome的文本输入撤消/重做(CTRL + Z / CTRL + Y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个web应用程序,并遇到一个问题。
正如你可能知道或不知道的那样,当你按CTRL + Z时,chrome有一个功能可以给出< input> (特别是文本输入)和一个undo和重做与CTRL + Y它可能看起来像一个很好的功能,在正常的网站,但目前我正在做一个图像编辑器也使用这些键盘快捷键(CTRL + Z& CTRL + Y)。 b
$ b

在我的应用程序中,我也有一个文本输入,因此,当我更改文本输入的内容,然后按Ctrl + Z撤消图像编辑器中的更改时,它将撤消文本编辑器!



这是 Codepen 会显示效果
(指令在Codepen中)

所以最后我想删除chrome中的撤消/重做功能,我怎么能这样做吗?

解决方案

var ctrlDown = false; var ctrlKey = 17,vKey = 86,cKey = 67,zKey = 90; document.body.onkeydown = function(e){if(e.keyCode == 17 || e.keyCode == 91){ctrlDown = true; }((ctrlDown& e.keyCode == zKey)||(ctrlDown&& e.keyCode == vKey)||(ctrlDown&& e.keyCode == cKey)){的preventDefault();返回false; }} document.body.onkeyup = function(e){if(e.keyCode == 17 || e.keyCode == 91){ctrlDown = false; };};

< body> < input type ='text'value ='test'/>< / body>

这是否工作?



在这里,在这里找到@KadeHafen的评论。


i'm currently developing a web application and i encounter a problem. As you might know or not, chrome has a feature that gives <input> (especially text inputs) an "undo" function when you hit CTRL+Z and "redo" with CTRL+Y it may seem like a good feature in normal websites, but currently i'm making an image editor that also uses those keyboard shortcuts (CTRL+Z & CTRL+Y).

in my app i also have a text input, so when i change the text input's content and then hit CTRL+Z to undo the changes in my image editor, it would undo the change in the text editor instead!

here is a Codepen that would demonstrate the effect
(instruction is in the Codepen)

So in conclusion i want to remove the undo/redo function in chrome how can i do that?

解决方案

var ctrlDown = false;
var ctrlKey = 17, vKey = 86, cKey = 67, zKey = 90;

document.body.onkeydown = function(e) {
  if (e.keyCode == 17 || e.keyCode == 91) {
    ctrlDown = true;
  }
  if ((ctrlDown && e.keyCode == zKey) || (ctrlDown && e.keyCode == vKey) || (ctrlDown && e.keyCode == cKey)) {
    e.preventDefault();
    return false;
  }
}
document.body.onkeyup = function(e) {
  if (e.keyCode == 17 || e.keyCode == 91) {
    ctrlDown = false;
  };
};

<body>
    <input type='text' value='test' />
</body>

Does this work?

Stolen from here, found on here as a comment by @KadeHafen.

这篇关于禁用Chrome的文本输入撤消/重做(CTRL + Z / CTRL + Y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆