@@ -116,50 +116,54 @@ function addIdleListeners(editors) {
116
116
function addInputsPointerDownListener ( inputId ) {
117
117
const input = document . getElementById ( inputId ) ;
118
118
input . addEventListener ( 'pointerdown' , ( event ) => {
119
- pointerDownOnInput = true ;
120
- pointerDownOnInputPoint = extractPoint ( event , input , editorElementRef . editor . configuration ) ;
121
- if ( selectedInput !== input ) {
122
- if ( editorElementRef ) {
123
- if ( selectedInput ) {
124
- oldInput = selectedInput ;
125
- editorElementRef . editor . convert ( ) ;
126
- editorElementRef . editor . waitForIdle ( ) ;
127
- waitingForIdle = true ;
119
+ if ( editorElementRef . editor . initialized ) {
120
+ pointerDownOnInput = true ;
121
+ pointerDownOnInputPoint = extractPoint ( event , input , editorElementRef . editor . configuration ) ;
122
+ if ( selectedInput !== input ) {
123
+ if ( editorElementRef ) {
124
+ if ( selectedInput ) {
125
+ oldInput = selectedInput ;
126
+ editorElementRef . editor . convert ( ) ;
127
+ editorElementRef . editor . waitForIdle ( ) ;
128
+ waitingForIdle = true ;
129
+ }
128
130
}
131
+ clearForIdle = false ;
132
+ selectedEditor === 0 ? editorElementRef = editorElement : editorElementRef = editorElement2 ;
133
+ selectedInput = input ;
134
+ editorElementRef . style . width = `${ event . target . clientWidth } px` ;
135
+ editorElementRef . style . height = `${ event . target . clientHeight } px` ;
136
+ editorElementRef . style . display = 'block' ;
137
+ editorElementRef . style . position = 'absolute' ;
138
+ editorElementRef . style . left = `${ event . target . tagName === 'svg' ? event . target . parentElement . offsetLeft + 1 : event . target . offsetLeft + 1 } px` ;
139
+ editorElementRef . style . top = `${ event . target . tagName === 'svg' ? event . target . parentElement . offsetTop + 1 : event . target . offsetTop + 1 } px` ;
140
+ editorElementRef . style . background = 'white' ;
141
+ const inputValue = inputValues . get ( selectedInput . id ) ;
142
+ if ( inputValue ) {
143
+ editorElementRef . editor . import_ ( inputValue , 'text/plain' ) ;
144
+ }
145
+ editorElementRef . editor . resize ( ) ;
146
+ selectedEditor === 0 ? selectedEditor = 1 : selectedEditor = 0 ;
129
147
}
130
- clearForIdle = false ;
131
- selectedEditor === 0 ? editorElementRef = editorElement : editorElementRef = editorElement2 ;
132
- selectedInput = input ;
133
- editorElementRef . style . width = `${ event . target . clientWidth } px` ;
134
- editorElementRef . style . height = `${ event . target . clientHeight } px` ;
135
- editorElementRef . style . display = 'block' ;
136
- editorElementRef . style . position = 'absolute' ;
137
- editorElementRef . style . left = `${ event . target . tagName === 'svg' ? event . target . parentElement . offsetLeft + 1 : event . target . offsetLeft + 1 } px` ;
138
- editorElementRef . style . top = `${ event . target . tagName === 'svg' ? event . target . parentElement . offsetTop + 1 : event . target . offsetTop + 1 } px` ;
139
- editorElementRef . style . background = 'white' ;
140
- const inputValue = inputValues . get ( selectedInput . id ) ;
141
- if ( inputValue ) {
142
- editorElementRef . editor . import_ ( inputValue , 'text/plain' ) ;
143
- }
144
- editorElementRef . editor . resize ( ) ;
145
- selectedEditor === 0 ? selectedEditor = 1 : selectedEditor = 0 ;
146
148
}
147
149
} ) ;
148
150
input . addEventListener ( 'pointermove' , ( event ) => { // Trigger a pointerMove
149
- if ( this . activePointerId && this . activePointerId === event . pointerId ) {
150
- editorElementRef . editor . pointerMove ( extractPoint ( event , editorElementRef . editor . domElement , editorElementRef . editor . configuration ) ) ;
151
- } else if ( pointerDownOnInput ) {
152
- const point = extractPoint ( event , editorElementRef . editor . domElement , editorElementRef . editor . configuration ) ;
153
- const diffX = Math . abs ( pointerDownOnInputPoint . x - point . x ) ;
154
- const diffY = Math . abs ( pointerDownOnInputPoint . y - point . y ) ;
155
- // mMaxDiffX = Math.max(diffX, mMaxDiffX);
156
- const cond1 = diffX < 1 && diffY > 1 ; // && mMaxDiffX < 15;
157
- const cond2 = diffX > 1 && diffY > 1 ; // && mMaxDiffX < 15;
158
- if ( cond1 || cond2 ) {
159
- this . activePointerId = event . pointerId ;
160
- // Hack for iOS 9 Safari : pointerId has to be int so -1 if > max value
161
- const pointerId = event . pointerId > 2147483647 ? - 1 : event . pointerId ;
162
- editorElementRef . editor . pointerDown ( pointerDownOnInputPoint , event . pointerType , pointerId ) ;
151
+ if ( editorElementRef . editor . initialized ) {
152
+ if ( this . activePointerId && this . activePointerId === event . pointerId ) {
153
+ editorElementRef . editor . pointerMove ( extractPoint ( event , editorElementRef . editor . domElement , editorElementRef . editor . configuration ) ) ;
154
+ } else if ( pointerDownOnInput ) {
155
+ const point = extractPoint ( event , editorElementRef . editor . domElement , editorElementRef . editor . configuration ) ;
156
+ const diffX = Math . abs ( pointerDownOnInputPoint . x - point . x ) ;
157
+ const diffY = Math . abs ( pointerDownOnInputPoint . y - point . y ) ;
158
+ // mMaxDiffX = Math.max(diffX, mMaxDiffX);
159
+ const cond1 = diffX < 1 && diffY > 1 ; // && mMaxDiffX < 15;
160
+ const cond2 = diffX > 1 && diffY > 1 ; // && mMaxDiffX < 15;
161
+ if ( cond1 || cond2 ) {
162
+ this . activePointerId = event . pointerId ;
163
+ // Hack for iOS 9 Safari : pointerId has to be int so -1 if > max value
164
+ const pointerId = event . pointerId > 2147483647 ? - 1 : event . pointerId ;
165
+ editorElementRef . editor . pointerDown ( pointerDownOnInputPoint , event . pointerType , pointerId ) ;
166
+ }
163
167
}
164
168
}
165
169
} ) ;
0 commit comments