提交 8c0059a9 编写于 作者: P Peng Lyu

User keyboard layout

上级 5a5ccf7e
...@@ -113,11 +113,13 @@ export class KeyboardLayoutPickerAction extends Action { ...@@ -113,11 +113,13 @@ export class KeyboardLayoutPickerAction extends Action {
const picked = !isAutoDetect && areKeyboardLayoutsEqual(currentLayout, layout); const picked = !isAutoDetect && areKeyboardLayoutsEqual(currentLayout, layout);
const layoutInfo = parseKeyboardLayout(layout); const layoutInfo = parseKeyboardLayout(layout);
return { return {
label: layoutInfo.label, label: [layoutInfo.label, (layout && layout.isUserKeyboardLayout) ? '(User configured layout)' : ''].join(' '),
id: (<any>layout).text || (<any>layout).lang || (<any>layout).layout, id: (<any>layout).text || (<any>layout).lang || (<any>layout).layout,
description: layoutInfo.description + (picked ? ' (Current layout)' : ''), description: layoutInfo.description + (picked ? ' (Current layout)' : ''),
picked: !isAutoDetect && areKeyboardLayoutsEqual(currentLayout, layout) picked: !isAutoDetect && areKeyboardLayoutsEqual(currentLayout, layout)
}; };
}).sort((a: IQuickPickItem, b: IQuickPickItem) => {
return a.label < b.label ? -1 : (a.label > b.label ? 1 : 0);
}); });
if (picks.length > 0) { if (picks.length > 0) {
......
...@@ -47,7 +47,7 @@ function deserializeMapping(serializedMapping: ISerializedMapping) { ...@@ -47,7 +47,7 @@ function deserializeMapping(serializedMapping: ISerializedMapping) {
return ret; return ret;
} }
interface IKeyboardMapping { interface IRawMixedKeyboardMapping {
[key: string]: { [key: string]: {
value: string, value: string,
withShift: string; withShift: string;
...@@ -66,15 +66,16 @@ interface ISerializedMapping { ...@@ -66,15 +66,16 @@ interface ISerializedMapping {
} }
export class KeymapInfo { export class KeymapInfo {
mapping: IKeyboardMapping; mapping: IRawMixedKeyboardMapping;
isUserKeyboardLayout: boolean; isUserKeyboardLayout: boolean;
constructor(public layout: IKeyboardLayoutInfo, public secondaryLayouts: IKeyboardLayoutInfo[], keyboardMapping: ISerializedMapping, isUserKeyboardLayout?: boolean) { constructor(public layout: IKeyboardLayoutInfo, public secondaryLayouts: IKeyboardLayoutInfo[], keyboardMapping: ISerializedMapping, isUserKeyboardLayout?: boolean) {
this.mapping = deserializeMapping(keyboardMapping); this.mapping = deserializeMapping(keyboardMapping);
this.isUserKeyboardLayout = !!isUserKeyboardLayout; this.isUserKeyboardLayout = !!isUserKeyboardLayout;
this.layout.isUserKeyboardLayout = !!isUserKeyboardLayout;
} }
static createKeyboardLayoutFromDebugInfo(layout: IKeyboardLayoutInfo, value: IKeyboardMapping, isUserKeyboardLayout?: boolean): KeymapInfo { static createKeyboardLayoutFromDebugInfo(layout: IKeyboardLayoutInfo, value: IRawMixedKeyboardMapping, isUserKeyboardLayout?: boolean): KeymapInfo {
let keyboardLayoutInfo = new KeymapInfo(layout, [], {}, true); let keyboardLayoutInfo = new KeymapInfo(layout, [], {}, true);
keyboardLayoutInfo.mapping = value; keyboardLayoutInfo.mapping = value;
return keyboardLayoutInfo; return keyboardLayoutInfo;
...@@ -85,9 +86,10 @@ export class KeymapInfo { ...@@ -85,9 +86,10 @@ export class KeymapInfo {
this.secondaryLayouts = other.secondaryLayouts; this.secondaryLayouts = other.secondaryLayouts;
this.mapping = other.mapping; this.mapping = other.mapping;
this.isUserKeyboardLayout = other.isUserKeyboardLayout; this.isUserKeyboardLayout = other.isUserKeyboardLayout;
this.layout.isUserKeyboardLayout = other.isUserKeyboardLayout;
} }
fuzzyEqual(other: IKeyboardMapping): boolean { fuzzyEqual(other: IRawMixedKeyboardMapping): boolean {
for (let key in other) { for (let key in other) {
if (isWindows && (key === 'Backslash' || key === 'KeyQ')) { if (isWindows && (key === 'Backslash' || key === 'KeyQ')) {
// keymap from Chromium is probably wrong. // keymap from Chromium is probably wrong.
......
...@@ -87,7 +87,7 @@ export interface IMacKeyboardLayoutInfo { ...@@ -87,7 +87,7 @@ export interface IMacKeyboardLayoutInfo {
localizedName?: string; localizedName?: string;
} }
export type IKeyboardLayoutInfo = IWindowsKeyboardLayoutInfo | ILinuxKeyboardLayoutInfo | IMacKeyboardLayoutInfo; export type IKeyboardLayoutInfo = (IWindowsKeyboardLayoutInfo | ILinuxKeyboardLayoutInfo | IMacKeyboardLayoutInfo) & { isUserKeyboardLayout?: boolean; };
export const IKeymapService = createDecorator<IKeymapService>('keymapService'); export const IKeymapService = createDecorator<IKeymapService>('keymapService');
...@@ -126,7 +126,9 @@ export function areKeyboardLayoutsEqual(a: IKeyboardLayoutInfo | null, b: IKeybo ...@@ -126,7 +126,9 @@ export function areKeyboardLayoutsEqual(a: IKeyboardLayoutInfo | null, b: IKeybo
} }
export function parseKeyboardLayout(layout: IKeyboardLayoutInfo | null): { label: string, description: string } { export function parseKeyboardLayout(layout: IKeyboardLayoutInfo | null): { label: string, description: string } {
if (!layout) {
return { label: '', description: '' };
}
if ((<IWindowsKeyboardLayoutInfo>layout).name) { if ((<IWindowsKeyboardLayoutInfo>layout).name) {
// windows // windows
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册