@@ -138,6 +138,45 @@ async function prepareForSelectionTools() {
138
138
} )
139
139
}
140
140
141
+ async function prepareForSelectionToolsTouch ( ) {
142
+ document . addEventListener ( 'touchend' , ( e ) => {
143
+ if ( toolbarContainer && toolbarContainer . contains ( e . target ) ) return
144
+ if (
145
+ toolbarContainer &&
146
+ window . getSelection ( ) ?. rangeCount > 0 &&
147
+ toolbarContainer . contains ( window . getSelection ( ) ?. getRangeAt ( 0 ) . endContainer . parentElement )
148
+ )
149
+ return
150
+
151
+ if ( toolbarContainer ) toolbarContainer . remove ( )
152
+ setTimeout ( ( ) => {
153
+ const selection = window . getSelection ( ) ?. toString ( )
154
+ if ( selection ) {
155
+ const position = {
156
+ x : e . changedTouches [ 0 ] . clientX + 15 ,
157
+ y : e . changedTouches [ 0 ] . clientY - 15 ,
158
+ }
159
+ toolbarContainer = createElementAtPosition ( position . x , position . y )
160
+ toolbarContainer . className = 'toolbar-container'
161
+ render (
162
+ < FloatingToolbar
163
+ session = { initSession ( ) }
164
+ selection = { selection }
165
+ position = { position }
166
+ container = { toolbarContainer }
167
+ /> ,
168
+ toolbarContainer ,
169
+ )
170
+ }
171
+ } )
172
+ } )
173
+ document . addEventListener ( 'touchstart' , ( e ) => {
174
+ if ( toolbarContainer && toolbarContainer . contains ( e . target ) ) return
175
+
176
+ document . querySelectorAll ( '.toolbar-container' ) . forEach ( ( e ) => e . remove ( ) )
177
+ } )
178
+ }
179
+
141
180
let menuX , menuY
142
181
143
182
async function prepareForRightClickMenu ( ) {
@@ -220,6 +259,7 @@ async function run() {
220
259
userConfig = await getUserConfig ( )
221
260
if ( isSafari ( ) ) await prepareForSafari ( )
222
261
prepareForSelectionTools ( )
262
+ prepareForSelectionToolsTouch ( )
223
263
prepareForStaticCard ( )
224
264
prepareForRightClickMenu ( )
225
265
}
0 commit comments