Skip to content

Commit 9413602

Browse files
committed
Fixes #101483: check state after await and make tests async
1 parent 8cd23cf commit 9413602

File tree

3 files changed

+125
-98
lines changed

3 files changed

+125
-98
lines changed

src/vs/editor/contrib/find/findController.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ export class CommonFindController extends Disposable implements IEditorContribut
280280

281281
if (!stateChanges.searchString && opts.seedSearchStringFromGlobalClipboard) {
282282
let selectionSearchString = await this.getGlobalBufferTerm();
283+
284+
if (!this._editor.hasModel()) {
285+
// the editor has lost its model in the meantime
286+
return;
287+
}
288+
283289
if (selectionSearchString) {
284290
stateChanges.searchString = selectionSearchString;
285291
}
@@ -364,13 +370,14 @@ export class CommonFindController extends Disposable implements IEditorContribut
364370
return '';
365371
}
366372

367-
public async setGlobalBufferTerm(text: string) {
373+
public setGlobalBufferTerm(text: string): void {
368374
if (this._editor.getOption(EditorOption.find).globalFindClipboard
369375
&& this._clipboardService
370376
&& this._editor.hasModel()
371377
&& !this._editor.getModel().isTooLargeForSyncing()
372378
) {
373-
await this._clipboardService.writeFindText(text);
379+
// intentionally not awaited
380+
this._clipboardService.writeFindText(text);
374381
}
375382
}
376383
}
@@ -424,10 +431,12 @@ export class FindController extends CommonFindController implements IFindControl
424431

425432
await super._start(opts);
426433

427-
if (opts.shouldFocus === FindStartFocusAction.FocusReplaceInput) {
428-
this._widget!.focusReplaceInput();
429-
} else if (opts.shouldFocus === FindStartFocusAction.FocusFindInput) {
430-
this._widget!.focusFindInput();
434+
if (this._widget) {
435+
if (opts.shouldFocus === FindStartFocusAction.FocusReplaceInput) {
436+
this._widget.focusReplaceInput();
437+
} else if (opts.shouldFocus === FindStartFocusAction.FocusFindInput) {
438+
this._widget.focusFindInput();
439+
}
431440
}
432441
}
433442

@@ -470,10 +479,10 @@ export class StartFindAction extends EditorAction {
470479
});
471480
}
472481

473-
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
482+
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
474483
let controller = CommonFindController.get(editor);
475484
if (controller) {
476-
controller.start({
485+
await controller.start({
477486
forceRevealReplace: false,
478487
seedSearchStringFromSelection: editor.getOption(EditorOption.find).seedSearchStringFromSelection,
479488
seedSearchStringFromGlobalClipboard: editor.getOption(EditorOption.find).globalFindClipboard,
@@ -508,7 +517,7 @@ export class StartFindWithSelectionAction extends EditorAction {
508517
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
509518
let controller = CommonFindController.get(editor);
510519
if (controller) {
511-
controller.start({
520+
await controller.start({
512521
forceRevealReplace: false,
513522
seedSearchStringFromSelection: true,
514523
seedSearchStringFromGlobalClipboard: false,
@@ -518,15 +527,15 @@ export class StartFindWithSelectionAction extends EditorAction {
518527
loop: editor.getOption(EditorOption.find).loop
519528
});
520529

521-
return controller.setGlobalBufferTerm(controller.getState().searchString);
530+
controller.setGlobalBufferTerm(controller.getState().searchString);
522531
}
523532
}
524533
}
525534
export abstract class MatchFindAction extends EditorAction {
526-
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
535+
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
527536
let controller = CommonFindController.get(editor);
528537
if (controller && !this._run(controller)) {
529-
controller.start({
538+
await controller.start({
530539
forceRevealReplace: false,
531540
seedSearchStringFromSelection: (controller.getState().searchString.length === 0) && editor.getOption(EditorOption.find).seedSearchStringFromSelection,
532541
seedSearchStringFromGlobalClipboard: true,
@@ -629,7 +638,7 @@ export class PreviousMatchFindAction2 extends MatchFindAction {
629638
}
630639

631640
export abstract class SelectionMatchFindAction extends EditorAction {
632-
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
641+
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
633642
let controller = CommonFindController.get(editor);
634643
if (!controller) {
635644
return;
@@ -639,7 +648,7 @@ export abstract class SelectionMatchFindAction extends EditorAction {
639648
controller.setSearchString(selectionSearchString);
640649
}
641650
if (!this._run(controller)) {
642-
controller.start({
651+
await controller.start({
643652
forceRevealReplace: false,
644653
seedSearchStringFromSelection: editor.getOption(EditorOption.find).seedSearchStringFromSelection,
645654
seedSearchStringFromGlobalClipboard: false,
@@ -720,7 +729,7 @@ export class StartFindReplaceAction extends EditorAction {
720729
});
721730
}
722731

723-
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
732+
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
724733
if (!editor.hasModel() || editor.getOption(EditorOption.readOnly)) {
725734
return;
726735
}
@@ -745,7 +754,7 @@ export class StartFindReplaceAction extends EditorAction {
745754

746755

747756
if (controller) {
748-
controller.start({
757+
await controller.start({
749758
forceRevealReplace: true,
750759
seedSearchStringFromSelection: seedSearchStringFromSelection,
751760
seedSearchStringFromGlobalClipboard: editor.getOption(EditorOption.find).seedSearchStringFromSelection,

0 commit comments

Comments
 (0)