@@ -126,6 +126,19 @@ const deleteToolbar = () => {
126
126
toolbarContainer . remove ( )
127
127
}
128
128
129
+ const createSelectionTools = ( toolbarContainer , selection ) => {
130
+ toolbarContainer . className = 'chatgptbox-toolbar-container'
131
+ render (
132
+ < FloatingToolbar
133
+ session = { initSession ( ) }
134
+ selection = { selection }
135
+ container = { toolbarContainer }
136
+ dockable = { true }
137
+ /> ,
138
+ toolbarContainer ,
139
+ )
140
+ }
141
+
129
142
async function prepareForSelectionTools ( ) {
130
143
document . addEventListener ( 'mouseup' , ( e ) => {
131
144
if ( toolbarContainer && toolbarContainer . contains ( e . target ) ) return
@@ -154,16 +167,7 @@ async function prepareForSelectionTools() {
154
167
position = { x : e . pageX + 20 , y : e . pageY + 20 }
155
168
}
156
169
toolbarContainer = createElementAtPosition ( position . x , position . y )
157
- toolbarContainer . className = 'chatgptbox-toolbar-container'
158
- render (
159
- < FloatingToolbar
160
- session = { initSession ( ) }
161
- selection = { selection }
162
- container = { toolbarContainer }
163
- dockable = { true }
164
- /> ,
165
- toolbarContainer ,
166
- )
170
+ createSelectionTools ( toolbarContainer , selection )
167
171
}
168
172
} )
169
173
} )
@@ -207,16 +211,7 @@ async function prepareForSelectionToolsTouch() {
207
211
e . changedTouches [ 0 ] . pageX + 20 ,
208
212
e . changedTouches [ 0 ] . pageY + 20 ,
209
213
)
210
- toolbarContainer . className = 'chatgptbox-toolbar-container'
211
- render (
212
- < FloatingToolbar
213
- session = { initSession ( ) }
214
- selection = { selection }
215
- container = { toolbarContainer }
216
- dockable = { true }
217
- /> ,
218
- toolbarContainer ,
219
- )
214
+ createSelectionTools ( toolbarContainer , selection )
220
215
}
221
216
} )
222
217
} )
0 commit comments