@@ -4,7 +4,7 @@ import ConversationCard from '../ConversationCard'
4
4
import PropTypes from 'prop-types'
5
5
import { defaultConfig , getUserConfig } from '../../config/index.mjs'
6
6
import { config as toolsConfig } from '../../content-script/selection-tools'
7
- import { isMobile , setElementPositionInViewport } from '../../utils'
7
+ import { getClientPosition , isMobile , setElementPositionInViewport } from '../../utils'
8
8
import Draggable from 'react-draggable'
9
9
import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
10
10
@@ -16,15 +16,17 @@ function FloatingToolbar(props) {
16
16
const [ triggered , setTriggered ] = useState ( props . triggered )
17
17
const [ config , setConfig ] = useState ( defaultConfig )
18
18
const [ render , setRender ] = useState ( false )
19
- const [ position , setPosition ] = useState ( props . position )
20
19
const [ closeable , setCloseable ] = useState ( props . closeable )
20
+ const [ position , setPosition ] = useState ( getClientPosition ( props . container ) )
21
21
const [ virtualPosition , setVirtualPosition ] = useState ( { x : 0 , y : 0 } )
22
22
const windowSize = useClampWindowSize ( [ 750 , 1500 ] , [ 0 , Infinity ] )
23
23
24
24
useEffect ( ( ) => {
25
25
getUserConfig ( ) . then ( ( config ) => {
26
26
setConfig ( config )
27
27
setRender ( true )
28
+
29
+ if ( ! triggered ) props . container . style . position = 'absolute'
28
30
} )
29
31
} , [ ] )
30
32
@@ -127,6 +129,9 @@ function FloatingToolbar(props) {
127
129
className : 'chatgptbox-selection-toolbar-button' ,
128
130
title : toolConfig . label ,
129
131
onClick : async ( ) => {
132
+ const p = getClientPosition ( props . container )
133
+ props . container . style . position = 'fixed'
134
+ setPosition ( p )
130
135
setPrompt ( await toolConfig . genPrompt ( selection ) )
131
136
setTriggered ( true )
132
137
} ,
@@ -149,7 +154,6 @@ function FloatingToolbar(props) {
149
154
FloatingToolbar . propTypes = {
150
155
session : PropTypes . object . isRequired ,
151
156
selection : PropTypes . string . isRequired ,
152
- position : PropTypes . object . isRequired ,
153
157
container : PropTypes . object . isRequired ,
154
158
triggered : PropTypes . bool ,
155
159
closeable : PropTypes . bool ,
0 commit comments