Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
bd1a69c0
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bd1a69c0
编写于
9月 20, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #12214: Do not use <any>
上级
6fa2edb3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
47 deletion
+59
-47
src/vs/editor/common/config/config.ts
src/vs/editor/common/config/config.ts
+6
-18
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+1
-1
src/vs/editor/common/services/codeEditorService.ts
src/vs/editor/common/services/codeEditorService.ts
+39
-3
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
+13
-25
未找到文件。
src/vs/editor/common/config/config.ts
浏览文件 @
bd1a69c0
...
...
@@ -12,7 +12,7 @@ import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import
{
IContextKeyService
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ICommandAndKeybindingRule
,
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
ICodeEditorService
,
getCodeEditor
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
CommandsRegistry
,
ICommandHandler
,
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
H
=
editorCommon
.
Handler
;
...
...
@@ -112,7 +112,7 @@ export abstract class EditorCommand extends Command {
public
runCommand
(
accessor
:
ServicesAccessor
,
args
:
any
):
void
|
TPromise
<
void
>
{
let
editor
=
findFocusedEditor
(
this
.
id
,
accessor
,
false
);
if
(
!
editor
)
{
editor
=
getActiveEditor
(
accessor
);
editor
=
getActiveEditor
Widget
(
accessor
);
}
if
(
!
editor
)
{
// well, at least we tried...
...
...
@@ -150,22 +150,10 @@ function withCodeEditorFromCommandHandler(commandId: string, accessor: ServicesA
}
}
function
getActiveEditor
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
le
t
editorService
=
accessor
.
get
(
IEditorService
);
function
getActiveEditor
Widget
(
accessor
:
ServicesAccessor
):
editorCommon
.
ICommonCodeEditor
{
cons
t
editorService
=
accessor
.
get
(
IEditorService
);
let
activeEditor
=
(
<
any
>
editorService
).
getActiveEditor
&&
(
<
any
>
editorService
).
getActiveEditor
();
if
(
activeEditor
)
{
let
editor
=
<
editorCommon
.
IEditor
>
activeEditor
.
getControl
();
// Substitute for (editor instanceof ICodeEditor)
if
(
editor
&&
typeof
editor
.
getEditorType
===
'
function
'
)
{
if
(
editor
.
getEditorType
()
===
editorCommon
.
EditorType
.
ICodeEditor
)
{
return
<
editorCommon
.
ICommonCodeEditor
>
editor
;
}
return
(
<
editorCommon
.
ICommonDiffEditor
>
editor
).
getModifiedEditor
();
}
}
return
null
;
return
getCodeEditor
(
activeEditor
);
}
function
triggerEditorHandler
(
handlerId
:
string
,
accessor
:
ServicesAccessor
,
args
:
any
):
void
{
...
...
@@ -796,7 +784,7 @@ class SelectAllCommand extends Command {
}
// Redirecting to last active editor
let
activeEditor
=
getActiveEditor
(
accessor
);
let
activeEditor
=
getActiveEditor
Widget
(
accessor
);
if
(
activeEditor
)
{
activeEditor
.
focus
();
activeEditor
.
trigger
(
'
keyboard
'
,
HANDLER
,
args
);
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
bd1a69c0
...
...
@@ -4136,7 +4136,7 @@ export function isCommonCodeEditor(thing: any): thing is ICommonCodeEditor {
*/
export
function
isCommonDiffEditor
(
thing
:
any
):
thing
is
ICommonDiffEditor
{
if
(
thing
&&
typeof
(
<
ICommonDiffEditor
>
thing
).
getEditorType
===
'
function
'
)
{
return
(
<
ICommonDiffEditor
>
thing
).
getEditorType
()
===
EditorType
.
I
Code
Editor
;
return
(
<
ICommonDiffEditor
>
thing
).
getEditorType
()
===
EditorType
.
I
Diff
Editor
;
}
else
{
return
false
;
}
...
...
src/vs/editor/common/services/codeEditorService.ts
浏览文件 @
bd1a69c0
...
...
@@ -6,10 +6,10 @@
import
Event
from
'
vs/base/common/event
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ICommonCodeEditor
,
IDecorationRenderOptions
,
IModelDecorationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ICommonCodeEditor
,
ICommonDiffEditor
,
isCommonCodeEditor
,
isCommonDiffEditor
,
IDecorationRenderOptions
,
IModelDecorationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditor
}
from
'
vs/platform/editor/common/editor
'
;
export
var
ID_CODE_EDITOR_SERVICE
=
'
codeEditorService
'
;
export
var
ICodeEditorService
=
createDecorator
<
ICodeEditorService
>
(
ID_CODE_EDITOR_SERVICE
);
export
var
ICodeEditorService
=
createDecorator
<
ICodeEditorService
>
(
'
codeEditorService
'
);
export
interface
ICodeEditorService
{
_serviceBrand
:
any
;
...
...
@@ -33,3 +33,39 @@ export interface ICodeEditorService {
removeDecorationType
(
key
:
string
):
void
;
resolveDecorationOptions
(
typeKey
:
string
,
writable
:
boolean
):
IModelDecorationOptions
;
}
/**
* Uses `editor.getControl()` and returns either a `codeEditor` or a `diffEditor` or nothing.
*/
export
function
getCodeOrDiffEditor
(
editor
:
IEditor
):
{
codeEditor
:
ICommonCodeEditor
;
diffEditor
:
ICommonDiffEditor
}
{
if
(
editor
)
{
let
control
=
editor
.
getControl
();
if
(
control
)
{
if
(
isCommonCodeEditor
(
control
))
{
return
{
codeEditor
:
control
,
diffEditor
:
null
};
}
if
(
isCommonDiffEditor
(
control
))
{
return
{
codeEditor
:
null
,
diffEditor
:
control
};
}
}
}
return
{
codeEditor
:
null
,
diffEditor
:
null
};
}
/**
* Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing.
*/
export
function
getCodeEditor
(
editor
:
IEditor
):
ICommonCodeEditor
{
let
r
=
getCodeOrDiffEditor
(
editor
);
return
r
.
codeEditor
||
(
r
.
diffEditor
&&
r
.
diffEditor
.
getModifiedEditor
())
||
null
;
}
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
浏览文件 @
bd1a69c0
...
...
@@ -7,7 +7,6 @@
import
'
vs/css!./media/statusbarpart
'
;
import
dom
=
require
(
'
vs/base/browser/dom
'
);
import
types
=
require
(
'
vs/base/common/types
'
);
import
nls
=
require
(
'
vs/nls
'
);
import
{
toErrorMessage
}
from
'
vs/base/common/errorMessage
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -16,7 +15,6 @@ import {Builder, $} from 'vs/base/browser/builder';
import
{
OcticonLabel
}
from
'
vs/base/browser/ui/octiconLabel/octiconLabel
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
Part
}
from
'
vs/workbench/browser/part
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actionRegistry
'
;
...
...
@@ -25,6 +23,7 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IMessageService
,
Severity
}
from
'
vs/platform/message/common/message
'
;
import
{
IStatusbarService
,
IStatusbarEntry
}
from
'
vs/platform/statusbar/common/statusbar
'
;
import
{
getCodeEditor
}
from
'
vs/editor/common/services/codeEditorService
'
;
export
class
StatusbarPart
extends
Part
implements
IStatusbarService
{
...
...
@@ -236,30 +235,12 @@ class StatusBarEntryItem implements IStatusbarItem {
}
private
executeCommand
(
id
:
string
)
{
let
action
:
IAction
;
let
activeEditor
=
this
.
editorService
.
getActiveEditor
();
// Lookup built in commands
let
builtInActionDescriptor
=
(
<
IWorkbenchActionRegistry
>
Registry
.
as
(
ActionExtensions
.
WorkbenchActions
)).
getWorkbenchAction
(
id
);
if
(
builtInActionDescriptor
)
{
action
=
this
.
instantiationService
.
createInstance
(
builtInActionDescriptor
.
syncDescriptor
);
}
// Lookup editor commands
if
(
!
action
)
{
let
activeEditorControl
=
<
any
>
(
activeEditor
?
activeEditor
.
getControl
()
:
null
);
if
(
activeEditorControl
&&
types
.
isFunction
(
activeEditorControl
.
getAction
))
{
action
=
activeEditorControl
.
getAction
(
id
);
}
}
let
action
=
this
.
instantiationService
.
createInstance
(
builtInActionDescriptor
.
syncDescriptor
);
// Some actions or commands might only be enabled for an active editor, so focus it first
if
(
activeEditor
)
{
activeEditor
.
focus
();
}
// Run it if enabled
if
(
action
)
{
if
(
action
.
enabled
)
{
this
.
telemetryService
.
publicLog
(
'
workbenchActionExecuted
'
,
{
id
:
action
.
id
,
from
:
'
status bar
'
});
(
action
.
run
()
||
TPromise
.
as
(
null
)).
done
(()
=>
{
...
...
@@ -268,11 +249,18 @@ class StatusBarEntryItem implements IStatusbarItem {
}
else
{
this
.
messageService
.
show
(
Severity
.
Warning
,
nls
.
localize
(
'
canNotRun
'
,
"
Command '{0}' can not be run from here.
"
,
action
.
label
||
id
));
}
return
;
}
// Fallback to the keybinding service for any other case
else
{
this
.
commandService
.
executeCommand
(
id
).
done
(
undefined
,
err
=>
this
.
messageService
.
show
(
Severity
.
Error
,
toErrorMessage
(
err
)));
// Maintain old behaviour of always focusing the editor here
let
activeEditor
=
this
.
editorService
.
getActiveEditor
();
let
codeEditor
=
getCodeEditor
(
activeEditor
);
if
(
codeEditor
)
{
codeEditor
.
focus
();
}
// Fallback to the command service for any other case
this
.
commandService
.
executeCommand
(
id
).
done
(
undefined
,
err
=>
this
.
messageService
.
show
(
Severity
.
Error
,
toErrorMessage
(
err
)));
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录