0

I can't see whether the gaps at the beginning of new lines in Codemirror (in Joomla, in my case) are spaces or tabs.

Is there a way to display them?

1

Tabs can be styled in CSS using .cm-tab selector. See demo https://codemirror.net/demo/visibletabs.html.

For other invisibles, you could use CodeMirror Show Invisibles addon https://github.com/coderaiser/cm-show-invisibles. It can be integrated into Joomla! using a plugin which loads the script during onCodeMirrorBeforeDisplay event:

defined('_JEXEC') or exit;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;

class PlgEditors_CodemirrorShowinvisibles extends CMSPlugin
{
    public function onCodeMirrorBeforeDisplay($displayData)
    {
        // Load the addon script.
        HTMLHelper::_('script', 'plg_editors_codemirror_showinvisibles/show-invisibles.js', ['relative' => true]);

        // Set the flag for showing invisibles.
        $displayData->options->showInvisibles = true;
    }
}
0

If you are only differentiating between spaces and tabs, the most instant solution is probably to use your browser's Find tool. On Chrome, this is Ctrl+F. Type a space into the search box. If the targeted whitespace character does not receive the yellow highlight, then it is a tab. Try the technique here: https://3v4l.org/MIF6B

Also at your disposal is the Inspect dev tool, this is Ctrl+Shft+I. Access the text in the element of the inspector and highlight the whitespace by click-dragging over it. If it jumps more than one space, it's a tab.

Another way is to copy all of your raw text, paste it into regex101.com, then write \t into the pattern field. It will highlight all of the tabs in the text.

I am sure that there are more ways to do this, but these seem pretty easy to me.

1
  • Thanks, but I'd much rather be able to use something like regex101.com's \t within Codemirror rather than copying code back and forth or highlighting individual spaces/tabs with the browser's inspector. However, looking at Codemirror's github it seems that this option has been rejected some years ago. They mention styling spaces with CSS. I will look at that.
    – Gillian
    Feb 2 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.