Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b1f31342
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,发现更多精彩内容 >>
提交
b1f31342
编写于
3月 20, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'context-type'
上级
acb5677c
4e2d923e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
73 addition
and
74 deletion
+73
-74
src/vs/platform/contextkey/browser/contextKeyService.ts
src/vs/platform/contextkey/browser/contextKeyService.ts
+15
-26
src/vs/platform/contextkey/common/contextkey.ts
src/vs/platform/contextkey/common/contextkey.ts
+15
-11
src/vs/platform/contextkey/test/common/contextkey.test.ts
src/vs/platform/contextkey/test/common/contextkey.test.ts
+4
-2
src/vs/platform/keybinding/common/abstractKeybindingService.ts
...s/platform/keybinding/common/abstractKeybindingService.ts
+2
-2
src/vs/platform/keybinding/common/keybindingResolver.ts
src/vs/platform/keybinding/common/keybindingResolver.ts
+4
-4
src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts
.../keybinding/test/common/abstractKeybindingService.test.ts
+15
-13
src/vs/platform/keybinding/test/common/keybindingResolver.test.ts
...latform/keybinding/test/common/keybindingResolver.test.ts
+17
-15
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
.../platform/keybinding/test/common/mockKeybindingService.ts
+1
-1
未找到文件。
src/vs/platform/contextkey/browser/contextKeyService.ts
浏览文件 @
b1f31342
...
...
@@ -7,18 +7,19 @@
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
KeybindingResolver
}
from
'
vs/platform/keybinding/common/keybindingResolver
'
;
import
{
IContextKey
,
IContextKeyServiceTarget
,
IContextKeyService
,
SET_CONTEXT_COMMAND_ID
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IContextKey
,
IContext
,
IContext
KeyServiceTarget
,
IContextKeyService
,
SET_CONTEXT_COMMAND_ID
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
Event
,
{
Emitter
,
debounceEvent
}
from
'
vs/base/common/event
'
;
const
KEYBINDING_CONTEXT_ATTR
=
'
data-keybinding-context
'
;
export
class
ContextValuesContainer
{
protected
_parent
:
ContextValuesContainer
;
export
class
Context
implements
IContext
{
protected
_parent
:
Context
;
protected
_value
:
{
[
key
:
string
]:
any
;
};
protected
_id
:
number
;
constructor
(
id
:
number
,
parent
:
Context
ValuesContainer
)
{
constructor
(
id
:
number
,
parent
:
Context
)
{
this
.
_id
=
id
;
this
.
_parent
=
parent
;
this
.
_value
=
Object
.
create
(
null
);
...
...
@@ -46,18 +47,9 @@ export class ContextValuesContainer {
}
return
ret
;
}
public
fillInContext
(
bucket
:
any
):
void
{
if
(
this
.
_parent
)
{
this
.
_parent
.
fillInContext
(
bucket
);
}
for
(
let
key
in
this
.
_value
)
{
bucket
[
key
]
=
this
.
_value
[
key
];
}
}
}
class
ConfigAwareContextValuesContainer
extends
Context
ValuesContainer
{
class
ConfigAwareContextValuesContainer
extends
Context
{
private
_emitter
:
Emitter
<
string
>
;
private
_subscription
:
IDisposable
;
...
...
@@ -169,9 +161,8 @@ export abstract class AbstractContextKeyService {
}
public
contextMatchesRules
(
rules
:
ContextKeyExpr
):
boolean
{
const
ctx
=
Object
.
create
(
null
);
this
.
getContextValuesContainer
(
this
.
_myContextId
).
fillInContext
(
ctx
);
const
result
=
KeybindingResolver
.
contextMatchesRules
(
ctx
,
rules
);
const
context
=
this
.
getContextValuesContainer
(
this
.
_myContextId
);
const
result
=
KeybindingResolver
.
contextMatchesRules
(
context
,
rules
);
// console.group(rules.serialize() + ' -> ' + result);
// rules.keys().forEach(key => { console.log(key, ctx[key]); });
// console.groupEnd();
...
...
@@ -194,13 +185,11 @@ export abstract class AbstractContextKeyService {
}
}
public
getContextValue
(
target
:
IContextKeyServiceTarget
):
any
{
let
res
=
Object
.
create
(
null
);
this
.
getContextValuesContainer
(
findContextAttr
(
target
)).
fillInContext
(
res
);
return
res
;
public
getContext
(
target
:
IContextKeyServiceTarget
):
IContext
{
return
this
.
getContextValuesContainer
(
findContextAttr
(
target
));
}
public
abstract
getContextValuesContainer
(
contextId
:
number
):
Context
ValuesContainer
;
public
abstract
getContextValuesContainer
(
contextId
:
number
):
Context
;
public
abstract
createChildContext
(
parentContextId
?:
number
):
number
;
public
abstract
disposeContext
(
contextId
:
number
):
void
;
}
...
...
@@ -209,7 +198,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
private
_lastContextId
:
number
;
private
_contexts
:
{
[
contextId
:
string
]:
Context
ValuesContainer
;
[
contextId
:
string
]:
Context
;
};
private
_toDispose
:
IDisposable
[]
=
[];
...
...
@@ -239,13 +228,13 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
this
.
_toDispose
=
dispose
(
this
.
_toDispose
);
}
public
getContextValuesContainer
(
contextId
:
number
):
Context
ValuesContainer
{
public
getContextValuesContainer
(
contextId
:
number
):
Context
{
return
this
.
_contexts
[
String
(
contextId
)];
}
public
createChildContext
(
parentContextId
:
number
=
this
.
_myContextId
):
number
{
let
id
=
(
++
this
.
_lastContextId
);
this
.
_contexts
[
String
(
id
)]
=
new
Context
ValuesContainer
(
id
,
this
.
getContextValuesContainer
(
parentContextId
));
this
.
_contexts
[
String
(
id
)]
=
new
Context
(
id
,
this
.
getContextValuesContainer
(
parentContextId
));
return
id
;
}
...
...
@@ -281,7 +270,7 @@ class ScopedContextKeyService extends AbstractContextKeyService {
return
this
.
_parent
.
onDidChangeContext
;
}
public
getContextValuesContainer
(
contextId
:
number
):
Context
ValuesContainer
{
public
getContextValuesContainer
(
contextId
:
number
):
Context
{
return
this
.
_parent
.
getContextValuesContainer
(
contextId
);
}
...
...
src/vs/platform/contextkey/common/contextkey.ts
浏览文件 @
b1f31342
...
...
@@ -88,7 +88,7 @@ export abstract class ContextKeyExpr {
public
abstract
getType
():
ContextKeyExprType
;
public
abstract
equals
(
other
:
ContextKeyExpr
):
boolean
;
public
abstract
evaluate
(
context
:
any
):
boolean
;
public
abstract
evaluate
(
context
:
IContext
):
boolean
;
public
abstract
normalize
():
ContextKeyExpr
;
public
abstract
serialize
():
string
;
public
abstract
keys
():
string
[];
...
...
@@ -139,8 +139,8 @@ export class ContextKeyDefinedExpr implements ContextKeyExpr {
return
false
;
}
public
evaluate
(
context
:
any
):
boolean
{
return
(
!!
context
[
this
.
key
]
);
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
!!
context
.
getValue
(
this
.
key
)
);
}
public
normalize
():
ContextKeyExpr
{
...
...
@@ -187,10 +187,10 @@ export class ContextKeyEqualsExpr implements ContextKeyExpr {
return
false
;
}
public
evaluate
(
context
:
any
):
boolean
{
public
evaluate
(
context
:
IContext
):
boolean
{
/* tslint:disable:triple-equals */
// Intentional ==
return
(
context
[
this
.
key
]
==
this
.
value
);
return
(
context
.
getValue
(
this
.
key
)
==
this
.
value
);
/* tslint:enable:triple-equals */
}
...
...
@@ -248,10 +248,10 @@ export class ContextKeyNotEqualsExpr implements ContextKeyExpr {
return
false
;
}
public
evaluate
(
context
:
any
):
boolean
{
public
evaluate
(
context
:
IContext
):
boolean
{
/* tslint:disable:triple-equals */
// Intentional !=
return
(
context
[
this
.
key
]
!=
this
.
value
);
return
(
context
.
getValue
(
this
.
key
)
!=
this
.
value
);
/* tslint:enable:triple-equals */
}
...
...
@@ -303,8 +303,8 @@ export class ContextKeyNotExpr implements ContextKeyExpr {
return
false
;
}
public
evaluate
(
context
:
any
):
boolean
{
return
(
!
context
[
this
.
key
]
);
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
!
context
.
getValue
(
this
.
key
)
);
}
public
normalize
():
ContextKeyExpr
{
...
...
@@ -346,7 +346,7 @@ export class ContextKeyAndExpr implements ContextKeyExpr {
return
false
;
}
public
evaluate
(
context
:
any
):
boolean
{
public
evaluate
(
context
:
IContext
):
boolean
{
for
(
let
i
=
0
,
len
=
this
.
expr
.
length
;
i
<
len
;
i
++
)
{
if
(
!
this
.
expr
[
i
].
evaluate
(
context
))
{
return
false
;
...
...
@@ -441,6 +441,10 @@ export class RawContextKey<T> extends ContextKeyDefinedExpr {
}
}
export
interface
IContext
{
getValue
<
T
>
(
key
:
string
):
T
;
}
export
interface
IContextKey
<
T
>
{
set
(
value
:
T
):
void
;
reset
():
void
;
...
...
@@ -467,7 +471,7 @@ export interface IContextKeyService {
getContextKeyValue
<
T
>
(
key
:
string
):
T
;
createScoped
(
target
?:
IContextKeyServiceTarget
):
IContextKeyService
;
getContext
Value
(
target
:
IContextKeyServiceTarget
):
any
;
getContext
(
target
:
IContextKeyServiceTarget
):
IContext
;
}
export
const
SET_CONTEXT_COMMAND_ID
=
'
setContext
'
;
src/vs/platform/contextkey/test/common/contextkey.test.ts
浏览文件 @
b1f31342
...
...
@@ -7,6 +7,8 @@
import
*
as
assert
from
'
assert
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
const
createContext
=
ctx
=>
({
getValue
:
key
=>
ctx
[
key
]
});
suite
(
'
ContextKeyExpr
'
,
()
=>
{
test
(
'
ContextKeyExpr.equals
'
,
function
()
{
let
a
=
ContextKeyExpr
.
and
(
...
...
@@ -48,11 +50,11 @@ suite('ContextKeyExpr', () => {
test
(
'
evaluate
'
,
function
()
{
/* tslint:disable:triple-equals */
let
context
=
{
let
context
=
createContext
(
{
'
a
'
:
true
,
'
b
'
:
false
,
'
c
'
:
'
5
'
};
}
)
;
function
testExpression
(
expr
:
string
,
expected
:
boolean
):
void
{
let
rules
=
ContextKeyExpr
.
deserialize
(
expr
);
assert
.
equal
(
rules
.
evaluate
(
context
),
expected
,
expr
);
...
...
src/vs/platform/keybinding/common/abstractKeybindingService.ts
浏览文件 @
b1f31342
...
...
@@ -101,7 +101,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
return
null
;
}
const
contextValue
=
this
.
_contextKeyService
.
getContext
Value
(
target
);
const
contextValue
=
this
.
_contextKeyService
.
getContext
(
target
);
const
currentChord
=
this
.
_currentChord
?
this
.
_currentChord
.
keypress
:
null
;
return
this
.
_getResolver
().
resolve
(
contextValue
,
currentChord
,
firstPart
);
}
...
...
@@ -120,7 +120,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
return
shouldPreventDefault
;
}
const
contextValue
=
this
.
_contextKeyService
.
getContext
Value
(
target
);
const
contextValue
=
this
.
_contextKeyService
.
getContext
(
target
);
const
currentChord
=
this
.
_currentChord
?
this
.
_currentChord
.
keypress
:
null
;
const
keypressLabel
=
keybinding
.
getLabel
();
const
resolveResult
=
this
.
_getResolver
().
resolve
(
contextValue
,
currentChord
,
firstPart
);
...
...
src/vs/platform/keybinding/common/keybindingResolver.ts
浏览文件 @
b1f31342
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ContextKeyExpr
,
IContext
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ResolvedKeybindingItem
}
from
'
vs/platform/keybinding/common/resolvedKeybindingItem
'
;
import
{
CommandsRegistry
,
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
...
...
@@ -234,7 +234,7 @@ export class KeybindingResolver {
return
items
[
items
.
length
-
1
];
}
public
resolve
(
context
:
any
,
currentChord
:
string
,
keypress
:
string
):
IResolveResult
{
public
resolve
(
context
:
IContext
,
currentChord
:
string
,
keypress
:
string
):
IResolveResult
{
let
lookupMap
:
ResolvedKeybindingItem
[]
=
null
;
if
(
currentChord
!==
null
)
{
...
...
@@ -285,7 +285,7 @@ export class KeybindingResolver {
};
}
private
_findCommand
(
context
:
any
,
matches
:
ResolvedKeybindingItem
[]):
ResolvedKeybindingItem
{
private
_findCommand
(
context
:
IContext
,
matches
:
ResolvedKeybindingItem
[]):
ResolvedKeybindingItem
{
for
(
let
i
=
matches
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
k
=
matches
[
i
];
...
...
@@ -299,7 +299,7 @@ export class KeybindingResolver {
return
null
;
}
public
static
contextMatchesRules
(
context
:
any
,
rules
:
ContextKeyExpr
):
boolean
{
public
static
contextMatchesRules
(
context
:
IContext
,
rules
:
ContextKeyExpr
):
boolean
{
if
(
!
rules
)
{
return
true
;
}
...
...
src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts
浏览文件 @
b1f31342
...
...
@@ -12,7 +12,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
Severity
from
'
vs/base/common/severity
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
KeybindingResolver
}
from
'
vs/platform/keybinding/common/keybindingResolver
'
;
import
{
ContextKeyExpr
,
IContextKeyService
,
IContextKeyServiceTarget
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IContext
,
ContextKeyExpr
,
IContextKeyService
,
IContextKeyServiceTarget
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IStatusbarService
}
from
'
vs/platform/statusbar/common/statusbar
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -20,6 +20,8 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import
{
OS
}
from
'
vs/base/common/platform
'
;
import
{
IKeyboardEvent
}
from
'
vs/platform/keybinding/common/keybinding
'
;
const
createContext
=
ctx
=>
({
getValue
:
key
=>
ctx
[
key
]
});
suite
(
'
AbstractKeybindingService
'
,
()
=>
{
class
TestKeybindingService
extends
AbstractKeybindingService
{
...
...
@@ -69,7 +71,7 @@ suite('AbstractKeybindingService', () => {
}
let
createTestKeybindingService
:
(
items
:
ResolvedKeybindingItem
[],
contextValue
?:
any
)
=>
TestKeybindingService
=
null
;
let
currentContextValue
:
any
=
null
;
let
currentContextValue
:
IContext
=
null
;
let
executeCommandCalls
:
{
commandId
:
string
;
args
:
any
[];
}[]
=
null
;
let
showMessageCalls
:
{
sev
:
Severity
,
message
:
any
;
}[]
=
null
;
let
statusMessageCalls
:
string
[]
=
null
;
...
...
@@ -91,7 +93,7 @@ suite('AbstractKeybindingService', () => {
contextMatchesRules
:
undefined
,
getContextKeyValue
:
undefined
,
createScoped
:
undefined
,
getContext
Value
:
(
target
:
IContextKeyServiceTarget
):
any
=>
{
getContext
:
(
target
:
IContextKeyServiceTarget
):
any
=>
{
return
currentContextValue
;
}
};
...
...
@@ -269,9 +271,9 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + K
currentContextValue
=
{
currentContextValue
=
createContext
(
{
key1
:
true
};
}
)
;
let
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
);
assert
.
equal
(
shouldPreventDefault
,
true
);
assert
.
deepEqual
(
executeCommandCalls
,
[{
...
...
@@ -287,7 +289,7 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed
=
[];
// send Ctrl/Cmd + K
currentContextValue
=
{}
;
currentContextValue
=
createContext
({})
;
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
);
assert
.
equal
(
shouldPreventDefault
,
true
);
assert
.
deepEqual
(
executeCommandCalls
,
[]);
...
...
@@ -302,7 +304,7 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed
=
[];
// send Ctrl/Cmd + X
currentContextValue
=
{}
;
currentContextValue
=
createContext
({})
;
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_X
);
assert
.
equal
(
shouldPreventDefault
,
true
);
assert
.
deepEqual
(
executeCommandCalls
,
[{
...
...
@@ -331,7 +333,7 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + K
currentContextValue
=
{}
;
currentContextValue
=
createContext
({})
;
let
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
);
assert
.
equal
(
shouldPreventDefault
,
true
);
assert
.
deepEqual
(
executeCommandCalls
,
[{
...
...
@@ -347,9 +349,9 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed
=
[];
// send Ctrl/Cmd + K
currentContextValue
=
{
currentContextValue
=
createContext
(
{
key1
:
true
};
}
)
;
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
);
assert
.
equal
(
shouldPreventDefault
,
true
);
assert
.
deepEqual
(
executeCommandCalls
,
[{
...
...
@@ -365,9 +367,9 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed
=
[];
// send Ctrl/Cmd + X
currentContextValue
=
{
currentContextValue
=
createContext
(
{
key1
:
true
};
}
)
;
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_X
);
assert
.
equal
(
shouldPreventDefault
,
false
);
assert
.
deepEqual
(
executeCommandCalls
,
[]);
...
...
@@ -389,7 +391,7 @@ suite('AbstractKeybindingService', () => {
]);
// send Ctrl/Cmd + K
currentContextValue
=
{}
;
currentContextValue
=
createContext
({})
;
let
shouldPreventDefault
=
kbService
.
testDispatch
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
);
assert
.
equal
(
shouldPreventDefault
,
false
);
assert
.
deepEqual
(
executeCommandCalls
,
[{
...
...
src/vs/platform/keybinding/test/common/keybindingResolver.test.ts
浏览文件 @
b1f31342
...
...
@@ -7,11 +7,13 @@
import
*
as
assert
from
'
assert
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
,
createKeybinding
,
KeybindingType
,
SimpleKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
KeybindingResolver
}
from
'
vs/platform/keybinding/common/keybindingResolver
'
;
import
{
ContextKeyAndExpr
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ContextKeyAndExpr
,
ContextKeyExpr
,
IContext
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ResolvedKeybindingItem
}
from
'
vs/platform/keybinding/common/resolvedKeybindingItem
'
;
import
{
USLayoutResolvedKeybinding
}
from
'
vs/platform/keybinding/common/usLayoutResolvedKeybinding
'
;
import
{
OS
}
from
'
vs/base/common/platform
'
;
const
createContext
=
ctx
=>
({
getValue
:
key
=>
ctx
[
key
]
});
suite
(
'
KeybindingResolver
'
,
()
=>
{
function
kbItem
(
keybinding
:
number
,
command
:
string
,
commandArgs
:
any
,
when
:
ContextKeyExpr
,
isDefault
:
boolean
):
ResolvedKeybindingItem
{
...
...
@@ -35,12 +37,12 @@ suite('KeybindingResolver', () => {
let
contextRules
=
ContextKeyExpr
.
equals
(
'
bar
'
,
'
baz
'
);
let
keybindingItem
=
kbItem
(
keybinding
,
'
yes
'
,
null
,
contextRules
,
true
);
assert
.
equal
(
KeybindingResolver
.
contextMatchesRules
(
{
bar
:
'
baz
'
}
,
contextRules
),
true
);
assert
.
equal
(
KeybindingResolver
.
contextMatchesRules
(
{
bar
:
'
bz
'
}
,
contextRules
),
false
);
assert
.
equal
(
KeybindingResolver
.
contextMatchesRules
(
createContext
({
bar
:
'
baz
'
})
,
contextRules
),
true
);
assert
.
equal
(
KeybindingResolver
.
contextMatchesRules
(
createContext
({
bar
:
'
bz
'
})
,
contextRules
),
false
);
let
resolver
=
new
KeybindingResolver
([
keybindingItem
],
[]);
assert
.
equal
(
resolver
.
resolve
(
{
bar
:
'
baz
'
}
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)).
commandId
,
'
yes
'
);
assert
.
equal
(
resolver
.
resolve
(
{
bar
:
'
bz
'
}
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)),
null
);
assert
.
equal
(
resolver
.
resolve
(
createContext
({
bar
:
'
baz
'
})
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)).
commandId
,
'
yes
'
);
assert
.
equal
(
resolver
.
resolve
(
createContext
({
bar
:
'
bz
'
})
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)),
null
);
});
test
(
'
resolve key with arguments
'
,
function
()
{
...
...
@@ -51,7 +53,7 @@ suite('KeybindingResolver', () => {
let
keybindingItem
=
kbItem
(
keybinding
,
'
yes
'
,
commandArgs
,
contextRules
,
true
);
let
resolver
=
new
KeybindingResolver
([
keybindingItem
],
[]);
assert
.
equal
(
resolver
.
resolve
(
{
bar
:
'
baz
'
}
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)).
commandArgs
,
commandArgs
);
assert
.
equal
(
resolver
.
resolve
(
createContext
({
bar
:
'
baz
'
})
,
null
,
getDispatchStr
(
<
SimpleKeybinding
>
runtimeKeybinding
)).
commandArgs
,
commandArgs
);
});
test
(
'
KeybindingResolver.combine simple 1
'
,
function
()
{
...
...
@@ -333,7 +335,7 @@ suite('KeybindingResolver', () => {
}
};
let
testResolve
=
(
ctx
:
any
,
_expectedKey
:
number
,
commandId
:
string
)
=>
{
let
testResolve
=
(
ctx
:
IContext
,
_expectedKey
:
number
,
commandId
:
string
)
=>
{
const
expectedKey
=
createKeybinding
(
_expectedKey
,
OS
);
if
(
expectedKey
.
type
===
KeybindingType
.
Chord
)
{
...
...
@@ -360,30 +362,30 @@ suite('KeybindingResolver', () => {
testKey
(
'
first
'
,
[]);
testKey
(
'
second
'
,
[
KeyCode
.
KEY_Z
,
KeyCode
.
KEY_X
]);
testResolve
(
{
key2
:
true
}
,
KeyCode
.
KEY_X
,
'
second
'
);
testResolve
(
{}
,
KeyCode
.
KEY_Z
,
'
second
'
);
testResolve
(
createContext
({
key2
:
true
})
,
KeyCode
.
KEY_X
,
'
second
'
);
testResolve
(
createContext
({})
,
KeyCode
.
KEY_Z
,
'
second
'
);
testKey
(
'
third
'
,
[
KeyCode
.
KEY_X
]);
testResolve
(
{
key3
:
true
}
,
KeyCode
.
KEY_X
,
'
third
'
);
testResolve
(
createContext
({
key3
:
true
})
,
KeyCode
.
KEY_X
,
'
third
'
);
testKey
(
'
fourth
'
,
[]);
testKey
(
'
fifth
'
,
[
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_Y
,
KeyCode
.
KEY_Z
)]);
testResolve
(
{}
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_Y
,
KeyCode
.
KEY_Z
),
'
fifth
'
);
testResolve
(
createContext
({})
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_Y
,
KeyCode
.
KEY_Z
),
'
fifth
'
);
testKey
(
'
seventh
'
,
[
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
)]);
testResolve
(
{}
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
),
'
seventh
'
);
testResolve
(
createContext
({})
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
),
'
seventh
'
);
testKey
(
'
uncomment lines
'
,
[
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_U
)]);
testResolve
(
{}
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_U
),
'
uncomment lines
'
);
testResolve
(
createContext
({})
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_U
),
'
uncomment lines
'
);
testKey
(
'
comment lines
'
,
[
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_C
)]);
testResolve
(
{}
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_C
),
'
comment lines
'
);
testResolve
(
createContext
({})
,
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_C
),
'
comment lines
'
);
testKey
(
'
unreachablechord
'
,
[]);
testKey
(
'
eleven
'
,
[
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_G
]);
testResolve
(
{}
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_G
,
'
eleven
'
);
testResolve
(
createContext
({})
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_G
,
'
eleven
'
);
testKey
(
'
sixth
'
,
[]);
});
...
...
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
浏览文件 @
b1f31342
...
...
@@ -54,7 +54,7 @@ export class MockContextKeyService implements IContextKeyService {
public
getContextKeyValue
(
key
:
string
)
{
return
;
}
public
getContext
Value
(
domNode
:
HTMLElement
):
any
{
public
getContext
(
domNode
:
HTMLElement
):
any
{
return
null
;
}
public
createScoped
(
domNode
:
HTMLElement
):
IContextKeyService
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录