Hi,
I am trying to implement the custom tools for color and font size using dropdown list in the editor.
I have an issue when I select some text in the editor, and choose a color or a font size in the custom dropdown, the selected text becomes unselected, so I have to select them again if I want to change the option.
I don't see this issue when I use the default built-in tool like FontSize.
Here is my code:
import {
Editor,
EditorChangeEvent,
EditorMountEvent,
EditorPasteEvent,
EditorTools,
EditorToolsSettings,
ProseMirror,
} from'@progress/kendo-react-editor';
import { useEffect, useRef, useState } from'react';
import { Button } from'@progress/kendo-react-buttons';
const { EditorState, EditorView, Plugin, PluginKey, TextSelection } = ProseMirror;
const { Bold, Italic, Underline, Strikethrough, Indent, Outdent, OrderedList, UnorderedList, FormatBlock } =
EditorTools;
const fontSizeToolSettings: EditorToolsSettings.StyleDropDownListSettings = {
...EditorToolsSettings.fontSize,
items: [
{ text: '10', value: '10pt' },
{ text: '12', value: '12pt' },
{ text: '14', value: '14pt' },
{ text: '18', value: '18pt' },
{ text: '22', value: '22pt' },
{ text: '36', value: '36pt' },
],
};
const colorToolSettings = {
style: 'color',
defaultItem: { text: 'No Color', value: '' },
items: [
{ text: 'White', value: '#fff' },
{ text: 'Midnight', value: '#232437' },
{ text: 'Sand', value: '#e6e4dc' },
{ text: 'Slate', value: '#6a7885' },
{ text: 'Mint', value: '#6ce3c8' },
{ text: 'Green', value: '#20a786' },
{ text: 'Yellow', value: '#f1c22e' },
{ text: 'Orange', value: '#e79946' },
{ text: 'Red', value: '#c64f27' },
],
};
const CustomColor = EditorTools.createStyleDropDownList(colorToolSettings);
const MyColorTool = (props: any) => (
<CustomColor
{...props}
style={{
width: '100px',
...props.style,
}}
/>
);
// Creates custom FontSize tool.const CustomFontSize = EditorTools.createStyleDropDownList(fontSizeToolSettings);
// Styles the FontSize tool (DropDownList).const MyFontSizeTool = (props: any) => (
<CustomFontSize
{...props}
style={{
width: '110px',
...props.style,
}}
/>
);
const CommonEditor = () => {
return (
<Editor
tools={[
MyColorTool,
[Bold, Italic, Underline, Strikethrough],
[Indent, Outdent],
[OrderedList, UnorderedList],
MyFontSizeTool,
]}
defaultEditMode="div"
/>
);
};
exportdefault CommonEditor;
Could you provide me the solution to keep the selected text like the default tool?
Thanks a lot!