diff --git a/src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts b/src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts index e2a7ae59e08727c6ebef7c29b316c63328b5db5b..e75c3faade7ab76d07ae29e96e8a6064971aec34 100644 --- a/src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts +++ b/src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts @@ -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, ''); } diff --git a/src/vs/base/common/keyCodes.ts b/src/vs/base/common/keyCodes.ts index 5ee3473699295a0c20239060f87e18e9b036ac8a..289e2811aab065220e18e88c3b367fc188a9d6b1 100644 --- a/src/vs/base/common/keyCodes.ts +++ b/src/vs/base/common/keyCodes.ts @@ -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]; } diff --git a/src/vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts b/src/vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts index 5e204fc8be267d8314d369160587f4806526a9ed..7529049b83774fa3f1eceadb06f78e159e61324c 100644 --- a/src/vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts +++ b/src/vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts @@ -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] { diff --git a/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts b/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts index a1f187ccc3137b60ff54a6a238207bda50f189ea..43b5b6f0c26b2d76379acd9d1b0528acd80a8f7c 100644 --- a/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts +++ b/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts @@ -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; } } diff --git a/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts b/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts index 15050625c50eb7deea371ad3a3223df23867338e..51cb59538fc1a08e5dfaf9d5c62c436ba43c8871 100644 --- a/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts +++ b/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts @@ -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] { diff --git a/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts b/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts index 04c1a8e401035001a0955baa7b5c5fb173cae865..3add1f33869aa137843bd7ec9848eda9db272aeb 100644 --- a/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts +++ b/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts @@ -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] {