@@ -4,13 +4,14 @@ import ConversationCard from '../ConversationCard'
44import PropTypes from 'prop-types'
55import { defaultConfig , getUserConfig } from '../../config.mjs'
66import { config as toolsConfig } from '../../content-script/selection-tools'
7- import { setElementPositionInViewport } from '../../utils'
7+ import { isMobile , setElementPositionInViewport } from '../../utils'
88import Draggable from 'react-draggable'
99import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
1010
1111const logo = Browser . runtime . getURL ( 'logo.png' )
1212
1313function FloatingToolbar ( props ) {
14+ const [ selection , setSelection ] = useState ( props . selection )
1415 const [ prompt , setPrompt ] = useState ( props . prompt )
1516 const [ triggered , setTriggered ] = useState ( props . triggered )
1617 const [ config , setConfig ] = useState ( defaultConfig )
@@ -40,6 +41,19 @@ function FloatingToolbar(props) {
4041 }
4142 } , [ config ] )
4243
44+ useEffect ( ( ) => {
45+ if ( isMobile ( ) ) {
46+ const selectionListener = ( ) => {
47+ const currentSelection = window . getSelection ( ) ?. toString ( )
48+ if ( currentSelection ) setSelection ( currentSelection )
49+ }
50+ document . addEventListener ( 'selectionchange' , selectionListener )
51+ return ( ) => {
52+ document . removeEventListener ( 'selectionchange' , selectionListener )
53+ }
54+ }
55+ } , [ ] )
56+
4357 if ( ! render ) return < div />
4458
4559 if ( triggered ) {
@@ -101,7 +115,7 @@ function FloatingToolbar(props) {
101115 className : 'gpt-selection-toolbar-button' ,
102116 title : toolConfig . label ,
103117 onClick : async ( ) => {
104- setPrompt ( await toolConfig . genPrompt ( props . selection ) )
118+ setPrompt ( await toolConfig . genPrompt ( selection ) )
105119 setTriggered ( true )
106120 } ,
107121 } ) ,
0 commit comments