Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
81bb89de
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,发现更多精彩内容 >>
提交
81bb89de
编写于
9月 13, 2016
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Keep keyCodes.ts lean and mean
上级
ce099db9
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
541 addition
and
525 deletion
+541
-525
src/vs/base/browser/ui/dropdown/dropdown.ts
src/vs/base/browser/ui/dropdown/dropdown.ts
+1
-1
src/vs/base/browser/ui/menu/menu.ts
src/vs/base/browser/ui/menu/menu.ts
+1
-1
src/vs/base/browser/ui/toolbar/toolbar.ts
src/vs/base/browser/ui/toolbar/toolbar.ts
+1
-1
src/vs/base/common/keyCodes.ts
src/vs/base/common/keyCodes.ts
+3
-504
src/vs/base/common/keybinding.ts
src/vs/base/common/keybinding.ts
+508
-0
src/vs/base/parts/quickopen/common/quickOpen.ts
src/vs/base/parts/quickopen/common/quickOpen.ts
+1
-1
src/vs/code/electron-main/menus.ts
src/vs/code/electron-main/menus.ts
+1
-1
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
+2
-1
src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts
...itor/contrib/defineKeybinding/browser/defineKeybinding.ts
+2
-1
src/vs/editor/test/common/standalone/standaloneBase.test.ts
src/vs/editor/test/common/standalone/standaloneBase.test.ts
+1
-1
src/vs/platform/contextview/browser/contextView.ts
src/vs/platform/contextview/browser/contextView.ts
+1
-1
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
+2
-1
src/vs/platform/keybinding/common/keybinding.ts
src/vs/platform/keybinding/common/keybinding.ts
+1
-1
src/vs/platform/keybinding/common/keybindingResolver.ts
src/vs/platform/keybinding/common/keybindingResolver.ts
+2
-1
src/vs/platform/keybinding/test/common/keybindingIO.test.ts
src/vs/platform/keybinding/test/common/keybindingIO.test.ts
+2
-1
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
.../platform/keybinding/test/common/mockKeybindingService.ts
+1
-1
src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts
...ench/parts/extensions/electron-browser/extensionEditor.ts
+1
-1
src/vs/workbench/parts/files/browser/fileActions.ts
src/vs/workbench/parts/files/browser/fileActions.ts
+2
-1
src/vs/workbench/parts/files/browser/views/explorerViewer.ts
src/vs/workbench/parts/files/browser/views/explorerViewer.ts
+2
-1
src/vs/workbench/parts/search/browser/searchActions.ts
src/vs/workbench/parts/search/browser/searchActions.ts
+2
-1
src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts
...bench/parts/terminal/electron-browser/terminalInstance.ts
+1
-1
src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts
...services/keybinding/electron-browser/keybindingService.ts
+1
-1
src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts
...ench/services/keybinding/electron-browser/nativeKeymap.ts
+2
-1
未找到文件。
src/vs/base/browser/ui/dropdown/dropdown.ts
浏览文件 @
81bb89de
...
...
@@ -15,7 +15,7 @@ import {EventEmitter} from 'vs/base/common/eventEmitter';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IContextViewProvider
}
from
'
vs/base/browser/ui/contextview/contextview
'
;
import
{
IMenuOptions
}
from
'
vs/base/browser/ui/menu/menu
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
export
interface
ILabelRenderer
{
(
container
:
HTMLElement
):
IDisposable
;
...
...
src/vs/base/browser/ui/menu/menu.ts
浏览文件 @
81bb89de
...
...
@@ -11,7 +11,7 @@ import {$} from 'vs/base/browser/builder';
import
{
IActionRunner
,
IAction
}
from
'
vs/base/common/actions
'
;
import
{
ActionBar
,
IActionItemProvider
,
ActionsOrientation
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
export
interface
IMenuOptions
{
context
?:
any
;
...
...
src/vs/base/browser/ui/toolbar/toolbar.ts
浏览文件 @
81bb89de
...
...
@@ -14,7 +14,7 @@ import types = require('vs/base/common/types');
import
{
Action
,
IActionRunner
,
IAction
}
from
'
vs/base/common/actions
'
;
import
{
ActionBar
,
ActionsOrientation
,
IActionItemProvider
,
BaseActionItem
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
IContextMenuProvider
,
DropdownMenu
,
IActionProvider
,
ILabelRenderer
,
IDropdownMenuOptions
}
from
'
vs/base/browser/ui/dropdown/dropdown
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
export
const
CONTEXT
=
'
context.toolbar
'
;
...
...
src/vs/base/common/keyCodes.ts
浏览文件 @
81bb89de
...
...
@@ -5,15 +5,6 @@
'
use strict
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
defaultPlatform
from
'
vs/base/common/platform
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
export
interface
ISimplifiedPlatform
{
isMacintosh
:
boolean
;
isWindows
:
boolean
;
}
/**
* Virtual Key Codes, the value does not hold any inherent meaning.
* Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
...
...
@@ -199,11 +190,11 @@ export const enum KeyCode {
MAX_VALUE
}
interface
IReverseMap
{
export
interface
IReverseMap
{
[
str
:
string
]:
KeyCode
;
}
class
Mapping
{
export
class
Mapping
{
_fromKeyCode
:
string
[];
_toKeyCode
:
IReverseMap
;
...
...
@@ -380,7 +371,7 @@ let STRING = createMapping((TO_STRING_MAP) => {
});
let
USER_SETTINGS
=
createMapping
((
TO_USER_SETTINGS_MAP
)
=>
{
export
let
USER_SETTINGS
=
createMapping
((
TO_USER_SETTINGS_MAP
)
=>
{
for
(
let
i
=
0
,
len
=
STRING
.
_fromKeyCode
.
length
;
i
<
len
;
i
++
)
{
TO_USER_SETTINGS_MAP
[
i
]
=
STRING
.
_fromKeyCode
[
i
];
}
...
...
@@ -472,495 +463,3 @@ export class BinaryKeybindings {
return
(
keybinding
&
BinaryKeybindingsMask
.
KeyCode
);
}
}
export
class
Keybinding
{
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toUSLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
(
Platform
.
isMacintosh
?
MacUIKeyLabelProvider
.
INSTANCE
:
ClassicUIKeyLabelProvider
.
INSTANCE
),
Platform
);
}
/**
* Format the binding to a format appropiate for placing in an aria-label.
*/
private
static
_toUSAriaLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
AriaKeyLabelProvider
.
INSTANCE
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toUSHTMLLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
IHTMLContentElement
[]
{
return
_asHTML
(
value
,
(
Platform
.
isMacintosh
?
MacUIKeyLabelProvider
.
INSTANCE
:
ClassicUIKeyLabelProvider
.
INSTANCE
),
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toCustomLabel
(
value
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
labelProvider
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toCustomHTMLLabel
(
value
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
IHTMLContentElement
[]
{
return
_asHTML
(
value
,
labelProvider
,
Platform
);
}
/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
*/
private
static
_toElectronAccelerator
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
if
(
BinaryKeybindings
.
hasChord
(
value
))
{
// Electron cannot handle chords
return
null
;
}
return
_asString
(
value
,
ElectronAcceleratorLabelProvider
.
INSTANCE
,
Platform
);
}
private
static
_cachedKeybindingRegex
:
string
=
null
;
public
static
getUserSettingsKeybindingRegex
():
string
{
if
(
!
this
.
_cachedKeybindingRegex
)
{
let
numpadKey
=
'
numpad(0|1|2|3|4|5|6|7|8|9|_multiply|_add|_subtract|_decimal|_divide|_separator)
'
;
let
oemKey
=
'
`|
\\
-|=|
\\
[|
\\
]|
\\\\\\\\
|;|
\'
|,|
\\
.|
\\
/|oem_8|oem_102
'
;
let
specialKey
=
'
left|up|right|down|pageup|pagedown|end|home|tab|enter|escape|space|backspace|delete|pausebreak|capslock|insert|contextmenu|numlock|scrolllock
'
;
let
casualKey
=
'
[a-z]|[0-9]|f(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19)
'
;
let
key
=
'
((
'
+
[
numpadKey
,
oemKey
,
specialKey
,
casualKey
].
join
(
'
)|(
'
)
+
'
))
'
;
let
mod
=
'
((ctrl|shift|alt|cmd|win|meta)
\\
+)*
'
;
let
keybinding
=
'
(
'
+
mod
+
key
+
'
)
'
;
this
.
_cachedKeybindingRegex
=
'
"
\\
s*(
'
+
keybinding
+
'
(
\\
s+
'
+
keybinding
+
'
)?
'
+
'
)
\\
s*"
'
;
}
return
this
.
_cachedKeybindingRegex
;
}
/**
* Format the binding to a format appropiate for the user settings file.
*/
public
static
toUserSettingsLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
let
result
=
_asString
(
value
,
UserSettingsKeyLabelProvider
.
INSTANCE
,
Platform
);
result
=
result
.
toLowerCase
();
if
(
Platform
.
isMacintosh
)
{
result
=
result
.
replace
(
/meta/g
,
'
cmd
'
);
}
else
if
(
Platform
.
isWindows
)
{
result
=
result
.
replace
(
/meta/g
,
'
win
'
);
}
return
result
;
}
public
static
fromUserSettingsLabel
(
input
:
string
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
number
{
if
(
!
input
)
{
return
null
;
}
input
=
input
.
toLowerCase
().
trim
();
let
ctrlCmd
=
false
,
shift
=
false
,
alt
=
false
,
winCtrl
=
false
,
key
:
string
=
''
;
while
(
/^
(
ctrl|shift|alt|meta|win|cmd
)(\+
|
\-)
/
.
test
(
input
))
{
if
(
/^ctrl
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
winCtrl
=
true
;
}
else
{
ctrlCmd
=
true
;
}
input
=
input
.
substr
(
'
ctrl-
'
.
length
);
}
if
(
/^shift
(\+
|
\-)
/
.
test
(
input
))
{
shift
=
true
;
input
=
input
.
substr
(
'
shift-
'
.
length
);
}
if
(
/^alt
(\+
|
\-)
/
.
test
(
input
))
{
alt
=
true
;
input
=
input
.
substr
(
'
alt-
'
.
length
);
}
if
(
/^meta
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
meta-
'
.
length
);
}
if
(
/^win
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
win-
'
.
length
);
}
if
(
/^cmd
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
cmd-
'
.
length
);
}
}
let
chord
:
number
=
0
;
let
firstSpaceIdx
=
input
.
indexOf
(
'
'
);
if
(
firstSpaceIdx
>
0
)
{
key
=
input
.
substring
(
0
,
firstSpaceIdx
);
chord
=
Keybinding
.
fromUserSettingsLabel
(
input
.
substring
(
firstSpaceIdx
),
Platform
);
}
else
{
key
=
input
;
}
let
keyCode
=
USER_SETTINGS
.
toKeyCode
(
key
);
let
result
=
0
;
if
(
ctrlCmd
)
{
result
|=
KeyMod
.
CtrlCmd
;
}
if
(
shift
)
{
result
|=
KeyMod
.
Shift
;
}
if
(
alt
)
{
result
|=
KeyMod
.
Alt
;
}
if
(
winCtrl
)
{
result
|=
KeyMod
.
WinCtrl
;
}
result
|=
keyCode
;
return
KeyChord
(
result
,
chord
);
}
public
value
:
number
;
constructor
(
keybinding
:
number
)
{
this
.
value
=
keybinding
;
}
public
hasCtrlCmd
():
boolean
{
return
BinaryKeybindings
.
hasCtrlCmd
(
this
.
value
);
}
public
hasShift
():
boolean
{
return
BinaryKeybindings
.
hasShift
(
this
.
value
);
}
public
hasAlt
():
boolean
{
return
BinaryKeybindings
.
hasAlt
(
this
.
value
);
}
public
hasWinCtrl
():
boolean
{
return
BinaryKeybindings
.
hasWinCtrl
(
this
.
value
);
}
public
extractKeyCode
():
KeyCode
{
return
BinaryKeybindings
.
extractKeyCode
(
this
.
value
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
_toUSLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toUSLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for placing in an aria-label.
*/
public
_toUSAriaLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toUSAriaLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
_toUSHTMLLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
IHTMLContentElement
[]
{
return
Keybinding
.
_toUSHTMLLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
toCustomLabel
(
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toCustomLabel
(
this
.
value
,
labelProvider
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
toCustomHTMLLabel
(
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
IHTMLContentElement
[]
{
return
Keybinding
.
_toCustomHTMLLabel
(
this
.
value
,
labelProvider
,
Platform
);
}
/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
*/
public
_toElectronAccelerator
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toElectronAccelerator
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for the user settings file.
*/
public
toUserSettingsLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
toUserSettingsLabel
(
this
.
value
,
Platform
);
}
}
export
interface
IKeyBindingLabelProvider
{
ctrlKeyLabel
:
string
;
shiftKeyLabel
:
string
;
altKeyLabel
:
string
;
cmdKeyLabel
:
string
;
windowsKeyLabel
:
string
;
modifierSeparator
:
string
;
getLabelForKey
(
keyCode
:
KeyCode
):
string
;
}
/**
* Print for Electron
*/
export
class
ElectronAcceleratorLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
ElectronAcceleratorLabelProvider
();
public
ctrlKeyLabel
=
'
Ctrl
'
;
public
shiftKeyLabel
=
'
Shift
'
;
public
altKeyLabel
=
'
Alt
'
;
public
cmdKeyLabel
=
'
Cmd
'
;
public
windowsKeyLabel
=
'
Super
'
;
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
switch
(
keyCode
)
{
case
KeyCode
.
UpArrow
:
return
'
Up
'
;
case
KeyCode
.
DownArrow
:
return
'
Down
'
;
case
KeyCode
.
LeftArrow
:
return
'
Left
'
;
case
KeyCode
.
RightArrow
:
return
'
Right
'
;
}
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for Mac UI
*/
export
class
MacUIKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
MacUIKeyLabelProvider
();
private
static
leftArrowUnicodeLabel
=
String
.
fromCharCode
(
8592
);
private
static
upArrowUnicodeLabel
=
String
.
fromCharCode
(
8593
);
private
static
rightArrowUnicodeLabel
=
String
.
fromCharCode
(
8594
);
private
static
downArrowUnicodeLabel
=
String
.
fromCharCode
(
8595
);
public
ctrlKeyLabel
=
'
\
u2303
'
;
public
shiftKeyLabel
=
'
\
u21E7
'
;
public
altKeyLabel
=
'
\
u2325
'
;
public
cmdKeyLabel
=
'
\
u2318
'
;
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey
'
,
"
Windows
"
);
public
modifierSeparator
=
''
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
switch
(
keyCode
)
{
case
KeyCode
.
LeftArrow
:
return
MacUIKeyLabelProvider
.
leftArrowUnicodeLabel
;
case
KeyCode
.
UpArrow
:
return
MacUIKeyLabelProvider
.
upArrowUnicodeLabel
;
case
KeyCode
.
RightArrow
:
return
MacUIKeyLabelProvider
.
rightArrowUnicodeLabel
;
case
KeyCode
.
DownArrow
:
return
MacUIKeyLabelProvider
.
downArrowUnicodeLabel
;
}
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Aria label provider for Mac.
*/
export
class
AriaKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
MacUIKeyLabelProvider
();
public
ctrlKeyLabel
=
nls
.
localize
(
'
ctrlKey.long
'
,
"
Control
"
);
public
shiftKeyLabel
=
nls
.
localize
(
'
shiftKey.long
'
,
"
Shift
"
);
public
altKeyLabel
=
nls
.
localize
(
'
altKey.long
'
,
"
Alt
"
);
public
cmdKeyLabel
=
nls
.
localize
(
'
cmdKey.long
'
,
"
Command
"
);
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey.long
'
,
"
Windows
"
);
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for Windows, Linux UI
*/
export
class
ClassicUIKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
ClassicUIKeyLabelProvider
();
public
ctrlKeyLabel
=
nls
.
localize
(
'
ctrlKey
'
,
"
Ctrl
"
);
public
shiftKeyLabel
=
nls
.
localize
(
'
shiftKey
'
,
"
Shift
"
);
public
altKeyLabel
=
nls
.
localize
(
'
altKey
'
,
"
Alt
"
);
public
cmdKeyLabel
=
nls
.
localize
(
'
cmdKey
'
,
"
Command
"
);
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey
'
,
"
Windows
"
);
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for the user settings file.
*/
class
UserSettingsKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
UserSettingsKeyLabelProvider
();
public
ctrlKeyLabel
=
'
Ctrl
'
;
public
shiftKeyLabel
=
'
Shift
'
;
public
altKeyLabel
=
'
Alt
'
;
public
cmdKeyLabel
=
'
Meta
'
;
public
windowsKeyLabel
=
'
Meta
'
;
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
USER_SETTINGS
.
fromKeyCode
(
keyCode
);
}
}
function
_asString
(
keybinding
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
string
{
let
result
:
string
[]
=
[],
ctrlCmd
=
BinaryKeybindings
.
hasCtrlCmd
(
keybinding
),
shift
=
BinaryKeybindings
.
hasShift
(
keybinding
),
alt
=
BinaryKeybindings
.
hasAlt
(
keybinding
),
winCtrl
=
BinaryKeybindings
.
hasWinCtrl
(
keybinding
),
keyCode
=
BinaryKeybindings
.
extractKeyCode
(
keybinding
);
let
keyLabel
=
labelProvider
.
getLabelForKey
(
keyCode
);
if
(
!
keyLabel
)
{
// cannot trigger this key code under this kb layout
return
''
;
}
// translate modifier keys: Ctrl-Shift-Alt-Meta
if
((
ctrlCmd
&&
!
Platform
.
isMacintosh
)
||
(
winCtrl
&&
Platform
.
isMacintosh
))
{
result
.
push
(
labelProvider
.
ctrlKeyLabel
);
}
if
(
shift
)
{
result
.
push
(
labelProvider
.
shiftKeyLabel
);
}
if
(
alt
)
{
result
.
push
(
labelProvider
.
altKeyLabel
);
}
if
(
ctrlCmd
&&
Platform
.
isMacintosh
)
{
result
.
push
(
labelProvider
.
cmdKeyLabel
);
}
if
(
winCtrl
&&
!
Platform
.
isMacintosh
)
{
result
.
push
(
labelProvider
.
windowsKeyLabel
);
}
// the actual key
result
.
push
(
keyLabel
);
var
actualResult
=
result
.
join
(
labelProvider
.
modifierSeparator
);
if
(
BinaryKeybindings
.
hasChord
(
keybinding
))
{
return
actualResult
+
'
'
+
_asString
(
BinaryKeybindings
.
extractChordPart
(
keybinding
),
labelProvider
,
Platform
);
}
return
actualResult
;
}
function
_pushKey
(
result
:
IHTMLContentElement
[],
str
:
string
):
void
{
if
(
result
.
length
>
0
)
{
result
.
push
({
tagName
:
'
span
'
,
text
:
'
+
'
});
}
result
.
push
({
tagName
:
'
span
'
,
className
:
'
monaco-kbkey
'
,
text
:
str
});
}
function
_asHTML
(
keybinding
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
,
isChord
:
boolean
=
false
):
IHTMLContentElement
[]
{
let
result
:
IHTMLContentElement
[]
=
[],
ctrlCmd
=
BinaryKeybindings
.
hasCtrlCmd
(
keybinding
),
shift
=
BinaryKeybindings
.
hasShift
(
keybinding
),
alt
=
BinaryKeybindings
.
hasAlt
(
keybinding
),
winCtrl
=
BinaryKeybindings
.
hasWinCtrl
(
keybinding
),
keyCode
=
BinaryKeybindings
.
extractKeyCode
(
keybinding
);
let
keyLabel
=
labelProvider
.
getLabelForKey
(
keyCode
);
if
(
!
keyLabel
)
{
// cannot trigger this key code under this kb layout
return
[];
}
// translate modifier keys: Ctrl-Shift-Alt-Meta
if
((
ctrlCmd
&&
!
Platform
.
isMacintosh
)
||
(
winCtrl
&&
Platform
.
isMacintosh
))
{
_pushKey
(
result
,
labelProvider
.
ctrlKeyLabel
);
}
if
(
shift
)
{
_pushKey
(
result
,
labelProvider
.
shiftKeyLabel
);
}
if
(
alt
)
{
_pushKey
(
result
,
labelProvider
.
altKeyLabel
);
}
if
(
ctrlCmd
&&
Platform
.
isMacintosh
)
{
_pushKey
(
result
,
labelProvider
.
cmdKeyLabel
);
}
if
(
winCtrl
&&
!
Platform
.
isMacintosh
)
{
_pushKey
(
result
,
labelProvider
.
windowsKeyLabel
);
}
// the actual key
_pushKey
(
result
,
keyLabel
);
let
chordTo
:
IHTMLContentElement
[]
=
null
;
if
(
BinaryKeybindings
.
hasChord
(
keybinding
))
{
chordTo
=
_asHTML
(
BinaryKeybindings
.
extractChordPart
(
keybinding
),
labelProvider
,
Platform
,
true
);
result
.
push
({
tagName
:
'
span
'
,
text
:
'
'
});
result
=
result
.
concat
(
chordTo
);
}
if
(
isChord
)
{
return
result
;
}
return
[{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
result
}];
}
src/vs/base/common/keybinding.ts
0 → 100644
浏览文件 @
81bb89de
/*---------------------------------------------------------------------------------------------
* 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
nls
from
'
vs/nls
'
;
import
*
as
defaultPlatform
from
'
vs/base/common/platform
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
,
KeyCodeUtils
,
BinaryKeybindings
,
USER_SETTINGS
}
from
'
vs/base/common/keyCodes
'
;
export
interface
ISimplifiedPlatform
{
isMacintosh
:
boolean
;
isWindows
:
boolean
;
}
export
class
Keybinding
{
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toUSLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
(
Platform
.
isMacintosh
?
MacUIKeyLabelProvider
.
INSTANCE
:
ClassicUIKeyLabelProvider
.
INSTANCE
),
Platform
);
}
/**
* Format the binding to a format appropiate for placing in an aria-label.
*/
private
static
_toUSAriaLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
AriaKeyLabelProvider
.
INSTANCE
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toUSHTMLLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
IHTMLContentElement
[]
{
return
_asHTML
(
value
,
(
Platform
.
isMacintosh
?
MacUIKeyLabelProvider
.
INSTANCE
:
ClassicUIKeyLabelProvider
.
INSTANCE
),
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toCustomLabel
(
value
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
string
{
return
_asString
(
value
,
labelProvider
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
private
static
_toCustomHTMLLabel
(
value
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
IHTMLContentElement
[]
{
return
_asHTML
(
value
,
labelProvider
,
Platform
);
}
/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
*/
private
static
_toElectronAccelerator
(
value
:
number
,
Platform
:
ISimplifiedPlatform
):
string
{
if
(
BinaryKeybindings
.
hasChord
(
value
))
{
// Electron cannot handle chords
return
null
;
}
return
_asString
(
value
,
ElectronAcceleratorLabelProvider
.
INSTANCE
,
Platform
);
}
private
static
_cachedKeybindingRegex
:
string
=
null
;
public
static
getUserSettingsKeybindingRegex
():
string
{
if
(
!
this
.
_cachedKeybindingRegex
)
{
let
numpadKey
=
'
numpad(0|1|2|3|4|5|6|7|8|9|_multiply|_add|_subtract|_decimal|_divide|_separator)
'
;
let
oemKey
=
'
`|
\\
-|=|
\\
[|
\\
]|
\\\\\\\\
|;|
\'
|,|
\\
.|
\\
/|oem_8|oem_102
'
;
let
specialKey
=
'
left|up|right|down|pageup|pagedown|end|home|tab|enter|escape|space|backspace|delete|pausebreak|capslock|insert|contextmenu|numlock|scrolllock
'
;
let
casualKey
=
'
[a-z]|[0-9]|f(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19)
'
;
let
key
=
'
((
'
+
[
numpadKey
,
oemKey
,
specialKey
,
casualKey
].
join
(
'
)|(
'
)
+
'
))
'
;
let
mod
=
'
((ctrl|shift|alt|cmd|win|meta)
\\
+)*
'
;
let
keybinding
=
'
(
'
+
mod
+
key
+
'
)
'
;
this
.
_cachedKeybindingRegex
=
'
"
\\
s*(
'
+
keybinding
+
'
(
\\
s+
'
+
keybinding
+
'
)?
'
+
'
)
\\
s*"
'
;
}
return
this
.
_cachedKeybindingRegex
;
}
/**
* Format the binding to a format appropiate for the user settings file.
*/
public
static
toUserSettingsLabel
(
value
:
number
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
let
result
=
_asString
(
value
,
UserSettingsKeyLabelProvider
.
INSTANCE
,
Platform
);
result
=
result
.
toLowerCase
();
if
(
Platform
.
isMacintosh
)
{
result
=
result
.
replace
(
/meta/g
,
'
cmd
'
);
}
else
if
(
Platform
.
isWindows
)
{
result
=
result
.
replace
(
/meta/g
,
'
win
'
);
}
return
result
;
}
public
static
fromUserSettingsLabel
(
input
:
string
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
number
{
if
(
!
input
)
{
return
null
;
}
input
=
input
.
toLowerCase
().
trim
();
let
ctrlCmd
=
false
,
shift
=
false
,
alt
=
false
,
winCtrl
=
false
,
key
:
string
=
''
;
while
(
/^
(
ctrl|shift|alt|meta|win|cmd
)(\+
|
\-)
/
.
test
(
input
))
{
if
(
/^ctrl
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
winCtrl
=
true
;
}
else
{
ctrlCmd
=
true
;
}
input
=
input
.
substr
(
'
ctrl-
'
.
length
);
}
if
(
/^shift
(\+
|
\-)
/
.
test
(
input
))
{
shift
=
true
;
input
=
input
.
substr
(
'
shift-
'
.
length
);
}
if
(
/^alt
(\+
|
\-)
/
.
test
(
input
))
{
alt
=
true
;
input
=
input
.
substr
(
'
alt-
'
.
length
);
}
if
(
/^meta
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
meta-
'
.
length
);
}
if
(
/^win
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
win-
'
.
length
);
}
if
(
/^cmd
(\+
|
\-)
/
.
test
(
input
))
{
if
(
Platform
.
isMacintosh
)
{
ctrlCmd
=
true
;
}
else
{
winCtrl
=
true
;
}
input
=
input
.
substr
(
'
cmd-
'
.
length
);
}
}
let
chord
:
number
=
0
;
let
firstSpaceIdx
=
input
.
indexOf
(
'
'
);
if
(
firstSpaceIdx
>
0
)
{
key
=
input
.
substring
(
0
,
firstSpaceIdx
);
chord
=
Keybinding
.
fromUserSettingsLabel
(
input
.
substring
(
firstSpaceIdx
),
Platform
);
}
else
{
key
=
input
;
}
let
keyCode
=
USER_SETTINGS
.
toKeyCode
(
key
);
let
result
=
0
;
if
(
ctrlCmd
)
{
result
|=
KeyMod
.
CtrlCmd
;
}
if
(
shift
)
{
result
|=
KeyMod
.
Shift
;
}
if
(
alt
)
{
result
|=
KeyMod
.
Alt
;
}
if
(
winCtrl
)
{
result
|=
KeyMod
.
WinCtrl
;
}
result
|=
keyCode
;
return
KeyChord
(
result
,
chord
);
}
public
value
:
number
;
constructor
(
keybinding
:
number
)
{
this
.
value
=
keybinding
;
}
public
hasCtrlCmd
():
boolean
{
return
BinaryKeybindings
.
hasCtrlCmd
(
this
.
value
);
}
public
hasShift
():
boolean
{
return
BinaryKeybindings
.
hasShift
(
this
.
value
);
}
public
hasAlt
():
boolean
{
return
BinaryKeybindings
.
hasAlt
(
this
.
value
);
}
public
hasWinCtrl
():
boolean
{
return
BinaryKeybindings
.
hasWinCtrl
(
this
.
value
);
}
public
extractKeyCode
():
KeyCode
{
return
BinaryKeybindings
.
extractKeyCode
(
this
.
value
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
_toUSLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toUSLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for placing in an aria-label.
*/
public
_toUSAriaLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toUSAriaLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
_toUSHTMLLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
IHTMLContentElement
[]
{
return
Keybinding
.
_toUSHTMLLabel
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
toCustomLabel
(
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toCustomLabel
(
this
.
value
,
labelProvider
,
Platform
);
}
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public
toCustomHTMLLabel
(
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
IHTMLContentElement
[]
{
return
Keybinding
.
_toCustomHTMLLabel
(
this
.
value
,
labelProvider
,
Platform
);
}
/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
*/
public
_toElectronAccelerator
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
_toElectronAccelerator
(
this
.
value
,
Platform
);
}
/**
* Format the binding to a format appropiate for the user settings file.
*/
public
toUserSettingsLabel
(
Platform
:
ISimplifiedPlatform
=
defaultPlatform
):
string
{
return
Keybinding
.
toUserSettingsLabel
(
this
.
value
,
Platform
);
}
}
export
interface
IKeyBindingLabelProvider
{
ctrlKeyLabel
:
string
;
shiftKeyLabel
:
string
;
altKeyLabel
:
string
;
cmdKeyLabel
:
string
;
windowsKeyLabel
:
string
;
modifierSeparator
:
string
;
getLabelForKey
(
keyCode
:
KeyCode
):
string
;
}
/**
* Print for Electron
*/
export
class
ElectronAcceleratorLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
ElectronAcceleratorLabelProvider
();
public
ctrlKeyLabel
=
'
Ctrl
'
;
public
shiftKeyLabel
=
'
Shift
'
;
public
altKeyLabel
=
'
Alt
'
;
public
cmdKeyLabel
=
'
Cmd
'
;
public
windowsKeyLabel
=
'
Super
'
;
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
switch
(
keyCode
)
{
case
KeyCode
.
UpArrow
:
return
'
Up
'
;
case
KeyCode
.
DownArrow
:
return
'
Down
'
;
case
KeyCode
.
LeftArrow
:
return
'
Left
'
;
case
KeyCode
.
RightArrow
:
return
'
Right
'
;
}
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for Mac UI
*/
export
class
MacUIKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
MacUIKeyLabelProvider
();
private
static
leftArrowUnicodeLabel
=
String
.
fromCharCode
(
8592
);
private
static
upArrowUnicodeLabel
=
String
.
fromCharCode
(
8593
);
private
static
rightArrowUnicodeLabel
=
String
.
fromCharCode
(
8594
);
private
static
downArrowUnicodeLabel
=
String
.
fromCharCode
(
8595
);
public
ctrlKeyLabel
=
'
\
u2303
'
;
public
shiftKeyLabel
=
'
\
u21E7
'
;
public
altKeyLabel
=
'
\
u2325
'
;
public
cmdKeyLabel
=
'
\
u2318
'
;
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey
'
,
"
Windows
"
);
public
modifierSeparator
=
''
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
switch
(
keyCode
)
{
case
KeyCode
.
LeftArrow
:
return
MacUIKeyLabelProvider
.
leftArrowUnicodeLabel
;
case
KeyCode
.
UpArrow
:
return
MacUIKeyLabelProvider
.
upArrowUnicodeLabel
;
case
KeyCode
.
RightArrow
:
return
MacUIKeyLabelProvider
.
rightArrowUnicodeLabel
;
case
KeyCode
.
DownArrow
:
return
MacUIKeyLabelProvider
.
downArrowUnicodeLabel
;
}
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Aria label provider for Mac.
*/
export
class
AriaKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
MacUIKeyLabelProvider
();
public
ctrlKeyLabel
=
nls
.
localize
(
'
ctrlKey.long
'
,
"
Control
"
);
public
shiftKeyLabel
=
nls
.
localize
(
'
shiftKey.long
'
,
"
Shift
"
);
public
altKeyLabel
=
nls
.
localize
(
'
altKey.long
'
,
"
Alt
"
);
public
cmdKeyLabel
=
nls
.
localize
(
'
cmdKey.long
'
,
"
Command
"
);
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey.long
'
,
"
Windows
"
);
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for Windows, Linux UI
*/
export
class
ClassicUIKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
ClassicUIKeyLabelProvider
();
public
ctrlKeyLabel
=
nls
.
localize
(
'
ctrlKey
'
,
"
Ctrl
"
);
public
shiftKeyLabel
=
nls
.
localize
(
'
shiftKey
'
,
"
Shift
"
);
public
altKeyLabel
=
nls
.
localize
(
'
altKey
'
,
"
Alt
"
);
public
cmdKeyLabel
=
nls
.
localize
(
'
cmdKey
'
,
"
Command
"
);
public
windowsKeyLabel
=
nls
.
localize
(
'
windowsKey
'
,
"
Windows
"
);
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
KeyCodeUtils
.
toString
(
keyCode
);
}
}
/**
* Print for the user settings file.
*/
class
UserSettingsKeyLabelProvider
implements
IKeyBindingLabelProvider
{
public
static
INSTANCE
=
new
UserSettingsKeyLabelProvider
();
public
ctrlKeyLabel
=
'
Ctrl
'
;
public
shiftKeyLabel
=
'
Shift
'
;
public
altKeyLabel
=
'
Alt
'
;
public
cmdKeyLabel
=
'
Meta
'
;
public
windowsKeyLabel
=
'
Meta
'
;
public
modifierSeparator
=
'
+
'
;
public
getLabelForKey
(
keyCode
:
KeyCode
):
string
{
return
USER_SETTINGS
.
fromKeyCode
(
keyCode
);
}
}
function
_asString
(
keybinding
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
):
string
{
let
result
:
string
[]
=
[],
ctrlCmd
=
BinaryKeybindings
.
hasCtrlCmd
(
keybinding
),
shift
=
BinaryKeybindings
.
hasShift
(
keybinding
),
alt
=
BinaryKeybindings
.
hasAlt
(
keybinding
),
winCtrl
=
BinaryKeybindings
.
hasWinCtrl
(
keybinding
),
keyCode
=
BinaryKeybindings
.
extractKeyCode
(
keybinding
);
let
keyLabel
=
labelProvider
.
getLabelForKey
(
keyCode
);
if
(
!
keyLabel
)
{
// cannot trigger this key code under this kb layout
return
''
;
}
// translate modifier keys: Ctrl-Shift-Alt-Meta
if
((
ctrlCmd
&&
!
Platform
.
isMacintosh
)
||
(
winCtrl
&&
Platform
.
isMacintosh
))
{
result
.
push
(
labelProvider
.
ctrlKeyLabel
);
}
if
(
shift
)
{
result
.
push
(
labelProvider
.
shiftKeyLabel
);
}
if
(
alt
)
{
result
.
push
(
labelProvider
.
altKeyLabel
);
}
if
(
ctrlCmd
&&
Platform
.
isMacintosh
)
{
result
.
push
(
labelProvider
.
cmdKeyLabel
);
}
if
(
winCtrl
&&
!
Platform
.
isMacintosh
)
{
result
.
push
(
labelProvider
.
windowsKeyLabel
);
}
// the actual key
result
.
push
(
keyLabel
);
var
actualResult
=
result
.
join
(
labelProvider
.
modifierSeparator
);
if
(
BinaryKeybindings
.
hasChord
(
keybinding
))
{
return
actualResult
+
'
'
+
_asString
(
BinaryKeybindings
.
extractChordPart
(
keybinding
),
labelProvider
,
Platform
);
}
return
actualResult
;
}
function
_pushKey
(
result
:
IHTMLContentElement
[],
str
:
string
):
void
{
if
(
result
.
length
>
0
)
{
result
.
push
({
tagName
:
'
span
'
,
text
:
'
+
'
});
}
result
.
push
({
tagName
:
'
span
'
,
className
:
'
monaco-kbkey
'
,
text
:
str
});
}
function
_asHTML
(
keybinding
:
number
,
labelProvider
:
IKeyBindingLabelProvider
,
Platform
:
ISimplifiedPlatform
,
isChord
:
boolean
=
false
):
IHTMLContentElement
[]
{
let
result
:
IHTMLContentElement
[]
=
[],
ctrlCmd
=
BinaryKeybindings
.
hasCtrlCmd
(
keybinding
),
shift
=
BinaryKeybindings
.
hasShift
(
keybinding
),
alt
=
BinaryKeybindings
.
hasAlt
(
keybinding
),
winCtrl
=
BinaryKeybindings
.
hasWinCtrl
(
keybinding
),
keyCode
=
BinaryKeybindings
.
extractKeyCode
(
keybinding
);
let
keyLabel
=
labelProvider
.
getLabelForKey
(
keyCode
);
if
(
!
keyLabel
)
{
// cannot trigger this key code under this kb layout
return
[];
}
// translate modifier keys: Ctrl-Shift-Alt-Meta
if
((
ctrlCmd
&&
!
Platform
.
isMacintosh
)
||
(
winCtrl
&&
Platform
.
isMacintosh
))
{
_pushKey
(
result
,
labelProvider
.
ctrlKeyLabel
);
}
if
(
shift
)
{
_pushKey
(
result
,
labelProvider
.
shiftKeyLabel
);
}
if
(
alt
)
{
_pushKey
(
result
,
labelProvider
.
altKeyLabel
);
}
if
(
ctrlCmd
&&
Platform
.
isMacintosh
)
{
_pushKey
(
result
,
labelProvider
.
cmdKeyLabel
);
}
if
(
winCtrl
&&
!
Platform
.
isMacintosh
)
{
_pushKey
(
result
,
labelProvider
.
windowsKeyLabel
);
}
// the actual key
_pushKey
(
result
,
keyLabel
);
let
chordTo
:
IHTMLContentElement
[]
=
null
;
if
(
BinaryKeybindings
.
hasChord
(
keybinding
))
{
chordTo
=
_asHTML
(
BinaryKeybindings
.
extractChordPart
(
keybinding
),
labelProvider
,
Platform
,
true
);
result
.
push
({
tagName
:
'
span
'
,
text
:
'
'
});
result
=
result
.
concat
(
chordTo
);
}
if
(
isChord
)
{
return
result
;
}
return
[{
tagName
:
'
span
'
,
className
:
'
monaco-kb
'
,
children
:
result
}];
}
src/vs/base/parts/quickopen/common/quickOpen.ts
浏览文件 @
81bb89de
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
export
interface
IQuickNavigateConfiguration
{
keybindings
:
Keybinding
[];
...
...
src/vs/code/electron-main/menus.ts
浏览文件 @
81bb89de
...
...
@@ -15,7 +15,7 @@ import { IWindowsService } from 'vs/code/electron-main/windows';
import
{
IPath
,
VSCodeWindow
}
from
'
vs/code/electron-main/window
'
;
import
{
IStorageService
}
from
'
vs/code/electron-main/storage
'
;
import
{
IUpdateService
,
State
as
UpdateState
}
from
'
vs/code/electron-main/update-manager
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
product
from
'
vs/platform/product
'
;
import
pkg
from
'
vs/platform/package
'
;
...
...
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
浏览文件 @
81bb89de
...
...
@@ -6,7 +6,8 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
{
KeyCode
,
KeyMod
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
*
as
dom
from
'
vs/base/browser/dom
'
;
...
...
src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts
浏览文件 @
81bb89de
...
...
@@ -9,7 +9,8 @@ import 'vs/css!./defineKeybinding';
import
*
as
nls
from
'
vs/nls
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
MarkedString
}
from
'
vs/base/common/htmlContent
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
dom
from
'
vs/base/browser/dom
'
;
import
{
renderHtml
}
from
'
vs/base/browser/htmlContentRenderer
'
;
...
...
src/vs/editor/test/common/standalone/standaloneBase.test.ts
浏览文件 @
81bb89de
...
...
@@ -7,7 +7,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
KeyCode
as
StandaloneKeyCode
}
from
'
vs/editor/common/standalone/standaloneBase
'
;
import
{
KeyCode
as
RuntimeKeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
/*KeyCode, KeyMod, BinaryKeybindings,*/
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
suite
(
'
KeyCode
'
,
()
=>
{
test
(
'
is exported correctly in standalone editor
'
,
()
=>
{
...
...
src/vs/platform/contextview/browser/contextView.ts
浏览文件 @
81bb89de
...
...
@@ -8,7 +8,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
{
IActionItem
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
export
const
IContextViewService
=
createDecorator
<
IContextViewService
>
(
'
contextViewService
'
);
...
...
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
浏览文件 @
81bb89de
...
...
@@ -7,7 +7,8 @@
import
'
vs/css!./keybindings
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
KeyCode
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
...
...
src/vs/platform/keybinding/common/keybinding.ts
浏览文件 @
81bb89de
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
src/vs/platform/keybinding/common/keybindingResolver.ts
浏览文件 @
81bb89de
...
...
@@ -4,7 +4,8 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
BinaryKeybindings
,
ISimplifiedPlatform
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
BinaryKeybindings
}
from
'
vs/base/common/keyCodes
'
;
import
{
ISimplifiedPlatform
,
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
{
IKeybindingItem
,
IUserFriendlyKeybinding
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
src/vs/platform/keybinding/test/common/keybindingIO.test.ts
浏览文件 @
81bb89de
...
...
@@ -5,9 +5,10 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
ISimplifiedPlatform
,
KeyCode
,
KeyMod
,
KeyChord
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
}
from
'
vs/base/common/keyCodes
'
;
import
{
NormalizedKeybindingItem
,
IOSupport
}
from
'
vs/platform/keybinding/common/keybindingResolver
'
;
import
{
IUserFriendlyKeybinding
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
ISimplifiedPlatform
}
from
'
vs/base/common/keybinding
'
;
suite
(
'
Keybinding IO
'
,
()
=>
{
...
...
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
浏览文件 @
81bb89de
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
Event
from
'
vs/base/common/event
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
IContextKey
,
IContextKeyService
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts
浏览文件 @
81bb89de
...
...
@@ -38,7 +38,7 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import
{
CombinedInstallAction
,
UpdateAction
,
EnableAction
}
from
'
./extensionsActions
'
;
import
WebView
from
'
vs/workbench/parts/html/browser/webview
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
DomScrollableElement
}
from
'
vs/base/browser/ui/scrollbar/scrollableElement
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
...
...
src/vs/workbench/parts/files/browser/fileActions.ts
浏览文件 @
81bb89de
...
...
@@ -45,7 +45,8 @@ import {IEventService} from 'vs/platform/event/common/event';
import
{
IInstantiationService
,
IConstructorSignature2
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IMessageService
,
IMessageWithAction
,
IConfirmation
,
Severity
,
CancelAction
}
from
'
vs/platform/message/common/message
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
KeyMod
,
KeyCode
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyMod
,
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
export
interface
IEditableData
{
...
...
src/vs/workbench/parts/files/browser/views/explorerViewer.ts
浏览文件 @
81bb89de
...
...
@@ -46,7 +46,8 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import
{
IMessageService
,
IConfirmation
,
Severity
}
from
'
vs/platform/message/common/message
'
;
import
{
IProgressService
}
from
'
vs/platform/progress/common/progress
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
KeyCode
,
KeyMod
,
Keybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
IMenuService
,
IMenu
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
fillInActions
}
from
'
vs/platform/actions/browser/menuItemActionItem
'
;
...
...
src/vs/workbench/parts/search/browser/searchActions.ts
浏览文件 @
81bb89de
...
...
@@ -22,7 +22,8 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import
{
OpenGlobalSettingsAction
}
from
'
vs/workbench/browser/actions/openSettings
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
Keybinding
,
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
Keybinding
}
from
'
vs/base/common/keybinding
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
asFileEditorInput
}
from
'
vs/workbench/common/editor
'
;
...
...
src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts
浏览文件 @
81bb89de
...
...
@@ -20,7 +20,7 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
import
{
IStringDictionary
}
from
'
vs/base/common/collections
'
;
import
{
ITerminalInstance
}
from
'
vs/workbench/parts/terminal/electron-browser/terminal
'
;
import
{
IWorkspace
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
{
StandardKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
TabFocus
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
TerminalConfigHelper
,
IShell
}
from
'
vs/workbench/parts/terminal/electron-browser/terminalConfigHelper
'
;
...
...
src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts
浏览文件 @
81bb89de
...
...
@@ -7,7 +7,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
import
{
IJSONSchema
}
from
'
vs/base/common/jsonSchema
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
Codes
'
;
import
{
Keybinding
}
from
'
vs/base/common/key
binding
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
{
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
...
...
src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts
浏览文件 @
81bb89de
...
...
@@ -5,7 +5,8 @@
'
use strict
'
;
import
*
as
nativeKeymap
from
'
native-keymap
'
;
import
{
KeyCode
,
KeyCodeUtils
,
IKeyBindingLabelProvider
,
MacUIKeyLabelProvider
,
ClassicUIKeyLabelProvider
,
AriaKeyLabelProvider
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeyCode
,
KeyCodeUtils
}
from
'
vs/base/common/keyCodes
'
;
import
{
IKeyBindingLabelProvider
,
MacUIKeyLabelProvider
,
ClassicUIKeyLabelProvider
,
AriaKeyLabelProvider
}
from
'
vs/base/common/keybinding
'
;
import
{
lookupKeyCode
,
setExtractKeyCode
}
from
'
vs/base/browser/keyboardEvent
'
;
import
Platform
=
require
(
'
vs/base/common/platform
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录