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

Fixing strict-null-checks

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