@@ -178,35 +178,35 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode {
178
178
}
179
179
} , [ hasFocusWithin ] )
180
180
181
- const setFocusPathFromEditorSelection = useCallback ( ( ) => {
182
- const selection = nextSelectionRef . current
183
- const focusPath = selection ?. focus . path
184
- if ( ! focusPath ) return
185
-
186
- // Report focus on spans with `.text` appended to the reported focusPath.
187
- // This is done to support the Presentation tool which uses this kind of paths to refer to texts.
188
- // The PT-input already supports these paths the other way around.
189
- // It's a bit ugly right here, but it's a rather simple way to support the Presentation tool without
190
- // having to change the PTE's internals.
191
- const isSpanPath =
192
- focusPath . length === 3 && // A span path is always 3 segments long
193
- focusPath [ 1 ] === 'children' && // Is a child of a block
194
- isKeySegment ( focusPath [ 2 ] ) && // Contains the key of the child
195
- ! portableTextMemberItems . some (
196
- ( item ) => isKeySegment ( focusPath [ 2 ] ) && item . member . key === focusPath [ 2 ] . _key ,
197
- )
198
- const nextFocusPath = isSpanPath ? focusPath . concat ( [ 'text' ] ) : focusPath
181
+ const setFocusPathFromEditorSelection = useCallback (
182
+ ( nextSelection : EditorSelection ) => {
183
+ const focusPath = nextSelection ?. focus . path
184
+ if ( ! focusPath ) return
185
+
186
+ // Report focus on spans with `.text` appended to the reported focusPath.
187
+ // This is done to support the Presentation tool which uses this kind of paths to refer to texts.
188
+ // The PT-input already supports these paths the other way around.
189
+ // It's a bit ugly right here, but it's a rather simple way to support the Presentation tool without
190
+ // having to change the PTE's internals.
191
+ const isSpanPath =
192
+ focusPath . length === 3 && // A span path is always 3 segments long
193
+ focusPath [ 1 ] === 'children' && // Is a child of a block
194
+ isKeySegment ( focusPath [ 2 ] ) && // Contains the key of the child
195
+ ! portableTextMemberItems . some (
196
+ ( item ) => isKeySegment ( focusPath [ 2 ] ) && item . member . key === focusPath [ 2 ] . _key ,
197
+ )
198
+ const nextFocusPath = isSpanPath ? focusPath . concat ( [ 'text' ] ) : focusPath
199
199
200
- // Must called in a transition useTrackFocusPath hook
201
- // will try to effectuate a focusPath that is different from what currently is the editor focusPath
202
- startTransition ( ( ) => {
203
- onPathFocus ( nextFocusPath , {
204
- selection,
200
+ // Must called in a transition useTrackFocusPath hook
201
+ // will try to effectuate a focusPath that is different from what currently is the editor focusPath
202
+ startTransition ( ( ) => {
203
+ onPathFocus ( nextFocusPath , {
204
+ selection : nextSelection ,
205
+ } )
205
206
} )
206
- } )
207
- } , [ onPathFocus , portableTextMemberItems ] )
208
-
209
- const nextSelectionRef = useRef < EditorSelection | null > ( null )
207
+ } ,
208
+ [ onPathFocus , portableTextMemberItems ] ,
209
+ )
210
210
211
211
// Handle editor changes
212
212
const handleEditorChange = useCallback (
@@ -223,8 +223,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode {
223
223
}
224
224
break
225
225
case 'selection' :
226
- nextSelectionRef . current = change . selection
227
- setFocusPathFromEditorSelection ( )
226
+ setFocusPathFromEditorSelection ( change . selection )
228
227
break
229
228
case 'focus' :
230
229
setIsActive ( true )
0 commit comments