@@ -4,7 +4,7 @@ import ConversationCard from '../ConversationCard'
44import PropTypes from 'prop-types'
55import { defaultConfig , getUserConfig } from '../../config/index.mjs'
66import { config as toolsConfig } from '../../content-script/selection-tools'
7- import { isMobile , setElementPositionInViewport } from '../../utils'
7+ import { getClientPosition , isMobile , setElementPositionInViewport } from '../../utils'
88import Draggable from 'react-draggable'
99import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
1010
@@ -16,15 +16,17 @@ function FloatingToolbar(props) {
1616 const [ triggered , setTriggered ] = useState ( props . triggered )
1717 const [ config , setConfig ] = useState ( defaultConfig )
1818 const [ render , setRender ] = useState ( false )
19- const [ position , setPosition ] = useState ( props . position )
2019 const [ closeable , setCloseable ] = useState ( props . closeable )
20+ const [ position , setPosition ] = useState ( getClientPosition ( props . container ) )
2121 const [ virtualPosition , setVirtualPosition ] = useState ( { x : 0 , y : 0 } )
2222 const windowSize = useClampWindowSize ( [ 750 , 1500 ] , [ 0 , Infinity ] )
2323
2424 useEffect ( ( ) => {
2525 getUserConfig ( ) . then ( ( config ) => {
2626 setConfig ( config )
2727 setRender ( true )
28+
29+ if ( ! triggered ) props . container . style . position = 'absolute'
2830 } )
2931 } , [ ] )
3032
@@ -127,6 +129,9 @@ function FloatingToolbar(props) {
127129 className : 'chatgptbox-selection-toolbar-button' ,
128130 title : toolConfig . label ,
129131 onClick : async ( ) => {
132+ const p = getClientPosition ( props . container )
133+ props . container . style . position = 'fixed'
134+ setPosition ( p )
130135 setPrompt ( await toolConfig . genPrompt ( selection ) )
131136 setTriggered ( true )
132137 } ,
@@ -149,7 +154,6 @@ function FloatingToolbar(props) {
149154FloatingToolbar . propTypes = {
150155 session : PropTypes . object . isRequired ,
151156 selection : PropTypes . string . isRequired ,
152- position : PropTypes . object . isRequired ,
153157 container : PropTypes . object . isRequired ,
154158 triggered : PropTypes . bool ,
155159 closeable : PropTypes . bool ,
0 commit comments