Skip to content

Commit

Permalink
Prevents from opening the code editor before the content is set in Ti…
Browse files Browse the repository at this point in the history
…ny editor
  • Loading branch information
jmuletpol committed Dec 1, 2024
1 parent 392ddff commit 280df4c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
A plugin for the Moodle TinyMCE editor which replaces the basic source code editor shipped by TinyMCE6.
This plugin leverages [codeMirror](https://codemirror.net/) version 6 to provide syntax highlight, autocompletion, block fold, etc.

### Features

1. Color syntax and line numbers
2. Search and replace
3. Code formatting
4. Cursor position synchronized with Tiny editor (since v1.1.4)
5. Light and dark themes
6. Toggle fullscreen mode

This plugin does not include any configuration settings. The installation is straightforward: simply go to Site Administration area (Plugins → Install plugins → Install plugin from ZIP file).

Once the plugin is installed, the items named "Source Code" in the menu, will be replaced by "Source Code Pro". Also a button will be added in the first position of the toolbar.
Expand Down
2 changes: 1 addition & 1 deletion amd/build/commands.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/commands.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions amd/src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,20 @@ export const getSetup = async() => {
// Register the Icon.
editor.ui.registry.addIcon(icon, buttonImage.html);

// Disable button and menu item until the content has been set.
const onSetup = (api) => {
const cb = () => api.setEnabled(true);
editor.on('SetContent', cb);
return () => editor.off('SetContent', cb);
};

// Register the Toolbar Button.
editor.ui.registry.addButton(component, {
icon,
tooltip: pluginName,
onAction: () => handleAction(editor),
enabled: false,
onSetup
});

// Add the Menu Item.
Expand All @@ -56,6 +65,8 @@ export const getSetup = async() => {
icon,
text: pluginName,
onAction: () => handleAction(editor),
enabled: false,
onSetup
});
};
};

0 comments on commit 280df4c

Please sign in to comment.