@@ -4,13 +4,14 @@ import ConversationCard from '../ConversationCard'
4
4
import PropTypes from 'prop-types'
5
5
import { defaultConfig , getUserConfig } from '../../config.mjs'
6
6
import { config as toolsConfig } from '../../content-script/selection-tools'
7
- import { setElementPositionInViewport } from '../../utils'
7
+ import { isMobile , setElementPositionInViewport } from '../../utils'
8
8
import Draggable from 'react-draggable'
9
9
import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
10
10
11
11
const logo = Browser . runtime . getURL ( 'logo.png' )
12
12
13
13
function FloatingToolbar ( props ) {
14
+ const [ selection , setSelection ] = useState ( props . selection )
14
15
const [ prompt , setPrompt ] = useState ( props . prompt )
15
16
const [ triggered , setTriggered ] = useState ( props . triggered )
16
17
const [ config , setConfig ] = useState ( defaultConfig )
@@ -40,6 +41,19 @@ function FloatingToolbar(props) {
40
41
}
41
42
} , [ config ] )
42
43
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
+
43
57
if ( ! render ) return < div />
44
58
45
59
if ( triggered ) {
@@ -101,7 +115,7 @@ function FloatingToolbar(props) {
101
115
className : 'gpt-selection-toolbar-button' ,
102
116
title : toolConfig . label ,
103
117
onClick : async ( ) => {
104
- setPrompt ( await toolConfig . genPrompt ( props . selection ) )
118
+ setPrompt ( await toolConfig . genPrompt ( selection ) )
105
119
setTriggered ( true )
106
120
} ,
107
121
} ) ,
0 commit comments