Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e4bc9075
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,发现更多精彩内容 >>
提交
e4bc9075
编写于
3月 22, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve KeybindingIO.readKeybinding
上级
e344ce3d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
58 deletion
+51
-58
src/vs/workbench/services/keybinding/common/keybindingIO.ts
src/vs/workbench/services/keybinding/common/keybindingIO.ts
+51
-58
未找到文件。
src/vs/workbench/services/keybinding/common/keybindingIO.ts
浏览文件 @
e4bc9075
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
KeyMod
,
USER_SETTINGS
,
createKeybinding
,
Keybinding
,
SimpleKeybinding
,
KeybindingType
,
ChordKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
USER_SETTINGS
,
Keybinding
,
SimpleKeybinding
,
ChordKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
IUserFriendlyKeybinding
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
@@ -81,99 +81,92 @@ export class KeybindingIO {
return
this
.
_cachedKeybindingRegex
;
}
public
static
readKeybinding
(
input
:
string
,
OS
:
OperatingSystem
):
Keybinding
{
if
(
!
input
)
{
return
null
;
}
private
static
_readModifiers
(
input
:
string
)
{
input
=
input
.
toLowerCase
().
trim
();
let
ctrlCmd
=
false
,
shift
=
false
,
alt
=
false
,
winCtrl
=
false
,
key
:
string
=
''
;
let
ctrl
=
false
;
let
shift
=
false
;
let
alt
=
false
;
let
meta
=
false
;
let
matchedModifier
:
boolean
;
while
(
/^
(
ctrl|shift|alt|meta|win|cmd
)(\+
|
\-)
/
.
test
(
input
))
{
do
{
matchedModifier
=
false
;
if
(
/^ctrl
(\+
|
\-)
/
.
test
(
input
))
{
if
(
OS
===
OperatingSystem
.
Macintosh
)
{
winCtrl
=
true
;
}
else
{
ctrlCmd
=
true
;
}
ctrl
=
true
;
input
=
input
.
substr
(
'
ctrl-
'
.
length
);
matchedModifier
=
true
;
}
if
(
/^shift
(\+
|
\-)
/
.
test
(
input
))
{
shift
=
true
;
input
=
input
.
substr
(
'
shift-
'
.
length
);
matchedModifier
=
true
;
}
if
(
/^alt
(\+
|
\-)
/
.
test
(
input
))
{
alt
=
true
;
input
=
input
.
substr
(
'
alt-
'
.
length
);
matchedModifier
=
true
;
}
if
(
/^meta
(\+
|
\-)
/
.
test
(
input
))
{
if
(
OS
===
OperatingSystem
.
Macintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
meta
=
true
;
input
=
input
.
substr
(
'
meta-
'
.
length
);
matchedModifier
=
true
;
}
if
(
/^win
(\+
|
\-)
/
.
test
(
input
))
{
if
(
OS
===
OperatingSystem
.
Macintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
meta
=
true
;
input
=
input
.
substr
(
'
win-
'
.
length
);
matchedModifier
=
true
;
}
if
(
/^cmd
(\+
|
\-)
/
.
test
(
input
))
{
if
(
OS
===
OperatingSystem
.
Macintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
meta
=
true
;
input
=
input
.
substr
(
'
cmd-
'
.
length
);
matchedModifier
=
true
;
}
}
}
while
(
matchedModifier
);
let
chord
:
SimpleKeybinding
=
null
;
let
key
:
string
;
le
t
firstSpaceIdx
=
input
.
indexOf
(
'
'
);
cons
t
firstSpaceIdx
=
input
.
indexOf
(
'
'
);
if
(
firstSpaceIdx
>
0
)
{
key
=
input
.
substring
(
0
,
firstSpaceIdx
);
const
readChord
=
KeybindingIO
.
readKeybinding
(
input
.
substring
(
firstSpaceIdx
),
OS
);
if
(
readChord
)
{
if
(
readChord
.
type
===
KeybindingType
.
Chord
)
{
chord
=
readChord
.
firstPart
;
}
else
{
chord
=
readChord
;
}
}
input
=
input
.
substring
(
firstSpaceIdx
);
}
else
{
key
=
input
;
input
=
''
;
}
let
keyCode
=
USER_SETTINGS
.
toKeyCode
(
key
);
return
{
remains
:
input
,
ctrl
,
shift
,
alt
,
meta
,
key
};
}
private
static
_readSimpleKeybinding
(
input
:
string
,
OS
:
OperatingSystem
):
[
SimpleKeybinding
,
string
]
{
const
mods
=
this
.
_readModifiers
(
input
);
const
keyCode
=
USER_SETTINGS
.
toKeyCode
(
mods
.
key
);
return
[
new
SimpleKeybinding
(
mods
.
ctrl
,
mods
.
shift
,
mods
.
alt
,
mods
.
meta
,
keyCode
),
mods
.
remains
];
}
let
result
=
0
;
if
(
ctrlCmd
)
{
result
|=
KeyMod
.
CtrlCmd
;
}
if
(
shift
)
{
result
|=
KeyMod
.
Shift
;
}
if
(
alt
)
{
result
|=
KeyMod
.
Alt
;
public
static
readKeybinding
(
input
:
string
,
OS
:
OperatingSystem
):
Keybinding
{
if
(
!
input
)
{
return
null
;
}
if
(
winCtrl
)
{
result
|=
KeyMod
.
WinCtrl
;
let
[
firstPart
,
remains
]
=
this
.
_readSimpleKeybinding
(
input
,
OS
);
let
chordPart
:
SimpleKeybinding
=
null
;
if
(
remains
.
length
>
0
)
{
[
chordPart
]
=
this
.
_readSimpleKeybinding
(
remains
,
OS
);
}
result
|=
keyCode
;
if
(
chord
)
{
return
new
ChordKeybinding
(
<
SimpleKeybinding
>
createKeybinding
(
result
,
OS
),
chord
);
if
(
chord
Part
)
{
return
new
ChordKeybinding
(
firstPart
,
chordPart
);
}
return
<
SimpleKeybinding
>
createKeybinding
(
result
,
OS
)
;
return
firstPart
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录