Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a4c96027
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,发现更多精彩内容 >>
提交
a4c96027
编写于
3月 23, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renames
上级
9003dbc3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
77 deletion
+99
-77
src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts
...bench/services/keybinding/common/windowsKeyboardMapper.ts
+91
-69
src/vs/workbench/services/keybinding/test/win_de_ch.txt
src/vs/workbench/services/keybinding/test/win_de_ch.txt
+4
-4
src/vs/workbench/services/keybinding/test/win_en_us.txt
src/vs/workbench/services/keybinding/test/win_en_us.txt
+4
-4
未找到文件。
src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts
浏览文件 @
a4c96027
...
...
@@ -39,7 +39,7 @@ function windowsKeyMappingEquals(a: IWindowsKeyMapping, b: IWindowsKeyMapping):
}
export
interface
IWindowsKeyboardMapping
{
[
c
ode
:
string
]:
IWindowsKeyMapping
;
[
scanC
ode
:
string
]:
IWindowsKeyMapping
;
}
export
function
windowsKeyboardMappingEquals
(
a
:
IWindowsKeyboardMapping
,
b
:
IWindowsKeyboardMapping
):
boolean
{
...
...
@@ -70,8 +70,8 @@ function log(str: string): void {
const
NATIVE_KEY_CODE_TO_KEY_CODE
:
{
[
nativeKeyCode
:
string
]:
KeyCode
;
}
=
_getNativeMap
();
interface
IHardware
CodeMapping
{
c
ode
:
ScanCode
;
export
interface
IScan
CodeMapping
{
scanC
ode
:
ScanCode
;
keyCode
:
KeyCode
;
value
:
number
;
withShift
:
number
;
...
...
@@ -148,6 +148,16 @@ export class WindowsNativeResolvedKeybinding extends ResolvedKeybinding {
return
result
.
toLowerCase
();
}
public
isWYSISWYG
():
boolean
{
let
firstPart1
=
this
.
_firstPart
?
this
.
_mapper
.
getAriaLabelForKeyCode
(
this
.
_firstPart
.
keyCode
)
:
null
;
let
chordPart1
=
this
.
_chordPart
?
this
.
_mapper
.
getAriaLabelForKeyCode
(
this
.
_chordPart
.
keyCode
)
:
null
;
let
firstPart2
=
this
.
_firstPart
?
USER_SETTINGS
.
fromKeyCode
(
this
.
_firstPart
.
keyCode
)
:
null
;
let
chordPart2
=
this
.
_chordPart
?
USER_SETTINGS
.
fromKeyCode
(
this
.
_chordPart
.
keyCode
)
:
null
;
return
(
firstPart1
===
firstPart2
&&
chordPart1
===
chordPart2
);
}
public
isChord
():
boolean
{
return
(
this
.
_chordPart
?
true
:
false
);
}
...
...
@@ -208,39 +218,67 @@ export class WindowsNativeResolvedKeybinding extends ResolvedKeybinding {
return
result
;
}
private
static
getProducedCharCode
(
kb
:
ScanCodeBinding
,
mapping
:
IScanCodeMapping
):
number
{
if
(
!
mapping
)
{
return
0
;
}
if
(
kb
.
ctrlKey
&&
kb
.
shiftKey
&&
kb
.
altKey
)
{
return
mapping
.
withShiftAltGr
;
}
if
(
kb
.
ctrlKey
&&
kb
.
altKey
)
{
return
mapping
.
withAltGr
;
}
if
(
kb
.
shiftKey
)
{
return
mapping
.
withShift
;
}
return
mapping
.
value
;
}
public
static
getProducedChar
(
kb
:
ScanCodeBinding
,
mapping
:
IScanCodeMapping
):
string
{
const
charCode
=
this
.
getProducedCharCode
(
kb
,
mapping
);
if
(
charCode
===
0
)
{
return
'
---
'
;
}
if
(
charCode
>=
CharCode
.
U_Combining_Grave_Accent
&&
charCode
<=
CharCode
.
U_Combining_Latin_Small_Letter_X
)
{
// combining
return
'
U+
'
+
charCode
.
toString
(
16
);
}
return
'
'
+
String
.
fromCharCode
(
charCode
)
+
'
'
;
}
}
export
class
WindowsKeyboardMapper
implements
IKeyboardMapper
{
private
readonly
_codeInfo
:
I
Hardware
CodeMapping
[];
private
readonly
_
hwToKb
:
KeyCode
[];
private
readonly
_k
b
ToLabel
:
string
[]
=
[];
private
readonly
_k
b
Exists
:
boolean
[];
private
readonly
_codeInfo
:
I
Scan
CodeMapping
[];
private
readonly
_
scanCodeToKeyCode
:
KeyCode
[];
private
readonly
_k
eyCode
ToLabel
:
string
[]
=
[];
private
readonly
_k
eyCode
Exists
:
boolean
[];
constructor
(
rawMappings
:
IWindowsKeyboardMapping
)
{
this
.
_
hwToKb
=
[];
this
.
_k
b
ToLabel
=
[];
this
.
_k
b
Exists
=
[];
this
.
_k
b
ToLabel
[
KeyCode
.
Unknown
]
=
KeyCodeUtils
.
toString
(
KeyCode
.
Unknown
);
this
.
_
scanCodeToKeyCode
=
[];
this
.
_k
eyCode
ToLabel
=
[];
this
.
_k
eyCode
Exists
=
[];
this
.
_k
eyCode
ToLabel
[
KeyCode
.
Unknown
]
=
KeyCodeUtils
.
toString
(
KeyCode
.
Unknown
);
for
(
let
code
=
ScanCode
.
None
;
code
<
ScanCode
.
MAX_VALUE
;
c
ode
++
)
{
const
immutableKeyCode
=
IMMUTABLE_CODE_TO_KEY_CODE
[
c
ode
];
for
(
let
scanCode
=
ScanCode
.
None
;
scanCode
<
ScanCode
.
MAX_VALUE
;
scanC
ode
++
)
{
const
immutableKeyCode
=
IMMUTABLE_CODE_TO_KEY_CODE
[
scanC
ode
];
if
(
immutableKeyCode
!==
-
1
)
{
this
.
_
hwToKb
[
c
ode
]
=
immutableKeyCode
;
this
.
_k
b
ToLabel
[
immutableKeyCode
]
=
KeyCodeUtils
.
toString
(
immutableKeyCode
);
this
.
_k
b
Exists
[
immutableKeyCode
]
=
true
;
this
.
_
scanCodeToKeyCode
[
scanC
ode
]
=
immutableKeyCode
;
this
.
_k
eyCode
ToLabel
[
immutableKeyCode
]
=
KeyCodeUtils
.
toString
(
immutableKeyCode
);
this
.
_k
eyCode
Exists
[
immutableKeyCode
]
=
true
;
}
}
this
.
_codeInfo
=
[];
for
(
let
strCode
in
rawMappings
)
{
if
(
rawMappings
.
hasOwnProperty
(
strCode
))
{
const
c
ode
=
ScanCodeUtils
.
toEnum
(
strCode
);
if
(
c
ode
===
ScanCode
.
None
)
{
log
(
`Unknown
c
ode
${
strCode
}
in mapping.`
);
const
scanC
ode
=
ScanCodeUtils
.
toEnum
(
strCode
);
if
(
scanC
ode
===
ScanCode
.
None
)
{
log
(
`Unknown
scanC
ode
${
strCode
}
in mapping.`
);
continue
;
}
if
(
IMMUTABLE_CODE_TO_KEY_CODE
[
c
ode
]
!==
-
1
)
{
if
(
IMMUTABLE_CODE_TO_KEY_CODE
[
scanC
ode
]
!==
-
1
)
{
continue
;
}
...
...
@@ -251,27 +289,27 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
const
withShiftAltGr
=
WindowsKeyboardMapper
.
_getCharCode
(
rawMapping
.
withShiftAltGr
);
const
keyCode
=
NATIVE_KEY_CODE_TO_KEY_CODE
[
rawMapping
.
vkey
]
||
KeyCode
.
Unknown
;
const
mapping
:
I
Hardware
CodeMapping
=
{
code
:
c
ode
,
const
mapping
:
I
Scan
CodeMapping
=
{
scanCode
:
scanC
ode
,
keyCode
:
keyCode
,
value
:
value
,
withShift
:
withShift
,
withAltGr
:
withAltGr
,
withShiftAltGr
:
withShiftAltGr
,
};
this
.
_codeInfo
[
c
ode
]
=
mapping
;
this
.
_codeInfo
[
scanC
ode
]
=
mapping
;
if
(
keyCode
!==
KeyCode
.
Unknown
)
{
this
.
_k
b
Exists
[
keyCode
]
=
true
;
this
.
_k
eyCode
Exists
[
keyCode
]
=
true
;
if
(
value
>=
CharCode
.
a
&&
value
<=
CharCode
.
z
)
{
this
.
_k
b
ToLabel
[
keyCode
]
=
String
.
fromCharCode
(
CharCode
.
A
+
(
value
-
CharCode
.
a
));
this
.
_k
eyCode
ToLabel
[
keyCode
]
=
String
.
fromCharCode
(
CharCode
.
A
+
(
value
-
CharCode
.
a
));
}
else
if
(
value
)
{
this
.
_k
b
ToLabel
[
keyCode
]
=
String
.
fromCharCode
(
value
);
this
.
_k
eyCode
ToLabel
[
keyCode
]
=
String
.
fromCharCode
(
value
);
}
else
{
this
.
_k
b
ToLabel
[
keyCode
]
=
null
;
this
.
_k
eyCode
ToLabel
[
keyCode
]
=
null
;
}
}
this
.
_
hwToKb
[
c
ode
]
=
keyCode
;
this
.
_
scanCodeToKeyCode
[
scanC
ode
]
=
keyCode
;
}
}
}
...
...
@@ -281,8 +319,8 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
let
cnt
=
0
;
result
.
push
(
`--------------------------------------------------------------------------------------------------`
);
for
(
let
code
=
ScanCode
.
None
;
code
<
ScanCode
.
MAX_VALUE
;
c
ode
++
)
{
if
(
IMMUTABLE_CODE_TO_KEY_CODE
[
c
ode
]
!==
-
1
)
{
for
(
let
scanCode
=
ScanCode
.
None
;
scanCode
<
ScanCode
.
MAX_VALUE
;
scanC
ode
++
)
{
if
(
IMMUTABLE_CODE_TO_KEY_CODE
[
scanC
ode
]
!==
-
1
)
{
continue
;
}
...
...
@@ -292,11 +330,8 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
}
cnt
++
;
const
mapping
=
this
.
_codeInfo
[
code
];
const
strCode
=
ScanCodeUtils
.
toString
(
code
);
const
keyCode
=
this
.
_hwToKb
[
code
];
const
strKeyCode
=
KeyCodeUtils
.
toString
(
keyCode
);
const
uiLabel
=
this
.
_kbToLabel
[
keyCode
];
const
mapping
=
this
.
_codeInfo
[
scanCode
];
const
strCode
=
ScanCodeUtils
.
toString
(
scanCode
);
let
mods
=
[
0b000
,
0b010
,
0b101
,
0b111
];
for
(
let
modIndex
=
0
;
modIndex
<
mods
.
length
;
modIndex
++
)
{
...
...
@@ -304,34 +339,18 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
const
ctrlKey
=
(
mod
&
0b001
)
?
true
:
false
;
const
shiftKey
=
(
mod
&
0b010
)
?
true
:
false
;
const
altKey
=
(
mod
&
0b100
)
?
true
:
false
;
const
strHw
=
`
${
ctrlKey
?
'
Ctrl+
'
:
''
}${
shiftKey
?
'
Shift+
'
:
''
}${
altKey
?
'
Alt+
'
:
''
}${
strCode
}
`
;
const
uiHwLabel
=
`
${
ctrlKey
?
'
Ctrl+
'
:
''
}${
shiftKey
?
'
Shift+
'
:
''
}${
altKey
?
'
Alt+
'
:
''
}${
uiLabel
}
`
;
let
key
=
0
;
if
(
mapping
)
{
if
(
ctrlKey
&&
shiftKey
&&
altKey
)
{
key
=
mapping
.
withShiftAltGr
;
}
else
if
(
ctrlKey
&&
altKey
)
{
key
=
mapping
.
withAltGr
;
}
else
if
(
shiftKey
)
{
key
=
mapping
.
withShift
;
}
else
{
key
=
mapping
.
value
;
}
}
let
strKey
:
string
=
'
---
'
;
if
(
key
!==
0
)
{
if
(
key
>=
CharCode
.
U_Combining_Grave_Accent
&&
key
<=
CharCode
.
U_Combining_Latin_Small_Letter_X
)
{
// combining
strKey
=
'
U+
'
+
key
.
toString
(
16
);
}
else
{
strKey
=
'
'
+
String
.
fromCharCode
(
key
)
+
'
'
;
}
}
const
strKb
=
`
${
ctrlKey
?
'
Ctrl+
'
:
''
}${
shiftKey
?
'
Shift+
'
:
''
}${
altKey
?
'
Alt+
'
:
''
}${
strKeyCode
}
`
;
result
.
push
(
`|
${
this
.
_leftPad
(
strHw
,
30
)}
|
${
strKey
}
|
${
this
.
_leftPad
(
strKb
,
25
)}
|
${
this
.
_leftPad
(
uiHwLabel
,
25
)}
|`
);
const
scanCodeBinding
=
new
ScanCodeBinding
(
ctrlKey
,
shiftKey
,
altKey
,
false
,
scanCode
);
const
kb
=
this
.
_resolveSimpleUserBinding
(
scanCodeBinding
);
const
strKeyCode
=
(
kb
?
KeyCodeUtils
.
toString
(
kb
.
keyCode
)
:
null
);
const
resolvedKb
=
(
kb
?
new
WindowsNativeResolvedKeybinding
(
this
,
kb
,
null
)
:
null
);
const
outScanCode
=
`
${
ctrlKey
?
'
Ctrl+
'
:
''
}${
shiftKey
?
'
Shift+
'
:
''
}${
altKey
?
'
Alt+
'
:
''
}${
strCode
}
`
;
const
ariaLabel
=
(
resolvedKb
?
resolvedKb
.
getAriaLabel
()
:
null
);
const
outUILabel
=
(
ariaLabel
?
ariaLabel
.
replace
(
/Control
\+
/
,
'
Ctrl+
'
)
:
null
);
const
outKey
=
WindowsNativeResolvedKeybinding
.
getProducedChar
(
scanCodeBinding
,
mapping
);
const
outKb
=
(
strKeyCode
?
`
${
ctrlKey
?
'
Ctrl+
'
:
''
}${
shiftKey
?
'
Shift+
'
:
''
}${
altKey
?
'
Alt+
'
:
''
}${
strKeyCode
}
`
:
null
);
result
.
push
(
`|
${
this
.
_leftPad
(
outScanCode
,
30
)}
|
${
outKey
}
|
${
this
.
_leftPad
(
outKb
,
25
)}
|
${
this
.
_leftPad
(
outUILabel
,
25
)}
|`
);
}
result
.
push
(
`--------------------------------------------------------------------------------------------------`
);
}
...
...
@@ -341,6 +360,9 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
}
private
_leftPad
(
str
:
string
,
cnt
:
number
):
string
{
if
(
str
===
null
)
{
str
=
'
null
'
;
}
while
(
str
.
length
<
cnt
)
{
str
=
'
'
+
str
;
}
...
...
@@ -363,19 +385,19 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
}
private
_getLabelForKeyCode
(
keyCode
:
KeyCode
):
string
{
return
this
.
_k
b
ToLabel
[
keyCode
]
||
KeyCodeUtils
.
toString
(
KeyCode
.
Unknown
);
return
this
.
_k
eyCode
ToLabel
[
keyCode
]
||
KeyCodeUtils
.
toString
(
KeyCode
.
Unknown
);
}
public
resolveKeybinding
(
keybinding
:
Keybinding
):
WindowsNativeResolvedKeybinding
[]
{
if
(
keybinding
.
type
===
KeybindingType
.
Chord
)
{
const
firstPartKeyCode
=
keybinding
.
firstPart
.
keyCode
;
const
chordPartKeyCode
=
keybinding
.
chordPart
.
keyCode
;
if
(
!
this
.
_k
bExists
[
firstPartKeyCode
]
||
!
this
.
_kb
Exists
[
chordPartKeyCode
])
{
if
(
!
this
.
_k
eyCodeExists
[
firstPartKeyCode
]
||
!
this
.
_keyCode
Exists
[
chordPartKeyCode
])
{
return
[];
}
return
[
new
WindowsNativeResolvedKeybinding
(
this
,
keybinding
.
firstPart
,
keybinding
.
chordPart
)];
}
else
{
if
(
!
this
.
_k
b
Exists
[
keybinding
.
keyCode
])
{
if
(
!
this
.
_k
eyCode
Exists
[
keybinding
.
keyCode
])
{
return
[];
}
return
[
new
WindowsNativeResolvedKeybinding
(
this
,
keybinding
,
null
)];
...
...
@@ -392,13 +414,13 @@ export class WindowsKeyboardMapper implements IKeyboardMapper {
return
null
;
}
if
(
binding
instanceof
SimpleKeybinding
)
{
if
(
!
this
.
_k
b
Exists
[
binding
.
keyCode
])
{
if
(
!
this
.
_k
eyCode
Exists
[
binding
.
keyCode
])
{
return
null
;
}
return
binding
;
}
const
keyCode
=
this
.
_
hwToKb
[
binding
.
scanCode
]
||
KeyCode
.
Unknown
;
if
(
keyCode
===
KeyCode
.
Unknown
||
!
this
.
_k
b
Exists
[
keyCode
])
{
const
keyCode
=
this
.
_
scanCodeToKeyCode
[
binding
.
scanCode
]
||
KeyCode
.
Unknown
;
if
(
keyCode
===
KeyCode
.
Unknown
||
!
this
.
_k
eyCode
Exists
[
keyCode
])
{
return
null
;
}
return
new
SimpleKeybinding
(
binding
.
ctrlKey
,
binding
.
shiftKey
,
binding
.
altKey
,
binding
.
metaKey
,
keyCode
);
...
...
src/vs/workbench/services/keybinding/test/win_de_ch.txt
浏览文件 @
a4c96027
...
...
@@ -218,10 +218,10 @@
| Ctrl+Alt+Backslash | } | Ctrl+Alt+OEM_8 | Ctrl+Alt+$ |
| Ctrl+Shift+Alt+Backslash | --- | Ctrl+Shift+Alt+OEM_8 | Ctrl+Shift+Alt+$ |
--------------------------------------------------------------------------------------------------
| IntlHash | --- |
undefined | undefined
|
| Shift+IntlHash | --- |
Shift+undefined | Shift+undefined
|
| Ctrl+Alt+IntlHash | --- |
Ctrl+Alt+undefined | Ctrl+Alt+undefined
|
| Ctrl+Shift+Alt+IntlHash | --- |
Ctrl+Shift+Alt+undefined | Ctrl+Shift+Alt+undefined
|
| IntlHash | --- |
null | null
|
| Shift+IntlHash | --- |
null | null
|
| Ctrl+Alt+IntlHash | --- |
null | null
|
| Ctrl+Shift+Alt+IntlHash | --- |
null | null
|
--------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | UI label |
--------------------------------------------------------------------------------------------------
...
...
src/vs/workbench/services/keybinding/test/win_en_us.txt
浏览文件 @
a4c96027
...
...
@@ -218,10 +218,10 @@
| Ctrl+Alt+Backslash | --- | Ctrl+Alt+\ | Ctrl+Alt+\ |
| Ctrl+Shift+Alt+Backslash | --- | Ctrl+Shift+Alt+\ | Ctrl+Shift+Alt+\ |
--------------------------------------------------------------------------------------------------
| IntlHash | --- |
undefined | undefined
|
| Shift+IntlHash | --- |
Shift+undefined | Shift+undefined
|
| Ctrl+Alt+IntlHash | --- |
Ctrl+Alt+undefined | Ctrl+Alt+undefined
|
| Ctrl+Shift+Alt+IntlHash | --- |
Ctrl+Shift+Alt+undefined | Ctrl+Shift+Alt+undefined
|
| IntlHash | --- |
null | null
|
| Shift+IntlHash | --- |
null | null
|
| Ctrl+Alt+IntlHash | --- |
null | null
|
| Ctrl+Shift+Alt+IntlHash | --- |
null | null
|
--------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | UI label |
--------------------------------------------------------------------------------------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录