diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx index 8aef059f0c..7aefd0c199 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx @@ -480,6 +480,23 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { border-top: none !important; } + /* Override the TinyMCE font styles with more specific CSS selectors. + Without this, the built-in FontAwesome styles are not applied because + they are overridden by TinyMCE. */ + .plugin-icon.fa, .plugin-icon.far, .plugin-icon.fas { + font-family: "Font Awesome 5 Free"; + font-size: ${theme.toolbarHeight - theme.toolbarPadding}px; + } + + .plugin-icon.fa, .plugin-icon.fas { + font-weight: 900; + } + + .plugin-icon.fab, .plugin-icon.far { + font-weight: 400; + } + + .joplin-tinymce .tox-toolbar__group { background-color: ${theme.backgroundColor3}; padding-top: ${theme.toolbarPadding}px; @@ -631,9 +648,16 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { }); for (const pluginCommandName of pluginCommandNames) { + const iconClassName = CommandService.instance().iconName(pluginCommandName); + + // Only allow characters that appear in Font Awesome class names: letters, spaces, and dashes. + const safeIconClassName = iconClassName.replace(/[^a-z0-9 -]/g, ''); + + editor.ui.registry.addIcon(pluginCommandName, ``); + editor.ui.registry.addButton(pluginCommandName, { tooltip: CommandService.instance().label(pluginCommandName), - icon: CommandService.instance().iconName(pluginCommandName, 'tinymce'), + icon: pluginCommandName, onAction: function() { void CommandService.instance().execute(pluginCommandName); }, diff --git a/packages/lib/services/CommandService.ts b/packages/lib/services/CommandService.ts index 979c515353..87636764ab 100644 --- a/packages/lib/services/CommandService.ts +++ b/packages/lib/services/CommandService.ts @@ -43,11 +43,6 @@ export interface CommandDeclaration { // All free Font Awesome icons are available: https://fontawesome.com/icons?d=gallery&m=free iconName?: string; - // Will be used by TinyMCE (which doesn't support Font Awesome icons). - // Defaults to the "preferences" icon (a cog) if not specified. - // https://www.tiny.cloud/docs/advanced/editor-icon-identifiers/ - tinymceIconName?: string; - // Same as `role` key in Electron MenuItem: // https://www.electronjs.org/docs/api/menu-item#new-menuitemoptions // Note that due to a bug in Electron, menu items with a role cannot @@ -296,10 +291,10 @@ export default class CommandService extends BaseService { } } - public iconName(commandName: string, variant: string = null): string { + public iconName(commandName: string): string { const command = this.commandByName(commandName); if (!command) throw new Error(`No such command: ${commandName}`); - if (variant === 'tinymce') return command.declaration.tinymceIconName ? command.declaration.tinymceIconName : 'preferences'; + return command.declaration.iconName; }