提交 d5df66ae 编写于 作者: Y Yusuke Tsutsumi

Fixing strict-null-checks

上级 1521cc31
......@@ -517,7 +517,10 @@ export class ChordKeybinding {
return hashCodes.join(';');
}
public equals(other: ChordKeybinding): boolean {
public equals(other: ChordKeybinding | null): boolean {
if (other === null) {
return false;
}
if (this.parts.length !== other.parts.length) {
return false;
}
......
......@@ -49,7 +49,7 @@ export interface IControllerOptions {
}
interface IKeybindingDispatcherItem {
keybinding: Keybinding;
keybinding: Keybinding | null;
callback: IKeyBindingCallback;
}
......@@ -63,9 +63,11 @@ export class KeybindingDispatcher {
public has(keybinding: KeyCode): boolean {
let target = createKeybinding(keybinding, platform.OS);
for (const a of this._arr) {
if (target.equals(a.keybinding)) {
return true;
if (target !== null) {
for (const a of this._arr) {
if (target.equals(a.keybinding)) {
return true;
}
}
}
return false;
......
......@@ -346,21 +346,22 @@ suite('KeybindingResolver', () => {
let testResolve = (ctx: IContext, _expectedKey: number, commandId: string) => {
const expectedKey = createKeybinding(_expectedKey, OS)!;
let previousPart = null;
let previousPart: (string | null) = null;
for (let i = 0, len = expectedKey.parts.length; i < len; i++) {
let part = getDispatchStr(expectedKey.parts[i]);
let result = resolver.resolve(ctx, previousPart, part);
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
if (i === len - 1) {
// if it's the final part, then we should find a valid command,
// and there should not be a chord.
assert.equal(result.commandId, commandId, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result.enterChord, false, `Enters chord for ${commandId} at part ${i}`);
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result!.commandId, commandId, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result!.enterChord, false, `Enters chord for ${commandId} at part ${i}`);
} else {
// if it's not the final part, then we should not find a valid command,
// and there should be a chord.
assert.equal(result.commandId, null, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result.enterChord, true, `Enters chord for ${commandId} at part ${i}`);
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result!.commandId, null, `Enters chord for ${commandId} at part ${i}`);
assert.equal(result!.enterChord, true, `Enters chord for ${commandId} at part ${i}`);
}
previousPart = part;
}
......
......@@ -171,7 +171,7 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
}
public getDispatchParts(): (string | null)[] {
let dispatchParts = [];
let dispatchParts: (string | null)[] = [];
for (let part of this._parts) {
dispatchParts.push(part ? this._mapper.getDispatchStrForScanCodeBinding(part) : null);
}
......
......@@ -610,7 +610,7 @@ suite('KeybindingsEditorModel test', () => {
const { ctrlKey, shiftKey, altKey, metaKey } = part.modifiers || { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false };
return new SimpleKeybinding(ctrlKey!, shiftKey!, altKey!, metaKey!, part.keyCode);
};
let parts = [];
let parts: SimpleKeybinding[] = [];
if (firstPart) {
parts.push(aSimpleKeybinding(firstPart));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册