Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyMCE: Shortcut [Ctrl] + [Shift] + [Space] to insert non-breaking spaces #44702

Open
AK-CCM opened this issue Jan 9, 2025 · 6 comments
Open

Comments

@AK-CCM
Copy link

AK-CCM commented Jan 9, 2025

Is your feature request related to a problem? Please describe.

If I want to insert a non-breaking space   in the editor I have to click on the icon in the toolbar or choose the menu item in the Edit menu. This is cumbersome and interrupts the flow of writing every time.

Image

Image

Describe the solution you'd like

It would be great if non-breaking spaces could easily inserted by the shortcut [Ctrl] + [Shift] + [Space] like in Microsoft Word or LibreOffice Writer.

Additional context

https://www.tiny.cloud/docs/tinymce/latest/shortcuts/

@AK-CCM
Copy link
Author

AK-CCM commented Jan 11, 2025

In the tiny docu I found some infos about howto add custum shortcuts. Unfortunately, I am already failing to get the shortcut ctrl + shift + spacebar in the example to work: https://codepen.io/AK-CCM/pen/wBwmdbg.

@brianteeman
Copy link
Contributor

the demo on that page for inserting a username doesnt work either. Not sure what anyone at joomla can do to help you with that. You should contact tinymce

@AK-CCM
Copy link
Author

AK-CCM commented Jan 11, 2025

I've saved these lines (ChatGPT helped me and in CodePen it works) in plugin.js and uploaded the file to /home/www/.../media/plg_editors_tinymce/js/plugins/shortcut-nonbreaking

tinymce.PluginManager.add('shortcut-nonbreaking', function(editor) {
// Add a custom keyboard shortcut
editor.addShortcut('meta+shift+9', 'Add a non-breaking space', function() {
// Insert a non-breaking space at the current cursor position
editor.execCommand('mceInsertContent', false, '<span class="mce-nbsp-wrap mce-nbsp" contenteditable="false"> </span>');
});
});

After that I've added in the tinymce plugin at External Plugin URLs:
Plugin Name: shortcut-nonbreaking
Path: /media/plg_editors_tinymce/js/plugins/shortcut-nonbreaking

After saving changes I cleared the cache, opened an article, clicked in the editor and tried to insert a nbsp with Ctrl + Shift + 9. But nothing happens.

Did I made the plugin implementation correct?

@brianteeman
Copy link
Contributor

try
Path: /media/plg_editors_tinymce/js/plugins/shortcut-nonbreaking/plugin.min.js

@AK-CCM
Copy link
Author

AK-CCM commented Jan 11, 2025

thx4hint! I've forgotten the file in the path.

Here's my actual plugin.js – it works fine to insert a nbsp with ctrl + shift + 9:

tinymce.PluginManager.add('shortcut-nonbreaking', function(editor) {
// Add a custom keyboard shortcut: ctrl + shift + 9
editor.addShortcut('ctrl+shift+9', 'Insert nonbreaking space at cursor position or selection', function() {
// Insert a nonbreaking space using TinyMCE's command
tinymce.activeEditor.execCommand('mceNonBreaking');
});
});

But if I change the key combination to ctrl+shift+space nothing happens when I press ctrl + shift + spacebar.

@AK-CCM
Copy link
Author

AK-CCM commented Jan 12, 2025

These lines work fine:

tinymce.PluginManager.add('shortcut-nonbreaking', function(editor) {
    // Listen for the keydown event to capture Ctrl + Shift + Spacebar
    editor.on('keydown', function(e) {
        // Check if Ctrl, Shift, and Spacebar are pressed simultaneously
        if (e.ctrlKey && e.shiftKey && e.key === ' ') {
            e.preventDefault(); // Prevent the browser from handling the Spacebar normally
            editor.execCommand('mceNonBreaking'); // Insert a non-breaking space
        }
    });
});

Perhaps this functionality could be merged to Joomla?
I've attached the zipped plugin.js, plugin.min.js and plugin.min.js.gz.

shortcut-nonbreaking.zip

@alikon alikon added the Feature label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants