Trying to find where to disable individual keyboard shortcuts in the jQuery version of TinyMCE editor. Currently the list of allowable shortcuts is:
Currently looking to disable all shortcuts but Undo, Redo and bold. The rest are unnessary in our implementation due to it's unwanted formatting.
I can't seem to find the code that enables these shortcuts. Can you point out where to find this code.
Customize a keyboard shortcutOn the menu bar, choose Tools > Options. Expand Environment, and then choose Keyboard.
Initialize TinyMCE 5 on any element (or elements) on the web page by passing an object containing a selector value to tinymce. init() . The selector value can be any valid CSS selector. For example: To replace <textarea id="mytextarea"> with a TinyMCE 5 editor instance, pass the selector '#mytextarea' to tinymce.
Even though this has an accepted answer, I would share what I use with tinymce4. You can simply add editor.addShortcut('ctrl+u', "", "")
to the init
event method within the setup
method, which will override the added shortcut
Example:
tinyMCE.init({
// Your options here
setup: function(editor) {
editor.on("init", function(){
editor.addShortcut("ctrl+u", "", "");
});
}
})
You can replace any shortcut you'd like to disable with ctrl+u
in the above code.
Disable Tested in Firefox
This should help get you started. You might need to actually add empty shortcuts for ctrl+u
and ctrl+i
to disable it in other browsers, but this code has been tested to disable the actions in Firefox. Just run after the initialization of tinyMCE has run (I tested mine in Firebug):
for(var i in tinyMCE.editors){
var editor = tinyMCE.editors[i];
for(var s in editor.shortcuts){
var shortcut = editor.shortcuts[s];
// Remove all shortcuts except Bold (66), Redo (89), Undo (90)
if(!(s == "ctrl,,,66" || s == "ctrl,,,89" || s == "ctrl,,,90")){
// This completely removes the shortcuts
delete editor.shortcuts[s];
// You could use this instead, which just disables it, but still keeps
// browser functionality (like CMD+U = show source in FF Mac) from interrupting the flow
// shortcut.func = function(){ };
}
}
}
Background
It appears to be defined around line 2294
of jscripts/tiny_mce/classes/Editor.js
(From the full development download).
Also, they are stored in an array in the Editor.shortcuts
variable. They keys are setup with special chars then the keycode, like this: ctrl,,,90
.
But from what I can tell, it seems that many browser implement their own versions of ctrl+b
, ctrl+i
, and ctrl+u
and that only Gecko browsers do not:
// Add default shortcuts for gecko
if (isGecko) {
t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
}
But if you look around there, you can see how they enable it.
Additionally, look into the Editor.addShortcut
method. You might be able to override the default behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With