提交 31d62841 编写于 作者: A Alex Dima

Debt: Correct types for ResolvedKeybinding.getParts()

上级 5df5c920
......@@ -8,7 +8,7 @@ import 'vs/css!./keybindingLabel';
import { IDisposable } from 'vs/base/common/lifecycle';
import { equals } from 'vs/base/common/objects';
import { OperatingSystem } from 'vs/base/common/platform';
import { ResolvedKeybinding } from 'vs/base/common/keycodes';
import { ResolvedKeybinding, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
import { UILabelProvider } from 'vs/platform/keybinding/common/keybindingLabels';
import * as dom from 'vs/base/browser/dom';
......@@ -72,21 +72,21 @@ export class KeybindingLabel implements IDisposable {
this.didEverRender = true;
}
private renderPart(parent: HTMLElement, part: ResolvedKeybinding, match: PartMatches) {
private renderPart(parent: HTMLElement, part: ResolvedKeybindingPart, match: PartMatches) {
const modifierLabels = UILabelProvider.modifierLabels[this.os];
if (part.hasCtrlModifier()) {
if (part.ctrlKey) {
this.renderKey(parent, modifierLabels.ctrlKey, match && match.ctrlKey, modifierLabels.separator);
}
if (part.hasShiftModifier()) {
if (part.shiftKey) {
this.renderKey(parent, modifierLabels.shiftKey, match && match.shiftKey, modifierLabels.separator);
}
if (part.hasAltModifier()) {
if (part.altKey) {
this.renderKey(parent, modifierLabels.altKey, match && match.altKey, modifierLabels.separator);
}
if (part.hasMetaModifier()) {
if (part.metaKey) {
this.renderKey(parent, modifierLabels.metaKey, match && match.metaKey, modifierLabels.separator);
}
const keyLabel = part.getLabelWithoutModifiers();
const keyLabel = part.kbLabel;
if (keyLabel) {
this.renderKey(parent, keyLabel, match && match.keyCode, '');
}
......
......@@ -546,8 +546,27 @@ export class ChordKeybinding {
export type Keybinding = SimpleKeybinding | ChordKeybinding;
export class ResolvedKeybindingPart {
readonly ctrlKey: boolean;
readonly shiftKey: boolean;
readonly altKey: boolean;
readonly metaKey: boolean;
readonly kbLabel: string;
readonly kbAriaLabel: string;
constructor(ctrlKey: boolean, shiftKey: boolean, altKey: boolean, metaKey: boolean, kbLabel: string, kbAriaLabel: string) {
this.ctrlKey = ctrlKey;
this.shiftKey = shiftKey;
this.altKey = altKey;
this.metaKey = metaKey;
this.kbLabel = kbLabel;
this.kbAriaLabel = kbAriaLabel;
}
}
/**
* A resolved keybinding.
* A resolved keybinding. Can be a simple keybinding or a chord keybinding.
*/
export abstract class ResolvedKeybinding {
/**
......@@ -612,5 +631,5 @@ export abstract class ResolvedKeybinding {
/**
* Returns the firstPart, chordPart of the keybinding
*/
public abstract getParts(): [ResolvedKeybinding, ResolvedKeybinding];
public abstract getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart];
}
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { ResolvedKeybinding, KeyCode, KeyCodeUtils, USER_SETTINGS, Keybinding, KeybindingType, SimpleKeybinding } from 'vs/base/common/keyCodes';
import { ResolvedKeybinding, ResolvedKeybindingPart, KeyCode, KeyCodeUtils, USER_SETTINGS, Keybinding, KeybindingType, SimpleKeybinding } from 'vs/base/common/keyCodes';
import { UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider, NO_MODIFIERS } from 'vs/platform/keybinding/common/keybindingLabels';
import { OperatingSystem } from 'vs/base/common/platform';
......@@ -185,8 +185,26 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
return this._firstPart.metaKey;
}
public getParts(): [ResolvedKeybinding, ResolvedKeybinding] {
return [new USLayoutResolvedKeybinding(this._firstPart, this._os), this._chordPart ? new USLayoutResolvedKeybinding(this._chordPart, this._os) : null];
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart] {
return [
this._toResolvedKeybindingPart(this._firstPart),
this._toResolvedKeybindingPart(this._chordPart)
];
}
private _toResolvedKeybindingPart(keybinding: SimpleKeybinding): ResolvedKeybindingPart {
if (!keybinding) {
return null;
}
return new ResolvedKeybindingPart(
keybinding.ctrlKey,
keybinding.shiftKey,
keybinding.altKey,
keybinding.metaKey,
this._getUILabelForKeybinding(keybinding),
this._getAriaLabelForKeybinding(keybinding)
);
}
public getDispatchParts(): [string, string] {
......
......@@ -10,7 +10,7 @@ import * as strings from 'vs/base/common/strings';
import { OperatingSystem, language, LANGUAGE_DEFAULT } from 'vs/base/common/platform';
import { IMatch, IFilter, or, matchesContiguousSubString, matchesPrefix, matchesCamelCase, matchesWords } from 'vs/base/common/filters';
import { Registry } from 'vs/platform/platform';
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { ResolvedKeybinding, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
import { AriaLabelProvider, UserSettingsLabelProvider, UILabelProvider, ModifierLabels as ModLabels } from 'vs/platform/keybinding/common/keybindingLabels';
import { CommonEditorRegistry, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { MenuRegistry, ILocalizedString, SyncActionDescriptor, ICommandAction } from 'vs/platform/actions/common/actions';
......@@ -355,7 +355,7 @@ class KeybindingItemMatches {
return this.hasAnyMatch(firstPartMatch) || this.hasAnyMatch(chordPartMatch) ? { firstPart: firstPartMatch, chordPart: chordPartMatch } : null;
}
private matchPart(part: ResolvedKeybinding, match: KeybindingMatch, word: string): boolean {
private matchPart(part: ResolvedKeybindingPart, match: KeybindingMatch, word: string): boolean {
let matched = false;
if (this.matchesMetaModifier(part, word)) {
matched = true;
......@@ -380,11 +380,11 @@ class KeybindingItemMatches {
return matched;
}
private matchesKeyCode(keybinding: ResolvedKeybinding, word: string): boolean {
private matchesKeyCode(keybinding: ResolvedKeybindingPart, word: string): boolean {
if (!keybinding) {
return false;
}
const ariaLabel = keybinding.getAriaLabelWithoutModifiers();
const ariaLabel = keybinding.kbAriaLabel;
if (ariaLabel.length === 1 || word.length === 1) {
if (strings.compareIgnoreCase(ariaLabel, word) === 0) {
return true;
......@@ -397,11 +397,11 @@ class KeybindingItemMatches {
return false;
}
private matchesMetaModifier(keybinding: ResolvedKeybinding, word: string): boolean {
private matchesMetaModifier(keybinding: ResolvedKeybindingPart, word: string): boolean {
if (!keybinding) {
return false;
}
if (!keybinding.hasMetaModifier()) {
if (!keybinding.metaKey) {
return false;
}
return this.wordMatchesMetaModifier(word);
......@@ -423,11 +423,11 @@ class KeybindingItemMatches {
return false;
}
private matchesCtrlModifier(keybinding: ResolvedKeybinding, word: string): boolean {
private matchesCtrlModifier(keybinding: ResolvedKeybindingPart, word: string): boolean {
if (!keybinding) {
return false;
}
if (!keybinding.hasCtrlModifier()) {
if (!keybinding.ctrlKey) {
return false;
}
return this.wordMatchesCtrlModifier(word);
......@@ -446,11 +446,11 @@ class KeybindingItemMatches {
return false;
}
private matchesShiftModifier(keybinding: ResolvedKeybinding, word: string): boolean {
private matchesShiftModifier(keybinding: ResolvedKeybindingPart, word: string): boolean {
if (!keybinding) {
return false;
}
if (!keybinding.hasShiftModifier()) {
if (!keybinding.shiftKey) {
return false;
}
return this.wordMatchesShiftModifier(word);
......@@ -469,11 +469,11 @@ class KeybindingItemMatches {
return false;
}
private matchesAltModifier(keybinding: ResolvedKeybinding, word: string): boolean {
private matchesAltModifier(keybinding: ResolvedKeybindingPart, word: string): boolean {
if (!keybinding) {
return false;
}
if (!keybinding.hasAltModifier()) {
if (!keybinding.altKey) {
return false;
}
return this.wordMatchesAltModifier(word);
......@@ -503,42 +503,42 @@ class KeybindingItemMatches {
keybindingMatch.keyCode;
}
private isCompleteMatch(part: ResolvedKeybinding, match: KeybindingMatch): boolean {
private isCompleteMatch(part: ResolvedKeybindingPart, match: KeybindingMatch): boolean {
if (!part) {
return true;
}
if (!match.keyCode) {
return false;
}
if (part.hasMetaModifier() && !match.metaKey) {
if (part.metaKey && !match.metaKey) {
return false;
}
if (part.hasAltModifier() && !match.altKey) {
if (part.altKey && !match.altKey) {
return false;
}
if (part.hasCtrlModifier() && !match.ctrlKey) {
if (part.ctrlKey && !match.ctrlKey) {
return false;
}
if (part.hasShiftModifier() && !match.shiftKey) {
if (part.shiftKey && !match.shiftKey) {
return false;
}
return true;
}
private createCompleteMatch(part: ResolvedKeybinding): KeybindingMatch {
private createCompleteMatch(part: ResolvedKeybindingPart): KeybindingMatch {
let match: KeybindingMatch = {};
if (part) {
match.keyCode = true;
if (part.hasMetaModifier()) {
if (part.metaKey) {
match.metaKey = true;
}
if (part.hasAltModifier()) {
if (part.altKey) {
match.altKey = true;
}
if (part.hasCtrlModifier()) {
if (part.ctrlKey) {
match.ctrlKey = true;
}
if (part.hasShiftModifier()) {
if (part.shiftKey) {
match.shiftKey = true;
}
}
......
......@@ -6,7 +6,7 @@
'use strict';
import { OperatingSystem } from 'vs/base/common/platform';
import { KeyCode, ResolvedKeybinding, KeyCodeUtils, SimpleKeybinding, Keybinding, KeybindingType, USER_SETTINGS } from 'vs/base/common/keyCodes';
import { KeyCode, ResolvedKeybinding, KeyCodeUtils, SimpleKeybinding, Keybinding, KeybindingType, USER_SETTINGS, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
import { ScanCode, ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, IMMUTABLE_KEY_CODE_TO_CODE, ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
import { CharCode } from 'vs/base/common/charCode';
import { UILabelProvider, AriaLabelProvider, UserSettingsLabelProvider, ElectronAcceleratorLabelProvider, NO_MODIFIERS } from 'vs/platform/keybinding/common/keybindingLabels';
......@@ -222,8 +222,26 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
return this._firstPart.metaKey;
}
public getParts(): [ResolvedKeybinding, ResolvedKeybinding] {
return [new NativeResolvedKeybinding(this._mapper, this._OS, this._firstPart, null), this._chordPart ? new NativeResolvedKeybinding(this._mapper, this._OS, this._chordPart, null) : null];
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart] {
return [
this._toResolvedKeybindingPart(this._firstPart),
this._toResolvedKeybindingPart(this._chordPart)
];
}
private _toResolvedKeybindingPart(binding: ScanCodeBinding): ResolvedKeybindingPart {
if (!binding) {
return null;
}
return new ResolvedKeybindingPart(
binding.ctrlKey,
binding.shiftKey,
binding.altKey,
binding.metaKey,
this._getUILabelForScanCodeBinding(binding),
this._getAriaLabelForScanCodeBinding(binding)
);
}
public getDispatchParts(): [string, string] {
......
......@@ -5,7 +5,7 @@
'use strict';
import { KeyCode, KeyCodeUtils, ResolvedKeybinding, Keybinding, SimpleKeybinding, KeybindingType, USER_SETTINGS } from 'vs/base/common/keyCodes';
import { KeyCode, KeyCodeUtils, ResolvedKeybinding, Keybinding, SimpleKeybinding, KeybindingType, USER_SETTINGS, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
import { ScanCode, ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
import { CharCode } from 'vs/base/common/charCode';
import { UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider, NO_MODIFIERS } from 'vs/platform/keybinding/common/keybindingLabels';
......@@ -235,8 +235,26 @@ export class WindowsNativeResolvedKeybinding extends ResolvedKeybinding {
return this._firstPart.metaKey;
}
public getParts(): [ResolvedKeybinding, ResolvedKeybinding] {
return [new WindowsNativeResolvedKeybinding(this._mapper, this._firstPart, null), this._chordPart ? new WindowsNativeResolvedKeybinding(this._mapper, this._chordPart, null) : null];
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart] {
return [
this._toResolvedKeybindingPart(this._firstPart),
this._toResolvedKeybindingPart(this._chordPart)
];
}
private _toResolvedKeybindingPart(keybinding: SimpleKeybinding): ResolvedKeybindingPart {
if (!keybinding) {
return null;
}
return new ResolvedKeybindingPart(
keybinding.ctrlKey,
keybinding.shiftKey,
keybinding.altKey,
keybinding.metaKey,
this._getUILabelForKeybinding(keybinding),
this._getAriaLabelForKeybinding(keybinding)
);
}
public getDispatchParts(): [string, string] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册