@@ -434,6 +434,12 @@ var codeInput = {
434434 */
435435 codeElement = null ;
436436
437+ /**
438+ * Exposed non-scrolling element designed to contain dialog boxes etc. that shouldn't scroll
439+ * with the code-input element.
440+ */
441+ dialogContainerElement = null ;
442+
437443 /**
438444 * Form-Associated Custom Element Callbacks
439445 * https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example
@@ -504,6 +510,7 @@ var codeInput = {
504510 this . update ( ) ;
505511 this . needsHighlight = false ;
506512 }
513+
507514 window . requestAnimationFrame ( this . animateFrame . bind ( this ) ) ;
508515 }
509516
@@ -634,6 +641,12 @@ var codeInput = {
634641 }
635642 }
636643
644+ // dialogContainerElement used to store non-scrolling dialog boxes, etc.
645+ let dialogContainerElement = document . createElement ( "div" ) ;
646+ dialogContainerElement . classList . add ( "code-input_dialog-container" ) ;
647+ this . append ( dialogContainerElement ) ;
648+ this . dialogContainerElement = dialogContainerElement ;
649+
637650 this . pluginEvt ( "afterElementsAdded" ) ;
638651
639652 this . dispatchEvent ( new CustomEvent ( "code-input_load" ) ) ;
@@ -793,10 +806,12 @@ var codeInput = {
793806 * @override
794807 */
795808 addEventListener ( type , listener , options = undefined ) {
809+ // Save a copy of the callback where `this` refers to the code-input element
796810 let boundCallback = listener . bind ( this ) ;
797811 this . boundEventCallbacks [ listener ] = boundCallback ;
798812
799813 if ( codeInput . textareaSyncEvents . includes ( type ) ) {
814+ // Synchronise with textarea
800815 if ( options === undefined ) {
801816 if ( this . textareaElement == null ) {
802817 this . addEventListener ( "code-input_load" , ( ) => { this . textareaElement . addEventListener ( type , boundCallback ) ; } ) ;
@@ -811,6 +826,7 @@ var codeInput = {
811826 }
812827 }
813828 } else {
829+ // Synchronise with code-input element
814830 if ( options === undefined ) {
815831 super . addEventListener ( type , boundCallback ) ;
816832 } else {
@@ -822,22 +838,32 @@ var codeInput = {
822838 /**
823839 * @override
824840 */
825- removeEventListener ( type , listener , options = null ) {
841+ removeEventListener ( type , listener , options = undefined ) {
842+ // Save a copy of the callback where `this` refers to the code-input element
826843 let boundCallback = this . boundEventCallbacks [ listener ] ;
827- if ( type == "change" ) {
828- if ( options === null ) {
829- this . textareaElement . removeEventListener ( "change" , boundCallback ) ;
844+
845+ if ( codeInput . textareaSyncEvents . includes ( type ) ) {
846+ // Synchronise with textarea
847+ if ( options === undefined ) {
848+ if ( this . textareaElement == null ) {
849+ this . addEventListener ( "code-input_load" , ( ) => { this . textareaElement . removeEventListener ( type , boundCallback ) ; } ) ;
850+ } else {
851+ this . textareaElement . removeEventListener ( type , boundCallback ) ;
852+ }
830853 } else {
831- this . textareaElement . removeEventListener ( "change" , boundCallback , options ) ;
854+ if ( this . textareaElement == null ) {
855+ this . addEventListener ( "code-input_load" , ( ) => { this . textareaElement . removeEventListener ( type , boundCallback , options ) ; } ) ;
856+ } else {
857+ this . textareaElement . removeEventListener ( type , boundCallback , options ) ;
858+ }
832859 }
833- } else if ( type == "selectionchange" ) {
834- if ( options === null ) {
835- this . textareaElement . removeEventListener ( "selectionchange" , boundCallback ) ;
860+ } else {
861+ // Synchronise with code-input element
862+ if ( options === undefined ) {
863+ super . removeEventListener ( type , boundCallback ) ;
836864 } else {
837- this . textareaElement . removeEventListener ( "selectionchange" , boundCallback , options ) ;
865+ super . removeEventListener ( type , boundCallback , options ) ;
838866 }
839- } else {
840- super . removeEventListener ( type , listener , options ) ;
841867 }
842868 }
843869
0 commit comments