Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ebd346b3
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ebd346b3
编写于
3月 20, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Share test utils between keyboard mappers
上级
b3f8aee7
变更
6
展开全部
显示空白变更内容
内联
并排
Showing
6 changed file
with
744 addition
and
736 deletion
+744
-736
src/vs/workbench/services/keybinding/common/keyboardMapper.ts
...vs/workbench/services/keybinding/common/keyboardMapper.ts
+4
-593
src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts
...ench/services/keybinding/common/macLinuxKeyboardMapper.ts
+603
-0
src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts
...bench/services/keybinding/common/windowsKeyboardMapper.ts
+2
-1
src/vs/workbench/services/keybinding/test/keyboardMapperTestUtils.ts
...bench/services/keybinding/test/keyboardMapperTestUtils.ts
+107
-0
src/vs/workbench/services/keybinding/test/macLinuxKeyboardMapper.test.ts
...h/services/keybinding/test/macLinuxKeyboardMapper.test.ts
+9
-33
src/vs/workbench/services/keybinding/test/windowsKeyboardMapper.test.ts
...ch/services/keybinding/test/windowsKeyboardMapper.test.ts
+19
-109
未找到文件。
src/vs/workbench/services/keybinding/common/keyboardMapper.ts
浏览文件 @
ebd346b3
此差异已折叠。
点击以展开。
src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts
0 → 100644
浏览文件 @
ebd346b3
此差异已折叠。
点击以展开。
src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts
浏览文件 @
ebd346b3
...
...
@@ -11,6 +11,7 @@ import { CharCode } from 'vs/base/common/charCode';
import
{
UILabelProvider
,
AriaLabelProvider
,
ElectronAcceleratorLabelProvider
,
UserSettingsLabelProvider
}
from
'
vs/platform/keybinding/common/keybindingLabels
'
;
import
{
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
IKeyboardMapper
}
from
'
vs/workbench/services/keybinding/common/keyboardMapper
'
;
export
interface
IKeyMapping
{
vkey
:
string
;
...
...
@@ -173,7 +174,7 @@ export class WindowsNativeResolvedKeybinding extends ResolvedKeybinding {
}
}
export
class
WindowsKeyboardMapper
{
export
class
WindowsKeyboardMapper
implements
IKeyboardMapper
{
private
readonly
_codeInfo
:
IHardwareCodeMapping
[];
private
readonly
_hwToKb
:
KeyCode
[];
...
...
src/vs/workbench/services/keybinding/test/keyboardMapperTestUtils.ts
0 → 100644
浏览文件 @
ebd346b3
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
IKeyboardMapper
}
from
'
vs/workbench/services/keybinding/common/keyboardMapper
'
;
import
{
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
readFile
,
writeFile
}
from
'
vs/base/node/pfs
'
;
export
interface
IResolvedKeybinding
{
label
:
string
;
ariaLabel
:
string
;
HTMLLabel
:
IHTMLContentElement
[];
electronAccelerator
:
string
;
userSettingsLabel
:
string
;
isChord
:
boolean
;
hasCtrlModifier
:
boolean
;
hasShiftModifier
:
boolean
;
hasAltModifier
:
boolean
;
hasMetaModifier
:
boolean
;
dispatchParts
:
[
string
,
string
];
}
export
function
assertResolveKeybinding
(
mapper
:
IKeyboardMapper
,
keybinding
:
Keybinding
,
expected
:
IResolvedKeybinding
[]):
void
{
let
actual
:
IResolvedKeybinding
[]
=
mapper
.
resolveKeybinding
(
keybinding
).
map
((
kb
=>
{
return
{
label
:
kb
.
getLabel
(),
ariaLabel
:
kb
.
getAriaLabel
(),
HTMLLabel
:
kb
.
getHTMLLabel
(),
electronAccelerator
:
kb
.
getElectronAccelerator
(),
userSettingsLabel
:
kb
.
getUserSettingsLabel
(),
isChord
:
kb
.
isChord
(),
hasCtrlModifier
:
kb
.
hasCtrlModifier
(),
hasShiftModifier
:
kb
.
hasShiftModifier
(),
hasAltModifier
:
kb
.
hasAltModifier
(),
hasMetaModifier
:
kb
.
hasMetaModifier
(),
dispatchParts
:
kb
.
getDispatchParts
(),
};
}));
assert
.
deepEqual
(
actual
,
expected
);
}
function
_htmlPieces
(
pieces
:
string
[]):
IHTMLContentElement
[]
{
let
children
:
IHTMLContentElement
[]
=
[];
for
(
let
i
=
0
,
len
=
pieces
.
length
;
i
<
len
;
i
++
)
{
if
(
i
!==
0
)
{
children
.
push
({
tagName
:
'
span
'
,
text
:
'
+
'
});
}
children
.
push
({
tagName
:
'
span
'
,
className
:
'
monaco-kbkey
'
,
text
:
pieces
[
i
]
});
}
return
children
;
}
export
function
simpleHTMLLabel
(
pieces
:
string
[]):
IHTMLContentElement
{
return
{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
_htmlPieces
(
pieces
)
};
}
export
function
chordHTMLLabel
(
firstPart
:
string
[],
chordPart
:
string
[]):
IHTMLContentElement
{
return
{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
[].
concat
(
_htmlPieces
(
firstPart
),
[{
tagName
:
'
span
'
,
text
:
'
'
}],
_htmlPieces
(
chordPart
)
)
};
}
export
function
readRawMapping
<
T
>
(
file
:
string
):
TPromise
<
T
>
{
return
readFile
(
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
.js`
)).
then
((
buff
)
=>
{
let
contents
=
buff
.
toString
();
let
func
=
new
Function
(
'
define
'
,
contents
);
let
rawMappings
:
T
=
null
;
func
(
function
(
value
)
{
rawMappings
=
value
;
});
return
rawMappings
;
});
}
export
function
assertMapping
(
mapper
:
IKeyboardMapper
,
file
:
string
,
done
:
(
err
?:
any
)
=>
void
):
void
{
const
filePath
=
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
`
);
readFile
(
filePath
).
then
((
buff
)
=>
{
let
expected
=
buff
.
toString
();
const
actual
=
mapper
.
dumpDebugInfo
();
if
(
actual
!==
expected
)
{
writeFile
(
filePath
,
actual
);
}
try
{
assert
.
deepEqual
(
actual
,
expected
);
}
catch
(
err
)
{
return
done
(
err
);
}
done
();
},
done
);
}
src/vs/workbench/services/keybinding/test/
k
eyboardMapper.test.ts
→
src/vs/workbench/services/keybinding/test/
macLinuxK
eyboardMapper.test.ts
浏览文件 @
ebd346b3
...
...
@@ -7,48 +7,24 @@
import
*
as
assert
from
'
assert
'
;
import
{
KeyMod
,
KeyCode
,
createKeybinding
,
SimpleKeybinding
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyboardMapper
,
IKeyboardMapping
}
from
'
vs/workbench/services/keybinding/common/k
eyboardMapper
'
;
import
{
MacLinuxKeyboardMapper
,
IKeyboardMapping
}
from
'
vs/workbench/services/keybinding/common/macLinuxK
eyboardMapper
'
;
import
{
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
UserSettingsLabelProvider
}
from
'
vs/platform/keybinding/common/keybindingLabels
'
;
import
{
USLayoutResolvedKeybinding
}
from
'
vs/platform/keybinding/common/usLayoutResolvedKeybinding
'
;
import
{
KeyboardEventCodeUtils
}
from
'
vs/workbench/services/keybinding/common/keyboardEventCode
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
readFile
,
writeFile
}
from
'
vs/base/node/pfs
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
readRawMapping
,
assertMapping
}
from
'
vs/workbench/services/keybinding/test/keyboardMapperTestUtils
'
;
function
createKeyboardMapper
(
file
:
string
,
OS
:
OperatingSystem
):
TPromise
<
KeyboardMapper
>
{
return
readFile
(
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
.js`
)).
then
((
buff
)
=>
{
let
contents
=
buff
.
toString
();
let
func
=
new
Function
(
'
define
'
,
contents
);
let
rawMappings
:
IKeyboardMapping
=
null
;
func
(
function
(
value
)
{
rawMappings
=
value
;
function
createKeyboardMapper
(
file
:
string
,
OS
:
OperatingSystem
):
TPromise
<
MacLinuxKeyboardMapper
>
{
return
readRawMapping
<
IKeyboardMapping
>
(
file
).
then
((
rawMappings
)
=>
{
return
new
MacLinuxKeyboardMapper
(
rawMappings
,
OS
);
});
return
new
KeyboardMapper
(
rawMappings
,
OS
);
});
}
function
assertMapping
(
mapper
:
KeyboardMapper
,
file
:
string
,
done
:
(
err
?:
any
)
=>
void
):
void
{
const
filePath
=
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
`
);
readFile
(
filePath
).
then
((
buff
)
=>
{
let
expected
=
buff
.
toString
();
const
actual
=
mapper
.
dumpDebugInfo
();
if
(
actual
!==
expected
)
{
writeFile
(
filePath
,
actual
);
}
try
{
assert
.
deepEqual
(
actual
,
expected
);
}
catch
(
err
)
{
return
done
(
err
);
}
done
();
},
done
);
}
suite
(
'
keyboardMapper - MAC de_ch
'
,
()
=>
{
let
mapper
:
KeyboardMapper
;
let
mapper
:
MacLinux
KeyboardMapper
;
suiteSetup
((
done
)
=>
{
createKeyboardMapper
(
'
mac_de_ch
'
,
OperatingSystem
.
Macintosh
).
then
((
_mapper
)
=>
{
...
...
@@ -120,7 +96,7 @@ suite('keyboardMapper - MAC de_ch', () => {
suite
(
'
keyboardMapper - LINUX de_ch
'
,
()
=>
{
let
mapper
:
KeyboardMapper
;
let
mapper
:
MacLinux
KeyboardMapper
;
suiteSetup
((
done
)
=>
{
createKeyboardMapper
(
'
linux_de_ch
'
,
OperatingSystem
.
Linux
).
then
((
_mapper
)
=>
{
...
...
@@ -155,7 +131,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
suite
(
'
keyboardMapper - LINUX de_ch
'
,
()
=>
{
let
mapper
:
KeyboardMapper
;
let
mapper
:
MacLinux
KeyboardMapper
;
suiteSetup
((
done
)
=>
{
createKeyboardMapper
(
'
linux_en_us
'
,
OperatingSystem
.
Linux
).
then
((
_mapper
)
=>
{
...
...
@@ -169,7 +145,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
});
});
function
_assertKeybindingTranslation
(
mapper
:
KeyboardMapper
,
OS
:
OperatingSystem
,
kb
:
number
,
_expected
:
string
|
string
[]):
void
{
function
_assertKeybindingTranslation
(
mapper
:
MacLinux
KeyboardMapper
,
OS
:
OperatingSystem
,
kb
:
number
,
_expected
:
string
|
string
[]):
void
{
let
expected
:
string
[];
if
(
typeof
_expected
===
'
string
'
)
{
expected
=
[
_expected
];
...
...
src/vs/workbench/services/keybinding/test/windowsKeyboardMapper.test.ts
浏览文件 @
ebd346b3
...
...
@@ -5,108 +5,20 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
readFile
,
writeFile
}
from
'
vs/base/node/pfs
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
WindowsKeyboardMapper
,
IKeyboardMapping
}
from
'
vs/workbench/services/keybinding/common/windowsKeyboardMapper
'
;
import
{
createKeybinding
,
KeyMod
,
KeyCode
,
KeyChord
}
from
'
vs/base/common/keyCodes
'
;
import
{
I
HTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
I
ResolvedKeybinding
,
assertResolveKeybinding
,
readRawMapping
,
assertMapping
,
simpleHTMLLabel
,
chordHTMLLabel
}
from
'
vs/workbench/services/keybinding/test/keyboardMapperTestUtils
'
;
function
createKeyboardMapper
(
file
:
string
,
OS
:
OperatingSystem
):
TPromise
<
WindowsKeyboardMapper
>
{
return
readFile
(
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
.js`
)).
then
((
buff
)
=>
{
let
contents
=
buff
.
toString
();
let
func
=
new
Function
(
'
define
'
,
contents
);
let
rawMappings
:
IKeyboardMapping
=
null
;
func
(
function
(
value
)
{
rawMappings
=
value
;
});
function
createKeyboardMapper
(
file
:
string
):
TPromise
<
WindowsKeyboardMapper
>
{
return
readRawMapping
<
IKeyboardMapping
>
(
file
).
then
((
rawMappings
)
=>
{
return
new
WindowsKeyboardMapper
(
rawMappings
);
});
}
function
assertMapping
(
mapper
:
WindowsKeyboardMapper
,
file
:
string
,
done
:
(
err
?:
any
)
=>
void
):
void
{
const
filePath
=
require
.
toUrl
(
`vs/workbench/services/keybinding/test/
${
file
}
`
);
readFile
(
filePath
).
then
((
buff
)
=>
{
let
expected
=
buff
.
toString
();
const
actual
=
mapper
.
dumpDebugInfo
();
if
(
actual
!==
expected
)
{
writeFile
(
filePath
,
actual
);
}
try
{
assert
.
deepEqual
(
actual
,
expected
);
}
catch
(
err
)
{
return
done
(
err
);
}
done
();
},
done
);
}
function
_htmlPieces
(
pieces
:
string
[]):
IHTMLContentElement
[]
{
let
children
:
IHTMLContentElement
[]
=
[];
for
(
let
i
=
0
,
len
=
pieces
.
length
;
i
<
len
;
i
++
)
{
if
(
i
!==
0
)
{
children
.
push
({
tagName
:
'
span
'
,
text
:
'
+
'
});
}
children
.
push
({
tagName
:
'
span
'
,
className
:
'
monaco-kbkey
'
,
text
:
pieces
[
i
]
});
}
return
children
;
}
function
simpleHTMLLabel
(
pieces
:
string
[]):
IHTMLContentElement
{
return
{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
_htmlPieces
(
pieces
)
};
}
function
chordHTMLLabel
(
firstPart
:
string
[],
chordPart
:
string
[]):
IHTMLContentElement
{
return
{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
[].
concat
(
_htmlPieces
(
firstPart
),
[{
tagName
:
'
span
'
,
text
:
'
'
}],
_htmlPieces
(
chordPart
)
)
};
}
interface
IResolvedKeybindingExpected
{
label
:
string
;
ariaLabel
:
string
;
HTMLLabel
:
IHTMLContentElement
[];
electronAccelerator
:
string
;
userSettingsLabel
:
string
;
isChord
:
boolean
;
hasCtrlModifier
:
boolean
;
hasShiftModifier
:
boolean
;
hasAltModifier
:
boolean
;
hasMetaModifier
:
boolean
;
dispatchParts
:
[
string
,
string
];
}
function
_assertResolvedKeybinding
(
mapper
:
WindowsKeyboardMapper
,
k
:
number
,
expected
:
IResolvedKeybindingExpected
):
void
{
let
kbs
=
mapper
.
resolveKeybinding
(
createKeybinding
(
k
,
OperatingSystem
.
Windows
));
assert
.
equal
(
kbs
.
length
,
1
);
let
kb
=
kbs
[
0
];
let
actual
:
IResolvedKeybindingExpected
=
{
label
:
kb
.
getLabel
(),
ariaLabel
:
kb
.
getAriaLabel
(),
HTMLLabel
:
kb
.
getHTMLLabel
(),
electronAccelerator
:
kb
.
getElectronAccelerator
(),
userSettingsLabel
:
kb
.
getUserSettingsLabel
(),
isChord
:
kb
.
isChord
(),
hasCtrlModifier
:
kb
.
hasCtrlModifier
(),
hasShiftModifier
:
kb
.
hasShiftModifier
(),
hasAltModifier
:
kb
.
hasAltModifier
(),
hasMetaModifier
:
kb
.
hasMetaModifier
(),
dispatchParts
:
kb
.
getDispatchParts
(),
};
assert
.
deepEqual
(
actual
,
expected
);
function
_assertResolveKeybinding
(
mapper
:
WindowsKeyboardMapper
,
k
:
number
,
expected
:
IResolvedKeybinding
):
void
{
assertResolveKeybinding
(
mapper
,
createKeybinding
(
k
,
OperatingSystem
.
Windows
),
[
expected
]);
}
suite
(
'
keyboardMapper - WINDOWS de_ch
'
,
()
=>
{
...
...
@@ -114,7 +26,7 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
let
mapper
:
WindowsKeyboardMapper
;
suiteSetup
((
done
)
=>
{
createKeyboardMapper
(
'
win_de_ch
'
,
OperatingSystem
.
Macintosh
).
then
((
_mapper
)
=>
{
createKeyboardMapper
(
'
win_de_ch
'
).
then
((
_mapper
)
=>
{
mapper
=
_mapper
;
done
();
},
done
);
...
...
@@ -124,12 +36,9 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
assertMapping
(
mapper
,
'
win_de_ch.txt
'
,
done
);
});
function
assertResolveKeybinding
(
kb
:
number
,
expected
:
IResolvedKeybindingExpected
):
void
{
_assertResolvedKeybinding
(
mapper
,
kb
,
expected
);
}
test
(
'
resolveKeybinding Ctrl+A
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_A
,
{
label
:
'
Ctrl+A
'
,
...
...
@@ -148,7 +57,8 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
});
test
(
'
resolveKeybinding Ctrl+Z
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_Z
,
{
label
:
'
Ctrl+Z
'
,
...
...
@@ -167,7 +77,8 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
});
test
(
'
resolveKeybinding Ctrl+]
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyMod
.
CtrlCmd
|
KeyCode
.
US_CLOSE_SQUARE_BRACKET
,
{
label
:
'
Ctrl+^
'
,
...
...
@@ -186,7 +97,8 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
});
test
(
'
resolveKeybinding Ctrl+/
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyMod
.
CtrlCmd
|
KeyCode
.
US_SLASH
,
{
label
:
'
Ctrl+§
'
,
...
...
@@ -205,7 +117,8 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
});
test
(
'
resolveKeybinding Ctrl+K Ctrl+
\\
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
US_BACKSLASH
),
{
label
:
'
Ctrl+K Ctrl+ä
'
,
...
...
@@ -229,7 +142,7 @@ suite('keyboardMapper - WINDOWS en_us', () => {
let
mapper
:
WindowsKeyboardMapper
;
suiteSetup
((
done
)
=>
{
createKeyboardMapper
(
'
win_en_us
'
,
OperatingSystem
.
Macintosh
).
then
((
_mapper
)
=>
{
createKeyboardMapper
(
'
win_en_us
'
).
then
((
_mapper
)
=>
{
mapper
=
_mapper
;
done
();
},
done
);
...
...
@@ -239,12 +152,9 @@ suite('keyboardMapper - WINDOWS en_us', () => {
assertMapping
(
mapper
,
'
win_en_us.txt
'
,
done
);
});
function
assertResolveKeybinding
(
kb
:
number
,
expected
:
IResolvedKeybindingExpected
):
void
{
_assertResolvedKeybinding
(
mapper
,
kb
,
expected
);
}
test
(
'
resolveKeybinding Ctrl+K Ctrl+
\\
'
,
()
=>
{
assertResolveKeybinding
(
_assertResolveKeybinding
(
mapper
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
US_BACKSLASH
),
{
label
:
'
Ctrl+K Ctrl+
\\
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录