Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to listen to the paste event?

I can't find any document or window object that I can use https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event.

I know there is a clipboard variable but is there an event?

like image 503
Nathan Horrigan Avatar asked Oct 15 '25 11:10

Nathan Horrigan


1 Answers

It seems like it would be possible to detect pastes with fairly high confidence by:

  1. Subscribing to workspace.onDidChangeTextDocument(workspace api) to get all text edits
  2. On edit, check env.clipboard.readText() to get the current content of the clipboard
  3. From the TextDocumentChangeEvent, check each contentChanges entry's text and see if it matches the clipboard text
  4. If it matches (and it isn't a trivial edit like a single character), they probably just pasted.
like image 116
Thomas Boby Avatar answered Oct 17 '25 17:10

Thomas Boby