Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f4b6f17c
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f4b6f17c
编写于
6月 20, 2019
作者:
P
Peng Lyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
switch to user selected keyboard layout
上级
9e559490
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
26 deletion
+60
-26
src/vs/workbench/contrib/preferences/browser/keyboardLayoutPicker.ts
...bench/contrib/preferences/browser/keyboardLayoutPicker.ts
+10
-6
src/vs/workbench/services/keybinding/browser/keymapService.ts
...vs/workbench/services/keybinding/browser/keymapService.ts
+25
-19
src/vs/workbench/services/keybinding/common/keymapInfo.ts
src/vs/workbench/services/keybinding/common/keymapInfo.ts
+25
-1
未找到文件。
src/vs/workbench/contrib/preferences/browser/keyboardLayoutPicker.ts
浏览文件 @
f4b6f17c
...
...
@@ -6,7 +6,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
StatusbarAlignment
,
IStatusbarService
,
IStatusbarEntryAccessor
}
from
'
vs/platform/statusbar/common/statusbar
'
;
import
{
Disposable
,
MutableDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IKeymapService
,
areKeyboardLayoutsEqual
,
parseKeyboardLayout
}
from
'
vs/workbench/services/keybinding/common/keymapInfo
'
;
import
{
IKeymapService
,
areKeyboardLayoutsEqual
,
parseKeyboardLayout
Description
,
getKeyboardLayoutId
,
IKeyboardLayoutInfo
}
from
'
vs/workbench/services/keybinding/common/keymapInfo
'
;
import
{
LifecyclePhase
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
Extensions
as
WorkbenchExtensions
,
IWorkbenchContribution
,
IWorkbenchContributionsRegistry
}
from
'
vs/workbench/common/contributions
'
;
...
...
@@ -34,7 +34,7 @@ export class KeyboardLayoutPickerContribution extends Disposable implements IWor
let
layout
=
this
.
keymapService
.
getCurrentKeyboardLayout
();
if
(
layout
)
{
let
layoutInfo
=
parseKeyboardLayout
(
layout
);
let
layoutInfo
=
parseKeyboardLayout
Description
(
layout
);
this
.
pickerElement
.
value
=
this
.
statusbarService
.
addEntry
(
{
text
:
`Layout:
${
layoutInfo
.
label
}
`
,
...
...
@@ -49,7 +49,7 @@ export class KeyboardLayoutPickerContribution extends Disposable implements IWor
this
.
_register
(
keymapService
.
onDidChangeKeyboardMapper
(()
=>
{
let
layout
=
this
.
keymapService
.
getCurrentKeyboardLayout
();
let
layoutInfo
=
parseKeyboardLayout
(
layout
);
let
layoutInfo
=
parseKeyboardLayout
Description
(
layout
);
if
(
this
.
pickerElement
.
value
)
{
this
.
pickerElement
.
value
.
update
({
...
...
@@ -75,6 +75,9 @@ export class KeyboardLayoutPickerContribution extends Disposable implements IWor
const
workbenchContributionsRegistry
=
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
);
workbenchContributionsRegistry
.
registerWorkbenchContribution
(
KeyboardLayoutPickerContribution
,
LifecyclePhase
.
Starting
);
interface
LayoutQuickPickItem
extends
IQuickPickItem
{
layout
:
IKeyboardLayoutInfo
;
}
export
class
KeyboardLayoutPickerAction
extends
Action
{
static
readonly
ID
=
KEYBOARD_LAYOUT_OPEN_PICKER
;
...
...
@@ -111,8 +114,9 @@ export class KeyboardLayoutPickerAction extends Action {
const
picks
:
QuickPickInput
[]
=
layouts
.
map
(
layout
=>
{
const
picked
=
!
isAutoDetect
&&
areKeyboardLayoutsEqual
(
currentLayout
,
layout
);
const
layoutInfo
=
parseKeyboardLayout
(
layout
);
const
layoutInfo
=
parseKeyboardLayout
Description
(
layout
);
return
{
layout
:
layout
,
label
:
[
layoutInfo
.
label
,
(
layout
&&
layout
.
isUserKeyboardLayout
)
?
'
(User configured layout)
'
:
''
].
join
(
'
'
),
id
:
(
<
any
>
layout
).
text
||
(
<
any
>
layout
).
lang
||
(
<
any
>
layout
).
layout
,
description
:
layoutInfo
.
description
+
(
picked
?
'
(Current layout)
'
:
''
),
...
...
@@ -134,7 +138,7 @@ export class KeyboardLayoutPickerAction extends Action {
// Offer to "Auto Detect"
const
autoDetectMode
:
IQuickPickItem
=
{
label
:
nls
.
localize
(
'
autoDetect
'
,
"
Auto Detect
"
),
description
:
isAutoDetect
?
`Current:
${
parseKeyboardLayout
(
currentLayout
).
label
}
`
:
undefined
,
description
:
isAutoDetect
?
`Current:
${
parseKeyboardLayout
Description
(
currentLayout
).
label
}
`
:
undefined
,
picked
:
isAutoDetect
?
true
:
undefined
};
...
...
@@ -171,7 +175,7 @@ export class KeyboardLayoutPickerAction extends Action {
return
Promise
.
resolve
();
}
this
.
configurationService
.
updateValue
(
'
keyboard.layout
'
,
pick
.
label
);
this
.
configurationService
.
updateValue
(
'
keyboard.layout
'
,
getKeyboardLayoutId
((
<
LayoutQuickPickItem
>
pick
).
layout
)
);
}
}
...
...
src/vs/workbench/services/keybinding/browser/keymapService.ts
浏览文件 @
f4b6f17c
...
...
@@ -6,11 +6,11 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
toDisposable
,
IDisposable
,
MutableDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IKeymapService
,
IKeyboardLayoutInfo
,
IKeyboardMapping
,
IWindowsKeyboardMapping
,
IWindowsKeyboardLayoutInfo
,
IMacKeyboardLayoutInfo
,
ILinuxKeyboardLayoutInfo
,
KeymapInfo
,
IRawMixedKeyboardMapping
}
from
'
vs/workbench/services/keybinding/common/keymapInfo
'
;
import
{
IKeymapService
,
IKeyboardLayoutInfo
,
IKeyboardMapping
,
IWindowsKeyboardMapping
,
KeymapInfo
,
IRawMixedKeyboardMapping
,
getKeyboardLayoutId
}
from
'
vs/workbench/services/keybinding/common/keymapInfo
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
DispatchConfig
}
from
'
vs/workbench/services/keybinding/common/dispatchConfig
'
;
import
{
IKeyboardMapper
,
CachedKeyboardMapper
}
from
'
vs/workbench/services/keybinding/common/keyboardMapper
'
;
import
{
OS
,
OperatingSystem
,
isMacintosh
,
isWindows
,
isLinux
}
from
'
vs/base/common/platform
'
;
import
{
OS
,
OperatingSystem
,
isMacintosh
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
WindowsKeyboardMapper
}
from
'
vs/workbench/services/keybinding/common/windowsKeyboardMapper
'
;
import
{
MacLinuxFallbackKeyboardMapper
}
from
'
vs/workbench/services/keybinding/common/macLinuxFallbackKeyboardMapper
'
;
import
{
IKeyboardEvent
}
from
'
vs/platform/keybinding/common/keybinding
'
;
...
...
@@ -41,6 +41,10 @@ export class BrowserKeyboardMapperFactory {
private
_mru
:
KeymapInfo
[];
private
_activeKeymapInfo
:
KeymapInfo
|
null
;
get
activeKeymap
():
KeymapInfo
|
null
{
return
this
.
_activeKeymapInfo
;
}
get
keymapInfos
():
KeymapInfo
[]
{
return
this
.
_keymapInfos
;
}
...
...
@@ -233,21 +237,7 @@ export class BrowserKeyboardMapperFactory {
}
public
setKeyboardLayout
(
layoutName
:
string
)
{
let
allKeyboardLayouts
=
this
.
keymapInfos
;
let
matchedLayouts
:
KeymapInfo
[]
=
[];
if
(
isWindows
)
{
matchedLayouts
=
allKeyboardLayouts
.
filter
(
layout
=>
(
<
IWindowsKeyboardLayoutInfo
>
layout
.
layout
).
name
===
layoutName
);
}
if
(
isMacintosh
)
{
// todo, probably we should use layout.id?
matchedLayouts
=
allKeyboardLayouts
.
filter
(
layout
=>
(
<
IMacKeyboardLayoutInfo
>
layout
.
layout
).
lang
===
layoutName
);
}
if
(
isLinux
)
{
// todo, probably we should use layout.id?
matchedLayouts
=
allKeyboardLayouts
.
filter
(
layout
=>
(
<
ILinuxKeyboardLayoutInfo
>
layout
.
layout
).
layout
===
layoutName
);
}
let
matchedLayouts
:
KeymapInfo
[]
=
this
.
keymapInfos
.
filter
(
keymapInfo
=>
getKeyboardLayoutId
(
keymapInfo
.
layout
)
===
layoutName
);
if
(
matchedLayouts
.
length
>
0
)
{
this
.
setActiveKeymapInfo
(
matchedLayouts
[
0
]);
...
...
@@ -498,8 +488,8 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
constructor
(
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
IConfigurationService
configurationService
:
IConfigurationService
,
@
IFileService
fileService
:
IFileService
,
@
IConfigurationService
private
configurationService
:
IConfigurationService
,
)
{
super
();
const
keyboardConfig
=
configurationService
.
getValue
<
{
layout
:
string
}
>
(
'
keyboard
'
);
...
...
@@ -530,6 +520,8 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
this
.
_userKeyboardLayout
.
initialize
().
then
(()
=>
{
if
(
this
.
_userKeyboardLayout
.
keyboardLayout
)
{
BrowserKeyboardMapperFactory
.
INSTANCE
.
registerKeyboardLayout
(
this
.
_userKeyboardLayout
.
keyboardLayout
);
this
.
setUserKeyboardLayoutIfMatched
();
}
});
...
...
@@ -548,10 +540,24 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
}
}
// TODO: trigger keymap update
this
.
setUserKeyboardLayoutIfMatched
();
}));
}
setUserKeyboardLayoutIfMatched
()
{
const
keyboardConfig
=
this
.
configurationService
.
getValue
<
{
layout
:
string
}
>
(
'
keyboard
'
);
const
layout
=
keyboardConfig
.
layout
;
if
(
layout
&&
this
.
_userKeyboardLayout
.
keyboardLayout
)
{
if
(
getKeyboardLayoutId
(
this
.
_userKeyboardLayout
.
keyboardLayout
.
layout
)
===
layout
&&
BrowserKeyboardMapperFactory
.
INSTANCE
.
activeKeymap
)
{
if
(
!
this
.
_userKeyboardLayout
.
keyboardLayout
.
equal
(
BrowserKeyboardMapperFactory
.
INSTANCE
.
activeKeymap
))
{
BrowserKeyboardMapperFactory
.
INSTANCE
.
setActiveKeymapInfo
(
this
.
_userKeyboardLayout
.
keyboardLayout
);
}
}
}
}
registerKeyboardListener
()
{
this
.
layoutChangeListener
.
value
=
BrowserKeyboardMapperFactory
.
INSTANCE
.
onDidChangeKeyboardMapper
(()
=>
{
this
.
_onDidChangeKeyboardMapper
.
fire
();
...
...
src/vs/workbench/services/keybinding/common/keymapInfo.ts
浏览文件 @
f4b6f17c
...
...
@@ -127,7 +127,7 @@ export function areKeyboardLayoutsEqual(a: IKeyboardLayoutInfo | null, b: IKeybo
return
false
;
}
export
function
parseKeyboardLayout
(
layout
:
IKeyboardLayoutInfo
|
null
):
{
label
:
string
,
description
:
string
}
{
export
function
parseKeyboardLayout
Description
(
layout
:
IKeyboardLayoutInfo
|
null
):
{
label
:
string
,
description
:
string
}
{
if
(
!
layout
)
{
return
{
label
:
''
,
description
:
''
};
}
...
...
@@ -177,6 +177,18 @@ export function parseKeyboardLayout(layout: IKeyboardLayoutInfo | null): { label
};
}
export
function
getKeyboardLayoutId
(
layout
:
IKeyboardLayoutInfo
):
string
{
if
((
<
IWindowsKeyboardLayoutInfo
>
layout
).
name
)
{
return
(
<
IWindowsKeyboardLayoutInfo
>
layout
).
name
;
}
if
((
<
IMacKeyboardLayoutInfo
>
layout
).
id
)
{
return
(
<
IMacKeyboardLayoutInfo
>
layout
).
id
;
}
return
(
<
ILinuxKeyboardLayoutInfo
>
layout
).
layout
;
}
function
deserializeMapping
(
serializedMapping
:
ISerializedMapping
)
{
let
mapping
=
serializedMapping
;
...
...
@@ -282,6 +294,18 @@ export class KeymapInfo {
return
score
;
}
equal
(
other
:
KeymapInfo
):
boolean
{
if
(
this
.
isUserKeyboardLayout
!==
other
.
isUserKeyboardLayout
)
{
return
false
;
}
if
(
getKeyboardLayoutId
(
this
.
layout
)
!==
getKeyboardLayoutId
(
other
.
layout
))
{
return
false
;
}
return
this
.
fuzzyEqual
(
other
.
mapping
);
}
fuzzyEqual
(
other
:
IRawMixedKeyboardMapping
):
boolean
{
for
(
let
key
in
other
)
{
if
(
isWindows
&&
(
key
===
'
Backslash
'
||
key
===
'
KeyQ
'
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录