@@ -387,13 +387,21 @@ class CodeitElement extends HTMLElement {
387387
388388 } ) ;
389389
390-
391- cd . on ( 'cut' , ( ) => { cd . dispatchEvent ( typeEvent ) } ) ;
392-
390+
393391 cd . on ( 'keydown mousedown mouseup touchstart touchend focus blur' ,
394392 ( ) => { onNextFrame ( checkCaretPosEvent ) } , false ) ;
395393
396394
395+ cd . on ( 'cut' , ( ) => {
396+
397+ const text = window . getSelection ( ) . toString ( ) ;
398+ e . clipboardData . setData ( 'text/plain' , text ) ;
399+ e . preventDefault ( ) ;
400+
401+ cd . dispatchEvent ( typeEvent ) ;
402+
403+ } ) ;
404+
397405 cd . on ( 'copy' , ( e ) => {
398406
399407 const text = window . getSelection ( ) . toString ( ) ;
@@ -404,29 +412,24 @@ class CodeitElement extends HTMLElement {
404412
405413 cd . on ( 'paste' , ( e ) => {
406414
407- let paste = ( e . clipboardData || window . clipboardData ) . getData ( 'text' ) ;
415+ let paste = e . clipboardData . getData ( 'text' ) ;
408416
409417 const selection = window . getSelection ( ) ;
410418 if ( ! selection . rangeCount ) return false ;
411- selection . deleteFromDocument ( ) ;
412-
413- cd . insert ( paste ) ;
414419
415- cd . dispatchEvent ( typeEvent ) ;
420+ if ( hashCode ( paste ) === hashCode ( cd . textContent ) ) {
421+
422+ selection . getRangeAt ( 0 ) . collapse ( ) ;
423+
424+ } else {
416425
417- /*// if selecting codeit element itself
418- if (selection.baseNode === cd) {
426+ selection . deleteFromDocument ( ) ;
419427
420- // insert newline
421- cd.insert('\r');
428+ cd . insert ( paste ) ;
422429
423- }*/
424-
425- /* if (hashCode(paste) === hashCode(cd.textContent)) {
426-
427- selection.getRangeAt(0).collapse();
430+ cd . dispatchEvent ( typeEvent ) ;
428431
429- }*/
432+ }
430433
431434 e . preventDefault ( ) ;
432435
0 commit comments