Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
156f3c59
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,发现更多精彩内容 >>
提交
156f3c59
编写于
5月 06, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add api to move an editor
上级
fb1c9a6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
16 deletion
+77
-16
src/vs/workbench/common/editor/editorStacksModel.ts
src/vs/workbench/common/editor/editorStacksModel.ts
+29
-15
src/vs/workbench/test/common/editor/editorStacksModel.test.ts
...vs/workbench/test/common/editor/editorStacksModel.test.ts
+48
-1
未找到文件。
src/vs/workbench/common/editor/editorStacksModel.ts
浏览文件 @
156f3c59
...
...
@@ -14,8 +14,6 @@ import {dispose, IDisposable} from 'vs/base/common/lifecycle';
import
{
IEditorRegistry
,
Extensions
}
from
'
vs/workbench/browser/parts/editor/baseEditor
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
/// --- API-Start ----
export
interface
IEditorGroup
{
label
:
string
;
...
...
@@ -26,11 +24,13 @@ export interface IEditorGroup {
onEditorActivated
:
Event
<
EditorInput
>
;
onEditorOpened
:
Event
<
EditorInput
>
;
onEditorClosed
:
Event
<
EditorInput
>
;
onEditorMoved
:
Event
<
EditorInput
>
;
onEditorPinned
:
Event
<
EditorInput
>
;
onEditorUnpinned
:
Event
<
EditorInput
>
;
getEditors
(
mru
?:
boolean
):
EditorInput
[];
openEditor
(
editor
:
EditorInput
,
options
?:
IEditorOpenOptions
):
void
;
moveEditor
(
editor
:
EditorInput
,
toIndex
:
number
):
void
;
closeEditor
(
editor
:
EditorInput
):
void
;
closeEditors
(
except
:
EditorInput
,
direction
?:
Direction
):
void
;
closeAllEditors
():
void
;
...
...
@@ -68,10 +68,6 @@ export interface IEditorOpenOptions {
active
?:
boolean
;
}
/// --- API-End ----
// Move Editor
export
enum
Direction
{
LEFT
,
RIGHT
...
...
@@ -103,9 +99,12 @@ export class EditorGroup implements IEditorGroup {
private
preview
:
EditorInput
;
// editor in preview state
private
active
:
EditorInput
;
// editor in active state
private
toDispose
:
IDisposable
[];
private
_onEditorActivated
:
Emitter
<
EditorInput
>
;
private
_onEditorOpened
:
Emitter
<
EditorInput
>
;
private
_onEditorClosed
:
Emitter
<
EditorInput
>
;
private
_onEditorMoved
:
Emitter
<
EditorInput
>
;
private
_onEditorPinned
:
Emitter
<
EditorInput
>
;
private
_onEditorUnpinned
:
Emitter
<
EditorInput
>
;
...
...
@@ -115,6 +114,7 @@ export class EditorGroup implements IEditorGroup {
)
{
this
.
editors
=
[];
this
.
mru
=
[];
this
.
toDispose
=
[];
if
(
typeof
arg1
===
'
object
'
)
{
this
.
deserialize
(
arg1
);
...
...
@@ -125,8 +125,11 @@ export class EditorGroup implements IEditorGroup {
this
.
_onEditorActivated
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorOpened
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorClosed
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorMoved
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorPinned
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorUnpinned
=
new
Emitter
<
EditorInput
>
();
this
.
toDispose
.
push
(
this
.
_onEditorActivated
,
this
.
_onEditorOpened
,
this
.
_onEditorClosed
,
this
.
_onEditorMoved
,
this
.
_onEditorPinned
,
this
.
_onEditorUnpinned
);
}
public
get
label
():
string
{
...
...
@@ -149,6 +152,10 @@ export class EditorGroup implements IEditorGroup {
return
this
.
_onEditorClosed
.
event
;
}
public
get
onEditorMoved
():
Event
<
EditorInput
>
{
return
this
.
_onEditorMoved
.
event
;
}
public
get
onEditorPinned
():
Event
<
EditorInput
>
{
return
this
.
_onEditorPinned
.
event
;
}
...
...
@@ -307,6 +314,20 @@ export class EditorGroup implements IEditorGroup {
this
.
closeEditor
(
this
.
active
);
}
public
moveEditor
(
editor
:
EditorInput
,
toIndex
:
number
):
void
{
const
index
=
this
.
indexOf
(
editor
);
if
(
index
<
0
)
{
return
;
}
// Move
this
.
editors
.
splice
(
index
,
1
);
this
.
editors
.
splice
(
toIndex
,
0
,
editor
);
// Event
this
.
_onEditorMoved
.
fire
(
editor
);
}
public
setActive
(
editor
:
EditorInput
):
void
{
const
index
=
this
.
indexOf
(
editor
);
if
(
index
===
-
1
)
{
...
...
@@ -472,11 +493,7 @@ export class EditorGroup implements IEditorGroup {
}
public
dispose
():
void
{
this
.
_onEditorActivated
.
dispose
();
this
.
_onEditorClosed
.
dispose
();
this
.
_onEditorOpened
.
dispose
();
this
.
_onEditorPinned
.
dispose
();
this
.
_onEditorUnpinned
.
dispose
();
dispose
(
this
.
toDispose
);
}
}
...
...
@@ -513,10 +530,7 @@ export class EditorStacksModel implements IEditorStacksModel {
this
.
_onGroupActivated
=
new
Emitter
<
EditorGroup
>
();
this
.
_onGroupMoved
=
new
Emitter
<
EditorGroup
>
();
this
.
toDispose
.
push
(
this
.
_onGroupOpened
);
this
.
toDispose
.
push
(
this
.
_onGroupClosed
);
this
.
toDispose
.
push
(
this
.
_onGroupActivated
);
this
.
toDispose
.
push
(
this
.
_onGroupMoved
);
this
.
toDispose
.
push
(
this
.
_onGroupOpened
,
this
.
_onGroupClosed
,
this
.
_onGroupActivated
,
this
.
_onGroupMoved
);
this
.
load
();
this
.
registerListeners
();
...
...
src/vs/workbench/test/common/editor/editorStacksModel.test.ts
浏览文件 @
156f3c59
...
...
@@ -40,6 +40,7 @@ interface GroupEvents {
closed
:
EditorInput
[];
pinned
:
EditorInput
[];
unpinned
:
EditorInput
[];
moved
:
EditorInput
[];
}
function
modelListener
(
model
:
IEditorStacksModel
):
ModelEvents
{
...
...
@@ -64,7 +65,8 @@ function groupListener(group: IEditorGroup): GroupEvents {
closed
:
[],
activated
:
[],
pinned
:
[],
unpinned
:
[]
unpinned
:
[],
moved
:
[]
};
group
.
onEditorOpened
(
e
=>
groupEvents
.
opened
.
push
(
e
));
...
...
@@ -72,6 +74,7 @@ function groupListener(group: IEditorGroup): GroupEvents {
group
.
onEditorActivated
(
e
=>
groupEvents
.
activated
.
push
(
e
));
group
.
onEditorPinned
(
e
=>
groupEvents
.
pinned
.
push
(
e
));
group
.
onEditorUnpinned
(
e
=>
groupEvents
.
unpinned
.
push
(
e
));
group
.
onEditorMoved
(
e
=>
groupEvents
.
moved
.
push
(
e
));
return
groupEvents
;
}
...
...
@@ -595,6 +598,50 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
group
.
count
,
0
);
});
test
(
'
Stack - Multiple Editors - move editor
'
,
function
()
{
const
model
=
create
();
const
group
=
model
.
openGroup
(
'
group
'
);
const
events
=
groupListener
(
group
);
const
input1
=
input
();
const
input2
=
input
();
const
input3
=
input
();
const
input4
=
input
();
const
input5
=
input
();
group
.
openEditor
(
input1
,
{
pinned
:
true
,
active
:
true
});
group
.
openEditor
(
input2
,
{
pinned
:
true
,
active
:
true
});
group
.
moveEditor
(
input1
,
1
);
assert
.
equal
(
events
.
moved
[
0
],
input1
);
assert
.
equal
(
group
.
getEditors
()[
0
],
input2
);
assert
.
equal
(
group
.
getEditors
()[
1
],
input1
);
group
.
setActive
(
input1
);
group
.
openEditor
(
input3
,
{
pinned
:
true
,
active
:
true
});
group
.
openEditor
(
input4
,
{
pinned
:
true
,
active
:
true
});
group
.
openEditor
(
input5
,
{
pinned
:
true
,
active
:
true
});
group
.
moveEditor
(
input4
,
0
);
assert
.
equal
(
events
.
moved
[
1
],
input4
);
assert
.
equal
(
group
.
getEditors
()[
0
],
input4
);
assert
.
equal
(
group
.
getEditors
()[
1
],
input2
);
assert
.
equal
(
group
.
getEditors
()[
2
],
input1
);
assert
.
equal
(
group
.
getEditors
()[
3
],
input3
);
assert
.
equal
(
group
.
getEditors
()[
4
],
input5
);
group
.
moveEditor
(
input4
,
3
);
group
.
moveEditor
(
input2
,
1
);
assert
.
equal
(
group
.
getEditors
()[
0
],
input1
);
assert
.
equal
(
group
.
getEditors
()[
1
],
input2
);
assert
.
equal
(
group
.
getEditors
()[
2
],
input3
);
assert
.
equal
(
group
.
getEditors
()[
3
],
input4
);
assert
.
equal
(
group
.
getEditors
()[
4
],
input5
);
});
test
(
'
Stack - Multiple Editors - Pinned & Non Active
'
,
function
()
{
const
model
=
create
();
const
group
=
model
.
openGroup
(
'
group
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录