@@ -240,18 +240,20 @@ export class ActiveResult extends ActiveSource {
240
240
hasResult ( ) : this is ActiveResult { return true }
241
241
242
242
handleUserEvent ( tr : Transaction , type : "input" | "delete" , conf : Required < CompletionConfig > ) : ActiveSource {
243
+ let result = this . result as CompletionResult | null
244
+ if ( result ! . map && ! tr . changes . empty ) result = result ! . map ( result ! , tr . changes )
243
245
let from = tr . changes . mapPos ( this . from ) , to = tr . changes . mapPos ( this . to , 1 )
244
246
let pos = cur ( tr . state )
245
247
if ( ( this . explicitPos < 0 ? pos <= from : pos < this . from ) ||
246
- pos > to ||
248
+ pos > to || ! result ||
247
249
type == "delete" && cur ( tr . startState ) == this . from )
248
250
return new ActiveSource ( this . source , type == "input" && conf . activateOnTyping ? State . Pending : State . Inactive )
249
- let explicitPos = this . explicitPos < 0 ? - 1 : tr . changes . mapPos ( this . explicitPos ) , updated
250
- if ( checkValid ( this . result . validFor , tr . state , from , to ) )
251
- return new ActiveResult ( this . source , explicitPos , this . result , from , to )
252
- if ( this . result . update &&
253
- ( updated = this . result . update ( this . result , from , to , new CompletionContext ( tr . state , pos , explicitPos >= 0 ) ) ) )
254
- return new ActiveResult ( this . source , explicitPos , updated , updated . from , updated . to ?? cur ( tr . state ) )
251
+ let explicitPos = this . explicitPos < 0 ? - 1 : tr . changes . mapPos ( this . explicitPos )
252
+ if ( checkValid ( result . validFor , tr . state , from , to ) )
253
+ return new ActiveResult ( this . source , explicitPos , result , from , to )
254
+ if ( result . update &&
255
+ ( result = result . update ( result , from , to , new CompletionContext ( tr . state , pos , explicitPos >= 0 ) ) ) )
256
+ return new ActiveResult ( this . source , explicitPos , result , result . from , result . to ?? cur ( tr . state ) )
255
257
return new ActiveSource ( this . source , State . Pending , explicitPos )
256
258
}
257
259
@@ -260,9 +262,11 @@ export class ActiveResult extends ActiveSource {
260
262
}
261
263
262
264
map ( mapping : ChangeDesc ) {
263
- return mapping . empty ? this :
264
- new ActiveResult ( this . source , this . explicitPos < 0 ? - 1 : mapping . mapPos ( this . explicitPos ) , this . result ,
265
- mapping . mapPos ( this . from ) , mapping . mapPos ( this . to , 1 ) )
265
+ if ( mapping . empty ) return this
266
+ let result = this . result . map ? this . result . map ( this . result , mapping ) : this . result
267
+ if ( ! result ) return new ActiveSource ( this . source , State . Inactive )
268
+ return new ActiveResult ( this . source , this . explicitPos < 0 ? - 1 : mapping . mapPos ( this . explicitPos ) , this . result ,
269
+ mapping . mapPos ( this . from ) , mapping . mapPos ( this . to , 1 ) )
266
270
}
267
271
}
268
272
0 commit comments