提交 39da581b 编写于 作者: C Chris Ganga 提交者: Matt Bierner

enable strict null check for find controller (#65553)

上级 ff49f585
...@@ -240,6 +240,7 @@ ...@@ -240,6 +240,7 @@
"./vs/editor/contrib/find/replacePattern.ts", "./vs/editor/contrib/find/replacePattern.ts",
"./vs/editor/contrib/find/simpleFindWidget.ts", "./vs/editor/contrib/find/simpleFindWidget.ts",
"./vs/editor/contrib/find/test/find.test.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/find/test/replacePattern.test.ts",
"./vs/editor/contrib/folding/folding.ts", "./vs/editor/contrib/folding/folding.ts",
"./vs/editor/contrib/folding/foldingDecorations.ts", "./vs/editor/contrib/folding/foldingDecorations.ts",
......
...@@ -437,7 +437,7 @@ export class StartFindAction extends EditorAction { ...@@ -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); let controller = CommonFindController.get(editor);
if (controller) { if (controller) {
controller.start({ controller.start({
...@@ -488,7 +488,7 @@ export class StartFindWithSelectionAction extends EditorAction { ...@@ -488,7 +488,7 @@ export class StartFindWithSelectionAction extends EditorAction {
} }
} }
export abstract class MatchFindAction 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); let controller = CommonFindController.get(editor);
if (controller && !this._run(controller)) { if (controller && !this._run(controller)) {
controller.start({ controller.start({
...@@ -551,7 +551,7 @@ export class PreviousMatchFindAction extends MatchFindAction { ...@@ -551,7 +551,7 @@ export class PreviousMatchFindAction extends MatchFindAction {
} }
export abstract class SelectionMatchFindAction extends EditorAction { 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); let controller = CommonFindController.get(editor);
if (!controller) { if (!controller) {
return; return;
...@@ -641,7 +641,7 @@ export class StartFindReplaceAction extends EditorAction { ...@@ -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) { if (!editor.hasModel() || editor.getConfiguration().readOnly) {
return; return;
} }
......
...@@ -51,8 +51,8 @@ export class TestFindController extends CommonFindController { ...@@ -51,8 +51,8 @@ export class TestFindController extends CommonFindController {
} }
} }
function fromRange(rng: Range): number[] { function fromSelection(slc: Selection | null): number[] {
return [rng.startLineNumber, rng.startColumn, rng.endLineNumber, rng.endColumn]; return [slc!.startLineNumber, slc!.startColumn, slc!.endLineNumber, slc!.endColumn];
} }
suite('FindController', () => { suite('FindController', () => {
...@@ -68,7 +68,7 @@ suite('FindController', () => { ...@@ -68,7 +68,7 @@ suite('FindController', () => {
getInteger: (key: string) => undefined, getInteger: (key: string) => undefined,
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); }, store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
remove: (key) => void 0 remove: (key) => void 0
} as IStorageService); } as any);
if (platform.isMacintosh) { if (platform.isMacintosh) {
serviceCollection.set(IClipboardService, <any>{ serviceCollection.set(IClipboardService, <any>{
...@@ -122,7 +122,7 @@ suite('FindController', () => { ...@@ -122,7 +122,7 @@ suite('FindController', () => {
nextMatchFindAction.run(null, editor); nextMatchFindAction.run(null, editor);
assert.equal(findState.searchString, 'ABC'); 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(); findController.dispose();
}); });
...@@ -175,14 +175,14 @@ suite('FindController', () => { ...@@ -175,14 +175,14 @@ suite('FindController', () => {
findState.change({ searchString: 'ABC' }, true); findState.change({ searchString: 'ABC' }, true);
// The first ABC is highlighted. // 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. // I hit Esc to exit the Find dialog.
findController.closeFindWidget(); findController.closeFindWidget();
findController.hasFocus = false; findController.hasFocus = false;
// The cursor is now at end of the first line, with ABC on that line highlighted. // 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. // I hit delete to remove it and change the text to XYZ.
editor.pushUndoStop(); editor.pushUndoStop();
...@@ -195,10 +195,10 @@ suite('FindController', () => { ...@@ -195,10 +195,10 @@ suite('FindController', () => {
// ABC // ABC
// XYZ // XYZ
// ABC // ABC
assert.equal(editor.getModel().getLineContent(1), 'XYZ'); assert.equal(editor.getModel()!.getLineContent(1), 'XYZ');
// The cursor is at end of the first line. // 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. // I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
nextMatchFindAction.run(null, editor); nextMatchFindAction.run(null, editor);
...@@ -224,10 +224,10 @@ suite('FindController', () => { ...@@ -224,10 +224,10 @@ suite('FindController', () => {
}); });
nextMatchFindAction.run(null, editor); 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); nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 8, 1, 11]); assert.deepEqual(fromSelection(editor.getSelection()), [1, 8, 1, 11]);
findController.dispose(); findController.dispose();
}); });
...@@ -250,10 +250,10 @@ suite('FindController', () => { ...@@ -250,10 +250,10 @@ suite('FindController', () => {
startFindAction.run(null, editor); startFindAction.run(null, editor);
nextMatchFindAction.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); nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 9, 1, 13]); assert.deepEqual(fromSelection(editor.getSelection()), [1, 9, 1, 13]);
findController.dispose(); findController.dispose();
}); });
...@@ -330,7 +330,7 @@ suite('FindController', () => { ...@@ -330,7 +330,7 @@ suite('FindController', () => {
findController.getState().change({ searchString: '\\b\\s{3}\\b', replaceString: ' ', isRegex: true }, false); findController.getState().change({ searchString: '\\b\\s{3}\\b', replaceString: ' ', isRegex: true }, false);
findController.moveToNextMatch(); findController.moveToNextMatch();
assert.deepEqual(editor.getSelections().map(fromRange), [ assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[1, 39, 1, 42] [1, 39, 1, 42]
]); ]);
...@@ -357,7 +357,7 @@ suite('FindController', () => { ...@@ -357,7 +357,7 @@ suite('FindController', () => {
findController.getState().change({ searchString: '^', replaceString: 'x', isRegex: true }, false); findController.getState().change({ searchString: '^', replaceString: 'x', isRegex: true }, false);
findController.moveToNextMatch(); findController.moveToNextMatch();
assert.deepEqual(editor.getSelections().map(fromRange), [ assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[2, 1, 2, 1] [2, 1, 2, 1]
]); ]);
...@@ -388,7 +388,7 @@ suite('FindController', () => { ...@@ -388,7 +388,7 @@ suite('FindController', () => {
// cmd+f3 // cmd+f3
nextSelectionMatchFindAction.run(null, editor); nextSelectionMatchFindAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [ assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[3, 1, 3, 9] [3, 1, 3, 9]
]); ]);
...@@ -419,7 +419,7 @@ suite('FindController', () => { ...@@ -419,7 +419,7 @@ suite('FindController', () => {
// cmd+f3 // cmd+f3
nextSelectionMatchFindAction.run(null, editor); nextSelectionMatchFindAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [ assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[3, 1, 3, 9] [3, 1, 3, 9]
]); ]);
...@@ -443,7 +443,7 @@ suite('FindController query options persistence', () => { ...@@ -443,7 +443,7 @@ suite('FindController query options persistence', () => {
getInteger: (key: string) => undefined, getInteger: (key: string) => undefined,
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); }, store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
remove: (key) => void 0 remove: (key) => void 0
} as IStorageService); } as any);
test('matchCase', () => { test('matchCase', () => {
withTestCodeEditor([ withTestCodeEditor([
...@@ -464,7 +464,7 @@ suite('FindController query options persistence', () => { ...@@ -464,7 +464,7 @@ suite('FindController query options persistence', () => {
// I type ABC. // I type ABC.
findState.change({ searchString: 'ABC' }, true); findState.change({ searchString: 'ABC' }, true);
// The second ABC is highlighted as matchCase is 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(); findController.dispose();
}); });
...@@ -491,7 +491,7 @@ suite('FindController query options persistence', () => { ...@@ -491,7 +491,7 @@ suite('FindController query options persistence', () => {
// I type AB. // I type AB.
findState.change({ searchString: 'AB' }, true); findState.change({ searchString: 'AB' }, true);
// The second AB is highlighted as wholeWord is 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(); findController.dispose();
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册