CMB2 icon indicating copy to clipboard operation
CMB2 copied to clipboard

Paste event not triggered for character counters

Open gyrus opened this issue 5 years ago • 2 comments

For the character counter feature that I added, the counters update OK when text is pasted with the keyboard (since the keyup event is triggered), but not when pasted with the mouse.

I've experimented and changing the events in charcounter.initWYSIWYG() from 'nodechange keyup' to 'nodechange keyup paste' seems to work (although in Chrome, 'Paste as plain text' doesn't seem to trigger).

For charcounter.initAll(), changing the events from 'keyup' to 'keyup paste' does likewise for text fields.

I experimented with the input event, but this doesn't seem to do anything.

I wondered:

  1. If you had any ideas about a better set of events to use / ideas about making this more comprehensive?
  2. Since this is a very small change, is it worth me going through the process of a pull request, or might you be able to slip it into the next release yourselves?

gyrus avatar Jul 06 '20 10:07 gyrus

I'd also like to decrease the debounce delay for the the editor updateCounter, from 1000 to 500. This would be a very small change to slip in. Or make it configurable - a more substantial change.

gyrus avatar Jul 07 '20 10:07 gyrus

Apologies, some slight confusion here due to me still having my own CMB2 version going locally (not the release which included the char counter stuff).

So, ignore the debounce delay bit - looks like it was reduced to 400 anyway.

I think the addition of the paste event would still be useful:

  • In counter.initWysiwyg(): editor.on( 'nodechange keyup paste', counter.countWysiwyg );
  • At the bottom: $( document ).on( 'input keyup paste', '.cmb2-count-chars', counter.countTextarea )

gyrus avatar Jul 08 '20 16:07 gyrus