? Language Change NPM Resource Changed ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
22 Sep 2021

This PR
changes the source code view of tinymce from raw text to a rich syntax highlighted area using codemirror.

It is enabled by default but there is an option in the plugin to disable it - can't imagine why someone would want though.

There are no additional tinymce strings to translate as I have reused existing strings.

As the code plugin is enabled by default in set 0 for super users you can activate the view either from the tools menu or the <> icon. If it is not enabled in your configuration then you will need to drag and drop the icon to your toolbar in the tinymce plugin

Before

image

After

image

As you can see you now also have search and replace etc.

Testing

Apply the pr and run npm ci
AND copy the file build/media_source/plg_editors_tinymce/js/plugins/highlighter/source.html to `media/plg_editors_tinymce/js/plugins/highlighter/source.html

Why this is a draft

I need help building the source.html file with our build scripts. I am guessing it will be built similar to the error pages

Thanks to @woluweb and @dgrammatiko

avatar brianteeman brianteeman - open - 22 Sep 2021
avatar brianteeman brianteeman - change - 22 Sep 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Sep 2021
Category Administration Language & Strings JavaScript Repository NPM Change Front End Plugins
avatar dgrammatiko
dgrammatiko - comment - 22 Sep 2021

I need help building the source.html file with our build scripts. I am guessing it will be built similar to the error pages

This is getting complicated due to the fact that the output is an HTML page and we don't want the sources in the media folder. I would just concatenate the source script and CSS in the HTML directly (non minified, it's not that much code anyway) and delete the js and css sources.

avatar brianteeman
brianteeman - comment - 22 Sep 2021

hint?

avatar dgrammatiko
dgrammatiko - comment - 22 Sep 2021

source.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <script>
// copy the contents of source.es5.js here
    </script>
    <style type="text/css">
// copy the contents of source.css here
    </style>
  </head>
  <body></body>
</html>

Delete the extra files

avatar brianteeman
brianteeman - comment - 22 Sep 2021

oh - didnt realise thats what you meant

avatar woluweb
woluweb - comment - 23 Sep 2021

Txs @dgrammatiko for your plugin and txs @brianteeman for implementing this PR!
This is very exciting.
It will be so handy on a day-to-day basis... and also it will give an extra incentive to use TinyMCE and stick to the core :)

If I may, I have two suggestions:

1. making the popup (almost) fullscreen?

At present the size of the popup is (only) 800x550, which is quite small especially to work comfortably with html code.
When testing Dimitris' plugin, I "cheated" by adding the following in Atum's user.css to go (almost) full-screen, since it is a popup anyway:

.tox-dialog {
    width: calc(100vw - 100px) !important;
    max-width: unset !important;
    height: calc(100vh - 100px) !important;
    max-height: unset !important;
}

But it would probably be nicer to have it natively.

Alternatively, if it is possible to implement the "fullscreen shortcut" (F10) (which works when selecting CodeMirror editor itself, even if there is a positioning issue bc the first lines are hidden behind the Save buttons bar), that could also solve the issue of the popup being "too small".

2. using the options of CodeMirror Plugin?

The popup with Syntax Highliting uses CodeMirror, but does not seem to use the Options set in the CodeMirror Plugin (it uses the default I guess).
I am already very happy as it is now, obviously.
But I wanted to mention it just in case it would be easy to apply CodeMirror Plugin Options.

avatar brianteeman
brianteeman - comment - 23 Sep 2021

I am looking at both those points

avatar dgrammatiko
dgrammatiko - comment - 23 Sep 2021

I "cheated" by adding the following in Atum's user.css

This has weird implications as it will make ALL the tinyMCE dialogs almost fullscreen. There's another way for this

but does not seem to use the Options set in the CodeMirror Plugin

Since I didn't wanted to create a Joomla plugin I left this with some defaults but it is possible to have the options exposed in the tinyMCE's configuration. Basically all it's needed is:

  • remove this part from the source.js
// CodeMirror settings
 const CMsettings = {
   path: '../../../../vendor/codemirror',
   indentOnInit: true,
// start remove
   config: {
     mode: 'htmlmixed',
     theme: 'default',
     lineNumbers: true,
     lineWrapping: true,
     indentUnit: 2,
     tabSize: 2,
     indentWithTabs: true,
     matchBrackets: true,
     saveCursorPosition: true,
     styleActiveLine: true,
   },
// end remove
   jsFiles: [// Default JS files
     'lib/codemirror.min.js',
     'addon/edit/matchbrackets.min.js',
     'mode/xml/xml.min.js',
     'mode/javascript/javascript.min.js',
     'mode/css/css.min.js',
     'mode/htmlmixed/htmlmixed.min.js',
     'addon/dialog/dialog.min.js',
     'addon/search/searchcursor.min.js',
     'addon/search/search.min.js',
     'addon/selection/active-line.min.js',
   ],
   cssFiles: [// Default CSS files
     'lib/codemirror.css',
     'addon/dialog/dialog.css',
   ],
 };
  • in the tinyMCE.php pass the options like:
$scriptOptions['codemirror'] = [
  'settings' => [
    'indentOnInit' =>  true, // the true should be $levelParams->get('codemirroe_settings_indentoninit'); which is a toogle in the settings form
  ]
] 
avatar brianteeman
brianteeman - comment - 23 Sep 2021

yeah I know ;)
I just wanted to put up a quick draft so I could ask about the html file

avatar dgrammatiko
dgrammatiko - comment - 23 Sep 2021

About the maximised modal, this should do it:

    const rects = document.body.getBoundingClientRect();

    const config = {
      title: 'HTML source code',
      url: url + '/source.html',
      width: rects.width - 5,
      height: rects.height - 150,
      resizable: true,
      maximizable: true,
      fullScreen: true,
      saveCursorPosition: false,
      buttons: buttonsConfig
    }

Result:
Screenshot 2021-09-23 at 15 27 31

avatar bembelimen
bembelimen - comment - 19 Oct 2021

Should this really be 4.0 or is 4.1 the target? If later, would be happy to include it.

avatar woluweb
woluweb - comment - 19 Oct 2021

Should this really be 4.0 or is 4.1 the target? If later, would be happy to include it.

Well, it is not up to me to say but I hope we won't have to wait until 4.1 for Syntax Highlighting :)

avatar brianteeman brianteeman - change - 22 Oct 2021
Title
Tiny source code syntax highlighting
[4.1] Tiny source code syntax highlighting
avatar brianteeman brianteeman - edited - 22 Oct 2021
avatar brianteeman brianteeman - change - 25 Oct 2021
Labels Added: Language Change ? NPM Resource Changed ?
avatar brianteeman
brianteeman - comment - 25 Oct 2021

@Fedik please could you review and check the changes you requested

avatar Fedik
Fedik - comment - 25 Oct 2021

@brianteeman they looks good now :)

avatar dgrammatiko
dgrammatiko - comment - 28 Oct 2021
avatar brianteeman
brianteeman - comment - 28 Oct 2021

hound says no ??

avatar dgrammatiko
dgrammatiko - comment - 28 Oct 2021

Hound was removed many months ago, I have no clue why you still have that around

@brianteeman it should be fine now

avatar brianteeman brianteeman - change - 22 Nov 2021
Labels Removed: ?
avatar brianteeman
brianteeman - comment - 22 Nov 2021

conflicts resolved

avatar chmst
chmst - comment - 22 Nov 2021

Tested on a fresh installation of 4.1. dev on a new database. Applied Patch, run npm ci..

@brianteeman could you please remove the testing instruction here:
AND copy the file build/media_source/plg_editors_tinymce/js/plugins/highlighter/source.html to `media/plg_editors_tinymce/js/plugins/highlighter/source.html

The result:

image

Did I miss something?

avatar dgrammatiko
dgrammatiko - comment - 22 Nov 2021
avatar chmst
chmst - comment - 23 Nov 2021

Works :)

image

avatar woluweb
woluweb - comment - 23 Nov 2021

Txs to all for this PR
๐Ÿงก๐Ÿ’™โค๏ธ๐Ÿ’š
@dgrammatiko had mentioned a clean solution above to have the popup (almost) full-screen (and not like 600x400 like it is by default now).
I really think we should go for that bc in practice it won't be very handy if the popup only covers like 1/4 of the screen, especially for Code editing.
This PR gives an extra incentive to have people using TinyMCE -which is excellent- so let's have this popup (almost) full-screen to get the full benefit of it :)

avatar Krshivam25 Krshivam25 - test_item - 23 Nov 2021 - Tested successfully
avatar Krshivam25
Krshivam25 - comment - 23 Nov 2021

I have tested this item โœ… successfully on e283301


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35647.

avatar chmst
chmst - comment - 23 Nov 2021

Can we test now or is it better waiting changes in the window?

avatar chmst chmst - test_item - 23 Nov 2021 - Tested successfully
avatar chmst
chmst - comment - 23 Nov 2021

I have tested this item โœ… successfully on e283301


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35647.

avatar richard67 richard67 - change - 23 Nov 2021
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 23 Nov 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35647.

avatar chmst
chmst - comment - 23 Nov 2021

THX


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35647.
avatar bembelimen bembelimen - change - 24 Nov 2021
Labels Added: ?
avatar bembelimen bembelimen - change - 24 Nov 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-11-24 13:58:09
Closed_By bembelimen
avatar bembelimen bembelimen - close - 24 Nov 2021
avatar bembelimen bembelimen - merge - 24 Nov 2021
avatar bembelimen
bembelimen - comment - 24 Nov 2021

Very cool feature, thank you!

avatar brianteeman
brianteeman - comment - 24 Nov 2021

thanks

avatar bsakhanov
bsakhanov - comment - 19 Jan 2022

For TinyMCE, such features would also be relevant (in the form of plugins, maybe)... For example, along with Quantum (as a media manager), I have to use JCE for projects (a shell for TinyMCE as a component of a visual editor for jumla) only because of a few things: 1) working with the source code, i.e. with the code is convenient โ€” there is a cool search with autocorrect; 2) auto-insertion is clearly worked out directly into the text of the video article, when just a short YouTube url is immediately transformed into a video insertion code with a frame, plus inserts from social networks (Twitter, Facebook, etc.) work similarly.; 3) in the visual editor mode, the text format is displayed there โ€” a paragraph or divas, for example, which is very convenient.

avatar brianteeman
brianteeman - comment - 19 Jan 2022

Not really sure I understand what you are asking for here but afaict everything is already present in joomla 4 and tinymce

Add a Comment

Login with GitHub to post a comment