Re answer cited by the OP:
Edited to add meta and access and other.
这个
custom_shortcuts
提到的旗帜在tinymce 3中。x(参见
here) 但从4中删除。x、 在扫描震源时,似乎没有任何等效物被替代。
上面提到的foo函数方法仍然可以使用。在主题的“functions.php”中:
add_action( \'wp_tiny_mce_init\', function () {
?>
<script>
function wpse167402_tiny_mce_init(ed) {
ed.on(\'init\', function () {
// Note these lists may not be complete & that other tinymce plugins can add their own shortcuts anyway.
var ctrls = [ \'b\', \'i\', \'u\', \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'z\', \'y,ctrl+shift+z\', \'s\', \'k\', \'Alt+F\', \'P\', \'shift+e > ctrl+shift+p\' ]; // Could add \'x\', \'c\', \'v\'.
var metas = [ \'b\', \'i\', \'u\', \'z\', \'y,meta+shift+z\', \'s\', \'k\' ]; // Could add \'x\', \'c\', \'v\'.
var modKeys = [ \'c\', \'r\', \'l\', \'j\', \'q\', \'u\', \'o\', \'n\', \'s\', \'m\', \'z\', \'t\', \'d\', \'h\', \'o\', \'x\', \'a\', \'w\' ];
var accesss = [ \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'a\', \'s\', \'c\', \'r\', \'l\', \'j\', \'q\', \'u\', \'o\', \'m\', \'z\', \'t\', \'d\', \'h\', \'p\', \'x\' ];
var others = [ \'Ctrl+Shift+F\', \'Meta+K\', \'alt+119\', \'Alt+F10\', \'Alt+F9\', \'Alt+F10,F10\', \'Alt+F11\' ];
var i;
// Overwrite shortcuts with no-op function. Key sequences will still be captured.
for (i = 0; i < ctrls.length; i++ ) {
this.addShortcut(\'ctrl+\' + ctrls[i], \'\', function () {});
}
for (i = 0; i < metas.length; i++ ) {
this.addShortcut(\'meta+\' + metas[i], \'\', function () {});
}
for (i = 0; i < modKeys.length; i++ ) {
this.addShortcut(\'alt+shift+\' + modKeys[i], \'\', function () {});
}
for (i = 0; i < accesss.length; i++ ) {
this.addShortcut(\'access+\' + accesss[i], \'\', function () {});
}
for (i = 0; i < others.length; i++ ) {
this.addShortcut( others[i], \'\', function () {});
}
});
}
</script>
<?php
});
function wpse167402_tiny_mce_before_init( $mceInit ) {
$mceInit[\'setup\'] = \'wpse167402_tiny_mce_init\';
return $mceInit;
}
add_filter( \'tiny_mce_before_init\', \'wpse167402_tiny_mce_before_init\' );
Original answer
原来的答案取代了编辑的
shortcuts
无操作的对象
SettupEditor
在创建任何tinymce实例之前激发事件):
add_action( \'wp_tiny_mce_init\', function () {
?>
<script>
tinymce.on(\'SetupEditor\', function (editor) {
editor.shortcuts = { add: function() {} };
});
</script>
<?php
});
尽管这禁用了tinymce的所有快捷方式,但它有一个不幸的副作用,即允许默认浏览器行为,这对于
contentEditable
元素(tinymce的编辑框标记为)可以包括各种格式,如ctrl+b、ctrl+i和ctrl+u(关于这方面的文档很差),具体取决于浏览器。解决这个问题的一种方法是使用
cmdFunc
替换为noop函数:
add_action( \'wp_tiny_mce_init\', function () {
?>
<script>
tinymce.on(\'SetupEditor\', function (editor) {
var orig_shortcuts_add = editor.shortcuts.add;
editor.shortcuts.add = function(pattern, desc, cmdFunc, scope) {
return orig_shortcuts_add(pattern, desc, function () {}, scope);
};
});
</script>
<?php
});