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

enable strict null check for find controller (#65553)

上级 ff49f585
......@@ -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",
......
......@@ -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;
}
......
......@@ -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, <any>{
......@@ -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();
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册