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

164
Vistas
How to only copy and paste highlighted text in an electron app?

I am having a lot of trouble implementing copy and paste in to my electron app. I have made a copy and paste window ui but have been looking for a way to implement the copy and paste feature (That only copies highlighted text). I have been at this for a LONG time and tried to use the clipboard API from electron themselves but that does not copy highlighted text only text that you have added youself. I also tryed to make a button that would just run thr CTRL + C command but i could not get it to work, So any help would be muchly appreciated!

Thanks in advance!

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

0

If you just want to get selected text from your own app window, you can use the web API Window.getSelection() normally like you would do in any web application that runs in the browser

See this answer

function getSelectionText() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    return text;
}

If you want a context menu (on right-click), you can use Electron Menu APIs to build this context menu with a copy menu item or you can use an npm package that does this for you electron-context-menu

If you want to get any highlighted text form any application, you can use synthesize a CTRL+C click then get the text from the clipboard. I have created an npm package electron-selected-text that does this for you and it preservers the old text in the clipboard as well

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