Cuando hago clic en el botón, el texto del portapapeles se pega sin estilo, pero mantiene el estilo actual en línea, pero eso no es lo que necesito.
Mi código
async function getClipboardContents() { try { const textFromClipboard = await navigator.clipboard.readText(); const newContentState = Modifier.replaceText( editorState.getCurrentContent(), editorState.getSelection(), textFromClipboard, editorState.getCurrentInlineStyle(), ); const newPushState = Draft.EditorState.push(editorState, newContentState, 'change-block-data'); handleOnChange(newPushState); } catch (err) { console.error('error', err); } }¿Qué hay que hacer para que el texto se inserte con formato?
El formato de texto se pierde después de usar clipboard.readText() . Debería usar clipboard.read() en su lugar. Devolverá una matriz de ClipBoardItem .
Puede leer su formato inicial de este objeto de esa manera:
const [clipboardItem] = await navigator.clipboard.read(); const blob = await clipboardItem.getType('text/html'); // Here's your formmated text const formattedText = await new Response(blob).text();