Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d2bac293
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,发现更多精彩内容 >>
提交
d2bac293
编写于
5月 19, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move editor command registration to coreCommands.ts
上级
bf562ce5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
70 deletion
+81
-70
src/vs/editor/common/config/config.ts
src/vs/editor/common/config/config.ts
+32
-64
src/vs/editor/common/controller/coreCommands.ts
src/vs/editor/common/controller/coreCommands.ts
+49
-6
未找到文件。
src/vs/editor/common/config/config.ts
浏览文件 @
d2bac293
...
...
@@ -11,8 +11,7 @@ import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/commo
import
{
ICommandAndKeybindingRule
,
IKeybindings
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
ICodeEditorService
,
getCodeEditor
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
CommandsRegistry
,
ICommandHandler
,
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
H
=
editorCommon
.
Handler
;
import
{
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
export
interface
ICommandKeybindingsOptions
extends
IKeybindings
{
kbExpr
?:
ContextKeyExpr
;
...
...
@@ -27,22 +26,20 @@ export interface ICommandOptions {
}
export
abstract
class
Command
{
public
id
:
string
;
public
precondition
:
ContextKeyExpr
;
private
kbOpts
:
ICommandKeybindingsOptions
;
private
description
:
ICommandHandlerDescription
;
public
readonly
id
:
string
;
public
readonly
precondition
:
ContextKeyExpr
;
private
readonly
_
kbOpts
:
ICommandKeybindingsOptions
;
private
readonly
_
description
:
ICommandHandlerDescription
;
constructor
(
opts
:
ICommandOptions
)
{
this
.
id
=
opts
.
id
;
this
.
precondition
=
opts
.
precondition
;
this
.
kbOpts
=
opts
.
kbOpts
;
this
.
description
=
opts
.
description
;
this
.
_
kbOpts
=
opts
.
kbOpts
;
this
.
_
description
=
opts
.
description
;
}
public
abstract
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
|
TPromise
<
void
>
;
public
toCommandAndKeybindingRule
(
defaultWeight
:
number
):
ICommandAndKeybindingRule
{
const
kbOpts
=
this
.
kbOpts
||
{
primary
:
0
};
const
kbOpts
=
this
.
_
kbOpts
||
{
primary
:
0
};
let
kbWhen
=
kbOpts
.
kbExpr
;
if
(
this
.
precondition
)
{
...
...
@@ -65,23 +62,37 @@ export abstract class Command {
win
:
kbOpts
.
win
,
linux
:
kbOpts
.
linux
,
mac
:
kbOpts
.
mac
,
description
:
this
.
description
description
:
this
.
_
description
};
}
public
abstract
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
|
TPromise
<
void
>
;
}
export
interface
IContributionCommandOptions
<
T
>
extends
ICommandOptions
{
handler
:
(
controller
:
T
)
=>
void
;
}
export
interface
EditorControllerCommand
<
T
extends
editorCommon
.
IEditorContribution
>
{
new
(
opts
:
IContributionCommandOptions
<
T
>
):
EditorCommand
;
}
export
interface
IContributionCommandOptions
<
T
>
extends
ICommandOptions
{
handler
:
(
controller
:
T
)
=>
void
;
function
findFocusedEditor
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
return
accessor
.
get
(
ICodeEditorService
).
getFocusedCodeEditor
();
}
function
getWorkbenchActiveEditor
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
const
editorService
=
accessor
.
get
(
IEditorService
);
let
activeEditor
=
(
<
any
>
editorService
).
getActiveEditor
&&
(
<
any
>
editorService
).
getActiveEditor
();
return
getCodeEditor
(
activeEditor
);
}
export
abstract
class
EditorCommand
extends
Command
{
/**
* Create a command class that is bound to a certain editor contribution.
*/
public
static
bindToContribution
<
T
extends
editorCommon
.
IEditorContribution
>
(
controllerGetter
:
(
editor
:
editorCommon
.
ICommonCodeEditor
)
=>
T
):
EditorControllerCommand
<
T
>
{
return
class
EditorControllerCommandImpl
extends
EditorCommand
{
private
_callback
:
(
controller
:
T
)
=>
void
;
...
...
@@ -100,19 +111,20 @@ export abstract class EditorCommand extends Command {
};
}
constructor
(
opts
:
ICommandOptions
)
{
super
(
opts
);
}
public
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
|
TPromise
<
void
>
{
// Find the editor with text focus
let
editor
=
findFocusedEditor
(
accessor
);
if
(
!
editor
)
{
editor
=
getActiveEditorWidget
(
accessor
);
// Fallback to use what the workbench considers the active editor
editor
=
getWorkbenchActiveEditor
(
accessor
);
}
if
(
!
editor
)
{
// well, at least we tried...
return
;
}
return
editor
.
invokeWithinContext
((
editorAccessor
)
=>
{
const
kbService
=
editorAccessor
.
get
(
IContextKeyService
);
if
(
!
kbService
.
contextMatchesRules
(
this
.
precondition
))
{
...
...
@@ -126,47 +138,3 @@ export abstract class EditorCommand extends Command {
public
abstract
runEditorCommand
(
accessor
:
ServicesAccessor
,
editor
:
editorCommon
.
ICommonCodeEditor
,
args
:
any
):
void
|
TPromise
<
void
>
;
}
function
findFocusedEditor
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
return
accessor
.
get
(
ICodeEditorService
).
getFocusedCodeEditor
();
}
function
withCodeEditorFromCommandHandler
(
accessor
:
ServicesAccessor
,
callback
:
(
editor
:
editorCommon
.
ICommonCodeEditor
)
=>
void
):
void
{
let
editor
=
findFocusedEditor
(
accessor
);
if
(
editor
)
{
callback
(
editor
);
}
}
function
getActiveEditorWidget
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
const
editorService
=
accessor
.
get
(
IEditorService
);
let
activeEditor
=
(
<
any
>
editorService
).
getActiveEditor
&&
(
<
any
>
editorService
).
getActiveEditor
();
return
getCodeEditor
(
activeEditor
);
}
function
triggerEditorHandler
(
handlerId
:
string
,
accessor
:
ServicesAccessor
,
args
:
any
):
void
{
withCodeEditorFromCommandHandler
(
accessor
,
(
editor
)
=>
{
editor
.
trigger
(
'
keyboard
'
,
handlerId
,
args
);
});
}
class
CoreCommand
extends
Command
{
public
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
{
triggerEditorHandler
(
this
.
id
,
accessor
,
args
);
}
}
function
registerOverwritableCommand
(
handlerId
:
string
,
handler
:
ICommandHandler
):
void
{
CommandsRegistry
.
registerCommand
(
handlerId
,
handler
);
CommandsRegistry
.
registerCommand
(
'
default:
'
+
handlerId
,
handler
);
}
function
registerCoreDispatchCommand
(
handlerId
:
string
):
void
{
registerOverwritableCommand
(
handlerId
,
triggerEditorHandler
.
bind
(
null
,
handlerId
));
}
registerCoreDispatchCommand
(
H
.
Type
);
registerCoreDispatchCommand
(
H
.
ReplacePreviousChar
);
registerCoreDispatchCommand
(
H
.
CompositionStart
);
registerCoreDispatchCommand
(
H
.
CompositionEnd
);
registerCoreDispatchCommand
(
H
.
Paste
);
registerCoreDispatchCommand
(
H
.
Cut
);
src/vs/editor/common/controller/coreCommands.ts
浏览文件 @
d2bac293
...
...
@@ -1522,7 +1522,7 @@ namespace Config {
return
accessor
.
get
(
ICodeEditorService
).
getFocusedCodeEditor
();
}
function
get
ActiveEditorWidget
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
function
get
WorkbenchActiveEditor
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
const
editorService
=
accessor
.
get
(
IEditorService
);
let
activeEditor
=
(
<
any
>
editorService
).
getActiveEditor
&&
(
<
any
>
editorService
).
getActiveEditor
();
return
getCodeEditor
(
activeEditor
);
...
...
@@ -1532,7 +1532,13 @@ namespace Config {
KeybindingsRegistry
.
registerCommandAndKeybindingRule
(
command
.
toCommandAndKeybindingRule
(
CORE_WEIGHT
));
}
class
BaseTextInputAwareCommand
extends
Command
{
/**
* A command that will:
* 1. invoke a command on the focused editor.
* 2. otherwise, invoke a browser built-in command on the `activeElement`.
* 3. otherwise, invoke a command on the workbench active editor.
*/
class
EditorOrNativeTextInputCommand
extends
Command
{
private
readonly
_editorHandler
:
string
|
EditorCommand
;
private
readonly
_inputHandler
:
string
;
...
...
@@ -1559,7 +1565,7 @@ namespace Config {
}
// Redirecting to last active editor
let
activeEditor
=
get
ActiveEditorWidget
(
accessor
);
let
activeEditor
=
get
WorkbenchActiveEditor
(
accessor
);
if
(
activeEditor
)
{
activeEditor
.
focus
();
return
this
.
_runEditorHandler
(
activeEditor
,
args
);
...
...
@@ -1578,7 +1584,7 @@ namespace Config {
}
}
registerCommand
(
new
BaseTextInputAware
Command
({
registerCommand
(
new
EditorOrNativeTextInput
Command
({
editorHandler
:
CoreNavigationCommands
.
SelectAll
,
inputHandler
:
'
selectAll
'
,
id
:
'
editor.action.selectAll
'
,
...
...
@@ -1590,7 +1596,7 @@ namespace Config {
}
}));
registerCommand
(
new
BaseTextInputAware
Command
({
registerCommand
(
new
EditorOrNativeTextInput
Command
({
editorHandler
:
H
.
Undo
,
inputHandler
:
'
undo
'
,
id
:
H
.
Undo
,
...
...
@@ -1602,7 +1608,7 @@ namespace Config {
}
}));
registerCommand
(
new
BaseTextInputAware
Command
({
registerCommand
(
new
EditorOrNativeTextInput
Command
({
editorHandler
:
H
.
Redo
,
inputHandler
:
'
redo
'
,
id
:
H
.
Redo
,
...
...
@@ -1616,4 +1622,41 @@ namespace Config {
}
}));
/**
* A command that will invoke a command on the focused editor.
*/
class
EditorHandlerCommand
extends
Command
{
private
readonly
_handlerId
:
string
;
constructor
(
id
:
string
,
handlerId
:
string
)
{
super
({
id
:
id
,
precondition
:
null
});
this
.
_handlerId
=
handlerId
;
}
public
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
{
const
editor
=
findFocusedEditor
(
accessor
);
if
(
!
editor
)
{
return
;
}
editor
.
trigger
(
'
keyboard
'
,
this
.
_handlerId
,
args
);
}
}
function
registerOverwritableCommand
(
handlerId
:
string
):
void
{
registerCommand
(
new
EditorHandlerCommand
(
'
default:
'
+
handlerId
,
handlerId
));
registerCommand
(
new
EditorHandlerCommand
(
handlerId
,
handlerId
));
}
registerOverwritableCommand
(
H
.
Type
);
registerOverwritableCommand
(
H
.
ReplacePreviousChar
);
registerOverwritableCommand
(
H
.
CompositionStart
);
registerOverwritableCommand
(
H
.
CompositionEnd
);
registerOverwritableCommand
(
H
.
Paste
);
registerOverwritableCommand
(
H
.
Cut
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录