Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
68521e35
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 搜索 >>
提交
68521e35
编写于
5月 16, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grid - replaceEditors() on editor service
上级
29226976
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
3 deletion
+78
-3
src/vs/workbench/services/editor/browser/nextEditorService.ts
...vs/workbench/services/editor/browser/nextEditorService.ts
+31
-2
src/vs/workbench/services/editor/common/nextEditorService.ts
src/vs/workbench/services/editor/common/nextEditorService.ts
+17
-1
src/vs/workbench/services/editor/test/browser/nextEditorService.test.ts
...ch/services/editor/test/browser/nextEditorService.test.ts
+26
-0
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+4
-0
未找到文件。
src/vs/workbench/services/editor/browser/nextEditorService.ts
浏览文件 @
68521e35
...
...
@@ -24,8 +24,8 @@ import { basename } from 'vs/base/common/paths';
import
{
DiffEditorInput
}
from
'
vs/workbench/common/editor/diffEditorInput
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
INextEditorGroupsService
,
INextEditorGroup
,
GroupDirection
,
GroupsOrder
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
import
{
INextEditorService
,
IResourceEditor
,
ACTIVE_GROUP_TYPE
,
SIDE_GROUP_TYPE
,
SIDE_GROUP
,
ACTIVE_GROUP
}
from
'
vs/workbench/services/editor/common/nextEditorService
'
;
import
{
INextEditorGroupsService
,
INextEditorGroup
,
GroupDirection
,
GroupsOrder
,
IEditorReplacement
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
import
{
INextEditorService
,
IResourceEditor
,
ACTIVE_GROUP_TYPE
,
SIDE_GROUP_TYPE
,
SIDE_GROUP
,
ACTIVE_GROUP
,
IResourceEditorReplacement
}
from
'
vs/workbench/services/editor/common/nextEditorService
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
coalesce
}
from
'
vs/base/common/arrays
'
;
...
...
@@ -390,6 +390,35 @@ export class NextEditorService extends Disposable implements INextEditorService,
//#endregion
//#region replaceEditors()
replaceEditors
(
editors
:
IResourceEditorReplacement
[],
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
;
replaceEditors
(
editors
:
IEditorReplacement
[],
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
;
replaceEditors
(
editors
:
(
IEditorReplacement
|
IResourceEditorReplacement
)[],
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
{
const
typedEditors
:
IEditorReplacement
[]
=
[];
editors
.
forEach
(
replaceEditorArg
=>
{
if
(
replaceEditorArg
.
editor
instanceof
EditorInput
)
{
typedEditors
.
push
(
replaceEditorArg
as
IEditorReplacement
);
}
else
{
const
editor
=
replaceEditorArg
.
editor
as
IResourceEditor
;
const
typedEditor
=
this
.
createInput
(
editor
);
const
replacementEditor
=
this
.
createInput
(
replaceEditorArg
.
replacement
as
IResourceEditor
);
typedEditors
.
push
({
editor
:
typedEditor
,
replacement
:
replacementEditor
,
options
:
this
.
toOptions
(
editor
.
options
)
});
}
});
const
targetGroup
=
typeof
group
===
'
number
'
?
this
.
nextEditorGroupsService
.
getGroup
(
group
)
:
group
;
return
targetGroup
.
replaceEditors
(
typedEditors
);
}
//#endregion
//#region closeEditor()
closeEditor
(
editor
:
IEditorInput
,
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
{
...
...
src/vs/workbench/services/editor/common/nextEditorService.ts
浏览文件 @
68521e35
...
...
@@ -10,13 +10,18 @@ import { IResourceInput, IEditorOptions } from 'vs/platform/editor/common/editor
import
{
IEditorInput
,
IEditor
,
GroupIdentifier
,
IEditorOpeningEvent
,
IEditorInputWithOptions
,
IEditorIdentifier
,
IUntitledResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
}
from
'
vs/workbench/common/editor
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
IEditor
as
ITextEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
INextEditorGroup
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
import
{
INextEditorGroup
,
IEditorReplacement
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
export
const
INextEditorService
=
createDecorator
<
INextEditorService
>
(
'
nextEditorService
'
);
export
type
IResourceEditor
=
IResourceInput
|
IUntitledResourceInput
|
IResourceDiffInput
|
IResourceSideBySideInput
;
export
interface
IResourceEditorReplacement
{
editor
:
IResourceEditor
;
replacement
:
IResourceEditor
;
}
export
const
ACTIVE_GROUP
=
-
1
;
export
type
ACTIVE_GROUP_TYPE
=
typeof
ACTIVE_GROUP
;
...
...
@@ -124,6 +129,17 @@ export interface INextEditorService {
openEditors
(
editors
:
IEditorInputWithOptions
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
TPromise
<
ReadonlyArray
<
IEditor
>>
;
openEditors
(
editors
:
IResourceEditor
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
TPromise
<
ReadonlyArray
<
IEditor
>>
;
/**
* Replaces editors in an editor group with the provided replacement.
*
* @param editors the editors to replace
*
* @returns a promise that is resolved when the replaced active
* editor (if any) has finished loading.
*/
replaceEditors
(
editors
:
IResourceEditorReplacement
[],
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
;
replaceEditors
(
editors
:
IEditorReplacement
[],
group
:
INextEditorGroup
|
GroupIdentifier
):
TPromise
<
void
>
;
/**
* Find out if the provided editor (or resource of an editor) is opened in any group.
*
...
...
src/vs/workbench/services/editor/test/browser/nextEditorService.test.ts
浏览文件 @
68521e35
...
...
@@ -146,6 +146,32 @@ suite('Editor service (editor2)', () => {
});
});
test
(
'
openEditors() / replaceEditors()
'
,
function
()
{
const
partInstantiator
=
workbenchInstantiationService
();
const
part
=
partInstantiator
.
createInstance
(
NextEditorPart
,
'
id
'
,
false
);
part
.
create
(
document
.
createElement
(
'
div
'
));
part
.
layout
(
new
Dimension
(
400
,
300
));
const
testInstantiationService
=
partInstantiator
.
createChild
(
new
ServiceCollection
([
INextEditorGroupsService
,
part
]));
const
service
:
INextEditorService
=
testInstantiationService
.
createInstance
(
NextEditorService
);
const
input
=
testInstantiationService
.
createInstance
(
TestEditorInput
,
URI
.
parse
(
'
my://resource
'
));
const
otherInput
=
testInstantiationService
.
createInstance
(
TestEditorInput
,
URI
.
parse
(
'
my://resource2
'
));
const
replaceInput
=
testInstantiationService
.
createInstance
(
TestEditorInput
,
URI
.
parse
(
'
my://resource3
'
));
// Open editors
return
service
.
openEditors
([{
editor
:
input
},
{
editor
:
otherInput
}]).
then
(()
=>
{
assert
.
equal
(
part
.
activeGroup
.
count
,
2
);
return
service
.
replaceEditors
([{
editor
:
input
,
replacement
:
replaceInput
}],
part
.
activeGroup
).
then
(()
=>
{
assert
.
equal
(
part
.
activeGroup
.
count
,
2
);
assert
.
equal
(
part
.
activeGroup
.
getIndexOfEditor
(
replaceInput
),
0
);
});
});
});
test
(
'
caching
'
,
function
()
{
const
instantiationService
=
workbenchInstantiationService
();
const
service
:
NextEditorService
=
<
any
>
instantiationService
.
createInstance
(
NextEditorService
);
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
68521e35
...
...
@@ -890,6 +890,10 @@ export class TestNextEditorService implements INextEditorService {
return
TPromise
.
as
(
null
);
}
replaceEditors
(
editors
:
any
,
group
:
any
)
{
return
TPromise
.
as
(
void
0
);
}
invokeWithinEditorContext
<
T
>
(
fn
:
(
accessor
:
ServicesAccessor
)
=>
T
):
T
{
return
fn
(
null
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录