我想在禁用它后简单地重新启用命令... 这就是我简单禁用它的方式:
editor.commands.removeCommand("backspace");
但现在我需要再次启用它,但我不知道该怎么做......
我找到了像this这样的东西,但这很难......
有没有办法简单地重新启用它?
请帮助..
答案 0 :(得分:1)
您可以保留对该命令的引用,以便稍后将其添加回来
var command = editor.commands.byName.backspace
editor.commands.removeCommand(command)
editor.commands.addCommand(command)
或仅删除密钥
function setCommandEnabled(editor, name, enabled) {
var command = editor.commands.byName[name]
if (!command.bindKeyOriginal)
command.bindKeyOriginal = command.bindKey
command.bindKey = enabled ? command.bindKeyOriginal : null;
editor.commands.addCommand(command);
// special case for backspace and delete which will be called from
// textarea if not handled by main commandb binding
if (!enabled) {
var key = command.bindKeyOriginal;
if (key && typeof key == "object")
key = key[editor.commands.platform];
if (/backspace|delete/i.test(key))
editor.commands.bindKey(key, "null")
}
}
然后致电
setCommandEnabled(editor, "backspace", false)
setCommandEnabled(editor, "backspace", true)