Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bfe5a942
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,体验更适合开发者的 AI 搜索 >>
提交
bfe5a942
编写于
1月 17, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
addAction returns IDisposable (fixes Microsoft/monaco-editor#286)
上级
18101697
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
73 addition
and
33 deletion
+73
-33
src/vs/editor/browser/standalone/simpleServices.ts
src/vs/editor/browser/standalone/simpleServices.ts
+28
-6
src/vs/editor/browser/standalone/standaloneCodeEditor.ts
src/vs/editor/browser/standalone/standaloneCodeEditor.ts
+27
-17
src/vs/editor/browser/widget/diffEditorWidget.ts
src/vs/editor/browser/widget/diffEditorWidget.ts
+2
-2
src/vs/editor/common/commonCodeEditor.ts
src/vs/editor/common/commonCodeEditor.ts
+12
-4
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+1
-1
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+3
-3
未找到文件。
src/vs/editor/browser/standalone/simpleServices.ts
浏览文件 @
bfe5a942
...
...
@@ -24,7 +24,7 @@ import { getDefaultValues as getDefaultConfiguration } from 'vs/platform/configu
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IProgressService
,
IProgressRunner
}
from
'
vs/platform/progress/common/progress
'
;
import
{
ITextModelResolverService
,
ITextModelContentProvider
,
ITextEditorModel
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
IDisposable
,
IReference
,
ImmortalReference
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
IReference
,
ImmortalReference
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
dom
from
'
vs/base/browser/dom
'
;
import
{
StandardKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
...
...
@@ -275,8 +275,13 @@ export class StandaloneCommandService implements ICommandService {
this
.
_dynamicCommands
=
Object
.
create
(
null
);
}
public
addCommand
(
id
:
string
,
command
:
ICommand
):
void
{
public
addCommand
(
id
:
string
,
command
:
ICommand
):
IDisposable
{
this
.
_dynamicCommands
[
id
]
=
command
;
return
{
dispose
:
()
=>
{
delete
this
.
_dynamicCommands
[
id
];
}
};
}
public
executeCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
TPromise
<
T
>
{
...
...
@@ -320,11 +325,14 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
}));
}
public
addDynamicKeybinding
(
keybinding
:
number
,
handler
:
ICommandHandler
,
when
:
string
,
commandId
:
string
=
null
):
string
{
public
addDynamicKeybinding
(
keybinding
:
number
,
handler
:
ICommandHandler
,
when
:
string
,
commandId
:
string
=
null
):
[
string
,
IDisposable
]
{
let
toDispose
:
IDisposable
[]
=
[];
if
(
commandId
===
null
)
{
commandId
=
'
DYNAMIC_
'
+
(
++
StandaloneKeybindingService
.
LAST_GENERATED_ID
);
}
let
parsedContext
=
IOSupport
.
readKeybindingWhen
(
when
);
this
.
_dynamicKeybindings
.
push
({
keybinding
:
keybinding
,
command
:
commandId
,
...
...
@@ -333,16 +341,30 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
weight2
:
0
});
toDispose
.
push
({
dispose
:
()
=>
{
for
(
let
i
=
0
;
i
<
this
.
_dynamicKeybindings
.
length
;
i
++
)
{
let
kb
=
this
.
_dynamicKeybindings
[
i
];
if
(
kb
.
command
===
commandId
)
{
this
.
_dynamicKeybindings
.
splice
(
i
,
1
);
this
.
updateResolver
({
source
:
KeybindingSource
.
Default
});
return
;
}
}
}
});
let
commandService
=
this
.
_commandService
;
if
(
commandService
instanceof
StandaloneCommandService
)
{
commandService
.
addCommand
(
commandId
,
{
toDispose
.
push
(
commandService
.
addCommand
(
commandId
,
{
handler
:
handler
});
})
)
;
}
else
{
throw
new
Error
(
'
Unknown command service!
'
);
}
this
.
updateResolver
({
source
:
KeybindingSource
.
Default
});
return
commandId
;
return
[
commandId
,
combinedDisposable
(
toDispose
)];
}
private
updateResolver
(
event
:
IKeybindingEvent
):
void
{
...
...
src/vs/editor/browser/standalone/standaloneCodeEditor.ts
浏览文件 @
bfe5a942
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
dispose
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IContextViewService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ICommandService
,
ICommandHandler
}
from
'
vs/platform/commands/common/commands
'
;
...
...
@@ -46,13 +46,13 @@ export interface IDiffEditorConstructionOptions extends IDiffEditorOptions {
export
interface
IStandaloneCodeEditor
extends
ICodeEditor
{
addCommand
(
keybinding
:
number
,
handler
:
ICommandHandler
,
context
:
string
):
string
;
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
;
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
}
export
interface
IStandaloneDiffEditor
extends
IDiffEditor
{
addCommand
(
keybinding
:
number
,
handler
:
ICommandHandler
,
context
:
string
):
string
;
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
;
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
}
export
class
StandaloneEditor
extends
CodeEditor
implements
IStandaloneCodeEditor
{
...
...
@@ -130,7 +130,8 @@ export class StandaloneEditor extends CodeEditor implements IStandaloneCodeEdito
console
.
warn
(
'
Cannot add command because the editor is configured with an unrecognized KeybindingService
'
);
return
null
;
}
return
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
keybinding
,
handler
,
context
);
let
r
=
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
keybinding
,
handler
,
context
);
return
r
[
0
];
}
public
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
{
...
...
@@ -141,8 +142,8 @@ export class StandaloneEditor extends CodeEditor implements IStandaloneCodeEdito
return
this
.
_contextKeyService
.
createKey
(
key
,
defaultValue
);
}
public
addAction
(
descriptor
:
IActionDescriptor
):
void
{
super
.
addAction
(
descriptor
)
;
public
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
{
let
toDispose
=
[
super
.
addAction
(
descriptor
)]
;
if
(
!
this
.
_standaloneKeybindingService
)
{
console
.
warn
(
'
Cannot add keybinding because the editor is configured with an unrecognized KeybindingService
'
);
return
null
;
...
...
@@ -151,10 +152,14 @@ export class StandaloneEditor extends CodeEditor implements IStandaloneCodeEdito
let
handler
:
ICommandHandler
=
(
accessor
)
=>
{
return
this
.
trigger
(
'
keyboard
'
,
descriptor
.
id
,
null
);
};
descriptor
.
keybindings
.
forEach
((
kb
)
=>
{
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
kb
,
handler
,
descriptor
.
keybindingContext
,
descriptor
.
id
);
});
}
toDispose
=
toDispose
.
concat
(
descriptor
.
keybindings
.
map
((
kb
)
=>
{
let
r
=
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
kb
,
handler
,
descriptor
.
keybindingContext
,
descriptor
.
id
);
return
r
[
1
];
})
);
}
return
combinedDisposable
(
toDispose
);
}
_attachModel
(
model
:
IModel
):
void
{
...
...
@@ -216,7 +221,8 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
console
.
warn
(
'
Cannot add command because the editor is configured with an unrecognized KeybindingService
'
);
return
null
;
}
return
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
keybinding
,
handler
,
context
);
let
r
=
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
keybinding
,
handler
,
context
);
return
r
[
0
];
}
public
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
{
...
...
@@ -227,8 +233,8 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
return
this
.
_contextKeyService
.
createKey
(
key
,
defaultValue
);
}
public
addAction
(
descriptor
:
IActionDescriptor
):
void
{
super
.
addAction
(
descriptor
)
;
public
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
{
let
toDispose
=
[
super
.
addAction
(
descriptor
)]
;
if
(
!
this
.
_standaloneKeybindingService
)
{
console
.
warn
(
'
Cannot add keybinding because the editor is configured with an unrecognized KeybindingService
'
);
return
null
;
...
...
@@ -237,9 +243,13 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
let
handler
:
ICommandHandler
=
(
ctx
)
=>
{
return
this
.
trigger
(
'
keyboard
'
,
descriptor
.
id
,
null
);
};
descriptor
.
keybindings
.
forEach
((
kb
)
=>
{
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
kb
,
handler
,
descriptor
.
keybindingContext
,
descriptor
.
id
);
});
}
toDispose
=
toDispose
.
concat
(
descriptor
.
keybindings
.
map
((
kb
)
=>
{
let
r
=
this
.
_standaloneKeybindingService
.
addDynamicKeybinding
(
kb
,
handler
,
descriptor
.
keybindingContext
,
descriptor
.
id
);
return
r
[
1
];
})
);
}
return
combinedDisposable
(
toDispose
);
}
}
src/vs/editor/browser/widget/diffEditorWidget.ts
浏览文件 @
bfe5a942
...
...
@@ -611,8 +611,8 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
this
.
modifiedEditor
.
revealRangeInCenterIfOutsideViewport
(
range
);
}
public
addAction
(
descriptor
:
editorCommon
.
IActionDescriptor
):
void
{
this
.
modifiedEditor
.
addAction
(
descriptor
);
public
addAction
(
descriptor
:
editorCommon
.
IActionDescriptor
):
IDisposable
{
return
this
.
modifiedEditor
.
addAction
(
descriptor
);
}
public
getActions
():
editorCommon
.
IEditorAction
[]
{
...
...
src/vs/editor/common/commonCodeEditor.ts
浏览文件 @
bfe5a942
...
...
@@ -7,7 +7,7 @@
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
Event
,
{
fromEventEmitter
}
from
'
vs/base/common/event
'
;
import
{
EventEmitter
,
IEventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
IDisposable
,
dispose
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ServicesAccessor
,
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
...
...
@@ -510,7 +510,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
return
<
T
>
(
this
.
_contributions
[
id
]
||
null
);
}
public
addAction
(
descriptor
:
editorCommon
.
IActionDescriptor
):
void
{
public
addAction
(
descriptor
:
editorCommon
.
IActionDescriptor
):
IDisposable
{
if
(
(
typeof
descriptor
.
id
!==
'
string
'
)
||
(
typeof
descriptor
.
label
!==
'
string
'
)
...
...
@@ -518,6 +518,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
)
{
throw
new
Error
(
'
Invalid action descriptor, `id`, `label` and `run` are required properties!
'
);
}
let
toDispose
:
IDisposable
[]
=
[];
// Generate a unique id to allow the same descriptor.id across multiple editor instances
let
uniqueId
=
this
.
getId
()
+
'
:
'
+
descriptor
.
id
;
...
...
@@ -525,7 +526,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
let
action
=
new
DynamicEditorAction
(
descriptor
,
this
);
// Register the command
CommandsRegistry
.
registerCommand
(
uniqueId
,
()
=>
action
.
run
(
));
toDispose
.
push
(
CommandsRegistry
.
registerCommand
(
uniqueId
,
()
=>
action
.
run
()
));
if
(
descriptor
.
contextMenuGroupId
)
{
let
menuItem
:
IMenuItem
=
{
...
...
@@ -539,10 +540,17 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
};
// Register the menu item
MenuRegistry
.
appendMenuItem
(
MenuId
.
EditorContext
,
menuItem
);
toDispose
.
push
(
MenuRegistry
.
appendMenuItem
(
MenuId
.
EditorContext
,
menuItem
)
);
}
this
.
_actions
[
action
.
id
]
=
action
;
toDispose
.
push
({
dispose
:
()
=>
{
delete
this
.
_actions
[
action
.
id
];
}
});
return
combinedDisposable
(
toDispose
);
}
public
getActions
():
editorCommon
.
IEditorAction
[]
{
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
bfe5a942
...
...
@@ -3481,7 +3481,7 @@ export interface IEditor {
/**
* Add a new action to this editor.
*/
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
/**
* Returns all actions associated with this editor.
...
...
src/vs/monaco.d.ts
浏览文件 @
bfe5a942
...
...
@@ -951,13 +951,13 @@ declare module monaco.editor {
export
interface
IStandaloneCodeEditor
extends
ICodeEditor
{
addCommand
(
keybinding
:
number
,
handler
:
ICommandHandler
,
context
:
string
):
string
;
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
;
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
}
export
interface
IStandaloneDiffEditor
extends
IDiffEditor
{
addCommand
(
keybinding
:
number
,
handler
:
ICommandHandler
,
context
:
string
):
string
;
createContextKey
<
T
>
(
key
:
string
,
defaultValue
:
T
):
IContextKey
<
T
>
;
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
}
export
interface
ICommandHandler
{
(...
args
:
any
[]):
void
;
...
...
@@ -2891,7 +2891,7 @@ declare module monaco.editor {
/**
* Add a new action to this editor.
*/
addAction
(
descriptor
:
IActionDescriptor
):
void
;
addAction
(
descriptor
:
IActionDescriptor
):
IDisposable
;
/**
* Returns all actions associated with this editor.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录