4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { disposableWindowInterval } from 'vs/base/browser/dom' ;
7
- import { $window } from 'vs/base/browser/window' ;
8
7
import { IAction , toAction } from 'vs/base/common/actions' ;
9
8
import { coalesceInPlace , equals , tail } from 'vs/base/common/arrays' ;
10
9
import { AsyncIterableObject , AsyncIterableSource } from 'vs/base/common/async' ;
@@ -77,9 +76,9 @@ export abstract class EditModeStrategy {
77
76
78
77
abstract cancel ( ) : Promise < void > ;
79
78
80
- abstract makeProgressiveChanges ( edits : ISingleEditOperation [ ] , timings : ProgressingEditsOptions ) : Promise < void > ;
79
+ abstract makeProgressiveChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] , timings : ProgressingEditsOptions ) : Promise < void > ;
81
80
82
- abstract makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > ;
81
+ abstract makeChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] ) : Promise < void > ;
83
82
84
83
abstract undoChanges ( altVersionId : number ) : Promise < void > ;
85
84
@@ -151,7 +150,7 @@ export class PreviewStrategy extends EditModeStrategy {
151
150
// nothing to do
152
151
}
153
152
154
- override async makeChanges ( _edits : ISingleEditOperation [ ] ) : Promise < void > {
153
+ override async makeChanges ( _targetWindow : Window , _edits : ISingleEditOperation [ ] ) : Promise < void > {
155
154
// nothing to do
156
155
}
157
156
@@ -244,7 +243,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
244
243
const targetAltVersion = textModelNSnapshotAltVersion ?? textModelNAltVersion ;
245
244
await undoModelUntil ( modelN , targetAltVersion ) ;
246
245
}
247
- override async makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > {
246
+ override async makeChanges ( _targetWindow : Window , edits : ISingleEditOperation [ ] ) : Promise < void > {
248
247
const cursorStateComputerAndInlineDiffCollection : ICursorStateComputer = ( undoEdits ) => {
249
248
let last : Position | null = null ;
250
249
for ( const edit of undoEdits ) {
@@ -266,7 +265,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
266
265
await this . _updateDiffZones ( ) ;
267
266
}
268
267
269
- override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
268
+ override async makeProgressiveChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
270
269
271
270
// push undo stop before first edit
272
271
if ( ++ this . _editCount === 1 ) {
@@ -285,7 +284,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
285
284
const wordCount = countWords ( edit . text ?? '' ) ;
286
285
const speed = wordCount / durationInSec ;
287
286
// console.log({ durationInSec, wordCount, speed: wordCount / durationInSec });
288
- await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( edit , speed , opts . token ) ) ;
287
+ await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( targetWindow , edit , speed , opts . token ) ) ;
289
288
}
290
289
291
290
await renderTask ;
@@ -444,15 +443,15 @@ export function asAsyncEdit(edit: IIdentifiedSingleEditOperation): AsyncTextEdit
444
443
} satisfies AsyncTextEdit ;
445
444
}
446
445
447
- export function asProgressiveEdit ( edit : IIdentifiedSingleEditOperation , wordsPerSec : number , token : CancellationToken ) : AsyncTextEdit {
446
+ export function asProgressiveEdit ( targetWindow : Window , edit : IIdentifiedSingleEditOperation , wordsPerSec : number , token : CancellationToken ) : AsyncTextEdit {
448
447
449
448
wordsPerSec = Math . max ( 10 , wordsPerSec ) ;
450
449
451
450
const stream = new AsyncIterableSource < string > ( ) ;
452
451
let newText = edit . text ?? '' ;
453
452
// const wordCount = countWords(newText);
454
453
455
- const handle = disposableWindowInterval ( $window , ( ) => {
454
+ const handle = disposableWindowInterval ( targetWindow , ( ) => {
456
455
457
456
const r = getNWords ( newText , 1 ) ;
458
457
stream . emitOne ( r . value ) ;
@@ -584,15 +583,15 @@ export class LiveStrategy extends EditModeStrategy {
584
583
await undoModelUntil ( textModelN , altVersionId ) ;
585
584
}
586
585
587
- override async makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > {
588
- return this . _makeChanges ( edits , undefined ) ;
586
+ override async makeChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] ) : Promise < void > {
587
+ return this . _makeChanges ( targetWindow , edits , undefined ) ;
589
588
}
590
589
591
- override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
592
- return this . _makeChanges ( edits , opts ) ;
590
+ override async makeProgressiveChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
591
+ return this . _makeChanges ( targetWindow , edits , opts ) ;
593
592
}
594
593
595
- private async _makeChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions | undefined ) : Promise < void > {
594
+ private async _makeChanges ( targetWindow : Window , edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions | undefined ) : Promise < void > {
596
595
597
596
// push undo stop before first edit
598
597
if ( ++ this . _editCount === 1 ) {
@@ -625,7 +624,7 @@ export class LiveStrategy extends EditModeStrategy {
625
624
const wordCount = countWords ( edit . text ?? '' ) ;
626
625
const speed = wordCount / durationInSec ;
627
626
// console.log({ durationInSec, wordCount, speed: wordCount / durationInSec });
628
- await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( edit , speed , opts . token ) , progress ) ;
627
+ await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( targetWindow , edit , speed , opts . token ) , progress ) ;
629
628
}
630
629
631
630
} else {
0 commit comments