Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

79
Vistas
Readding formatted draft.js text from clipboard

When I'm clicking on the button the text from the clipboard is pasted without style, but keeps the current style inline, but that's not what I need.

My code

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);
    }
  }

What needs to be done so that the text is inserted with formatting?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Text formatting loses after using clipboard.readText(). You should use clipboard.read() instead. It will return array of ClipBoardItem.

You can read your initial formatting from this object that way:

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();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda