diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 53ed62d0393c1..9cc58bf93eb23 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -240,6 +240,7 @@ "./vs/editor/contrib/find/replacePattern.ts", "./vs/editor/contrib/find/simpleFindWidget.ts", "./vs/editor/contrib/find/test/find.test.ts", + "./vs/editor/contrib/find/test/findController.test.ts", "./vs/editor/contrib/find/test/replacePattern.test.ts", "./vs/editor/contrib/folding/folding.ts", "./vs/editor/contrib/folding/foldingDecorations.ts", diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index dacefd20057b6..06d8c1bf07aa0 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -437,7 +437,7 @@ export class StartFindAction extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { let controller = CommonFindController.get(editor); if (controller) { controller.start({ @@ -488,7 +488,7 @@ export class StartFindWithSelectionAction extends EditorAction { } } export abstract class MatchFindAction extends EditorAction { - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { let controller = CommonFindController.get(editor); if (controller && !this._run(controller)) { controller.start({ @@ -551,7 +551,7 @@ export class PreviousMatchFindAction extends MatchFindAction { } export abstract class SelectionMatchFindAction extends EditorAction { - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { let controller = CommonFindController.get(editor); if (!controller) { return; @@ -641,7 +641,7 @@ export class StartFindReplaceAction extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { if (!editor.hasModel() || editor.getConfiguration().readOnly) { return; } diff --git a/src/vs/editor/contrib/find/test/findController.test.ts b/src/vs/editor/contrib/find/test/findController.test.ts index 81f2e6bf157ef..0d6c7efe4cee5 100644 --- a/src/vs/editor/contrib/find/test/findController.test.ts +++ b/src/vs/editor/contrib/find/test/findController.test.ts @@ -51,8 +51,8 @@ export class TestFindController extends CommonFindController { } } -function fromRange(rng: Range): number[] { - return [rng.startLineNumber, rng.startColumn, rng.endLineNumber, rng.endColumn]; +function fromSelection(slc: Selection | null): number[] { + return [slc!.startLineNumber, slc!.startColumn, slc!.endLineNumber, slc!.endColumn]; } suite('FindController', () => { @@ -68,7 +68,7 @@ suite('FindController', () => { getInteger: (key: string) => undefined, store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); }, remove: (key) => void 0 - } as IStorageService); + } as any); if (platform.isMacintosh) { serviceCollection.set(IClipboardService, { @@ -122,7 +122,7 @@ suite('FindController', () => { nextMatchFindAction.run(null, editor); assert.equal(findState.searchString, 'ABC'); - assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 1, 1, 4]); findController.dispose(); }); @@ -175,14 +175,14 @@ suite('FindController', () => { findState.change({ searchString: 'ABC' }, true); // The first ABC is highlighted. - assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 1, 1, 4]); // I hit Esc to exit the Find dialog. findController.closeFindWidget(); findController.hasFocus = false; // The cursor is now at end of the first line, with ABC on that line highlighted. - assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 1, 1, 4]); // I hit delete to remove it and change the text to XYZ. editor.pushUndoStop(); @@ -195,10 +195,10 @@ suite('FindController', () => { // ABC // XYZ // ABC - assert.equal(editor.getModel().getLineContent(1), 'XYZ'); + assert.equal(editor.getModel()!.getLineContent(1), 'XYZ'); // The cursor is at end of the first line. - assert.deepEqual(fromRange(editor.getSelection()), [1, 4, 1, 4]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 4, 1, 4]); // I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ. nextMatchFindAction.run(null, editor); @@ -224,10 +224,10 @@ suite('FindController', () => { }); nextMatchFindAction.run(null, editor); - assert.deepEqual(fromRange(editor.getSelection()), [1, 26, 1, 29]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 26, 1, 29]); nextMatchFindAction.run(null, editor); - assert.deepEqual(fromRange(editor.getSelection()), [1, 8, 1, 11]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 8, 1, 11]); findController.dispose(); }); @@ -250,10 +250,10 @@ suite('FindController', () => { startFindAction.run(null, editor); nextMatchFindAction.run(null, editor); - assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 13]); + assert.deepEqual(fromSelection(editor.getSelection()), [2, 9, 2, 13]); nextMatchFindAction.run(null, editor); - assert.deepEqual(fromRange(editor.getSelection()), [1, 9, 1, 13]); + assert.deepEqual(fromSelection(editor.getSelection()), [1, 9, 1, 13]); findController.dispose(); }); @@ -330,7 +330,7 @@ suite('FindController', () => { findController.getState().change({ searchString: '\\b\\s{3}\\b', replaceString: ' ', isRegex: true }, false); findController.moveToNextMatch(); - assert.deepEqual(editor.getSelections().map(fromRange), [ + assert.deepEqual(editor.getSelections()!.map(fromSelection), [ [1, 39, 1, 42] ]); @@ -357,7 +357,7 @@ suite('FindController', () => { findController.getState().change({ searchString: '^', replaceString: 'x', isRegex: true }, false); findController.moveToNextMatch(); - assert.deepEqual(editor.getSelections().map(fromRange), [ + assert.deepEqual(editor.getSelections()!.map(fromSelection), [ [2, 1, 2, 1] ]); @@ -388,7 +388,7 @@ suite('FindController', () => { // cmd+f3 nextSelectionMatchFindAction.run(null, editor); - assert.deepEqual(editor.getSelections().map(fromRange), [ + assert.deepEqual(editor.getSelections()!.map(fromSelection), [ [3, 1, 3, 9] ]); @@ -419,7 +419,7 @@ suite('FindController', () => { // cmd+f3 nextSelectionMatchFindAction.run(null, editor); - assert.deepEqual(editor.getSelections().map(fromRange), [ + assert.deepEqual(editor.getSelections()!.map(fromSelection), [ [3, 1, 3, 9] ]); @@ -443,7 +443,7 @@ suite('FindController query options persistence', () => { getInteger: (key: string) => undefined, store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); }, remove: (key) => void 0 - } as IStorageService); + } as any); test('matchCase', () => { withTestCodeEditor([ @@ -464,7 +464,7 @@ suite('FindController query options persistence', () => { // I type ABC. findState.change({ searchString: 'ABC' }, true); // The second ABC is highlighted as matchCase is true. - assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 2, 4]); + assert.deepEqual(fromSelection(editor.getSelection()), [2, 1, 2, 4]); findController.dispose(); }); @@ -491,7 +491,7 @@ suite('FindController query options persistence', () => { // I type AB. findState.change({ searchString: 'AB' }, true); // The second AB is highlighted as wholeWord is true. - assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 2, 3]); + assert.deepEqual(fromSelection(editor.getSelection()), [2, 1, 2, 3]); findController.dispose(); });