Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a8b78649
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,发现更多精彩内容 >>
提交
a8b78649
编写于
5月 04, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests for editor actions and fixes for it
上级
466d6549
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
190 addition
and
20 deletion
+190
-20
src/vs/workbench/common/editor/editorStacksModel.ts
src/vs/workbench/common/editor/editorStacksModel.ts
+16
-13
src/vs/workbench/test/common/editorStackModel.test.ts
src/vs/workbench/test/common/editorStackModel.test.ts
+174
-7
未找到文件。
src/vs/workbench/common/editor/editorStacksModel.ts
浏览文件 @
a8b78649
...
...
@@ -23,6 +23,7 @@ export interface IEditorGroup {
getEditors
(
mru
?:
boolean
):
EditorInput
[];
openEditor
(
editor
:
EditorInput
,
options
?:
IEditorOpenOptions
):
void
;
closeEditor
(
editor
:
EditorInput
):
void
;
setActive
(
editor
:
EditorInput
):
void
;
isActive
(
editor
:
EditorInput
):
boolean
;
isPreview
(
editor
:
EditorInput
):
boolean
;
...
...
@@ -137,7 +138,7 @@ export class EditorGroup implements IEditorGroup {
}
public
isActive
(
editor
:
EditorInput
):
boolean
{
return
this
.
active
&&
this
.
active
.
matches
(
editor
);
return
!!
this
.
active
&&
this
.
active
.
matches
(
editor
);
}
public
get
previewEditor
():
EditorInput
{
...
...
@@ -145,16 +146,17 @@ export class EditorGroup implements IEditorGroup {
}
public
isPreview
(
editor
:
EditorInput
):
boolean
{
return
this
.
preview
&&
this
.
preview
.
matches
(
editor
);
return
!!
this
.
preview
&&
this
.
preview
.
matches
(
editor
);
}
public
openEditor
(
editor
:
EditorInput
,
options
?:
IEditorOpenOptions
):
void
{
const
index
=
this
.
indexOf
(
editor
);
const
indexOfActive
=
this
.
indexOf
(
this
.
active
);
const
indexOfPreview
=
this
.
indexOf
(
this
.
preview
);
let
oldPreviewToClose
:
EditorInput
;
const
makeActive
=
options
&&
options
.
active
;
const
oldPreviewIsActive
=
this
.
preview
&&
this
.
preview
.
matches
(
this
.
activeEditor
);
const
makeActive
=
(
options
&&
options
.
active
)
||
!
this
.
activeEditor
;
// make active if this is the first editor to open
const
makePinned
=
options
&&
options
.
pinned
;
// New editor
...
...
@@ -175,9 +177,9 @@ export class EditorGroup implements IEditorGroup {
}
}
//
Otherwise replace preview one
else
{
oldPreviewToClose
=
this
.
preview
;
//
Handle preview
if
(
!
makePinned
)
{
this
.
closeEditor
(
this
.
preview
)
;
this
.
preview
=
editor
;
this
.
splice
(
indexOfPreview
,
true
,
editor
);
}
...
...
@@ -185,13 +187,10 @@ export class EditorGroup implements IEditorGroup {
// Event
this
.
_onEditorOpened
.
fire
(
editor
);
//
Mak
e active
if
(
makeActive
)
{
//
Handl
e active
if
(
makeActive
||
oldPreviewIsActive
)
{
this
.
setActive
(
editor
);
}
// Close old preview editor if any
this
.
closeEditor
(
oldPreviewToClose
);
}
// Existing editor
...
...
@@ -309,7 +308,11 @@ export class EditorGroup implements IEditorGroup {
private
splice
(
index
:
number
,
del
:
boolean
,
editor
?:
EditorInput
):
void
{
// Perform on editors array
this
.
editors
.
splice
(
index
,
del
?
1
:
0
,
editor
);
const
args
:
any
[]
=
[
index
,
del
];
if
(
editor
)
{
args
.
push
(
editor
);
}
this
.
editors
.
splice
.
apply
(
this
.
editors
,
args
);
// Add: make it LRU editor
if
(
!
del
&&
editor
)
{
...
...
src/vs/workbench/test/common/editorStackModel.test.ts
浏览文件 @
a8b78649
...
...
@@ -7,36 +7,71 @@
import
*
as
assert
from
'
assert
'
;
import
{
EditorStacksModel
,
IEditorStacksModel
,
IEditorGroup
}
from
'
vs/workbench/common/editor/editorStacksModel
'
;
import
{
EditorInput
}
from
'
vs/workbench/common/editor
'
;
function
create
():
IEditorStacksModel
{
return
new
EditorStacksModel
();
}
interface
Group
Events
{
interface
Model
Events
{
opened
:
IEditorGroup
[];
activated
:
IEditorGroup
[];
closed
:
IEditorGroup
[];
}
function
groupListener
(
model
:
IEditorStacksModel
):
GroupEvents
{
const
groupEvents
=
{
interface
GroupEvents
{
opened
:
EditorInput
[];
activated
:
EditorInput
[];
closed
:
EditorInput
[];
pinned
:
EditorInput
[];
unpinned
:
EditorInput
[];
}
function
modelListener
(
model
:
IEditorStacksModel
):
ModelEvents
{
const
modelEvents
=
{
opened
:
[],
activated
:
[],
closed
:
[]
};
model
.
onGroupOpened
(
g
=>
groupEvents
.
opened
.
push
(
g
));
model
.
onGroupActivated
(
g
=>
groupEvents
.
activated
.
push
(
g
));
model
.
onGroupClosed
(
g
=>
groupEvents
.
closed
.
push
(
g
));
model
.
onGroupOpened
(
g
=>
modelEvents
.
opened
.
push
(
g
));
model
.
onGroupActivated
(
g
=>
modelEvents
.
activated
.
push
(
g
));
model
.
onGroupClosed
(
g
=>
modelEvents
.
closed
.
push
(
g
));
return
modelEvents
;
}
function
groupListener
(
group
:
IEditorGroup
):
GroupEvents
{
const
groupEvents
=
{
opened
:
[],
closed
:
[],
activated
:
[],
pinned
:
[],
unpinned
:
[]
};
group
.
onEditorOpened
(
e
=>
groupEvents
.
opened
.
push
(
e
));
group
.
onEditorClosed
(
e
=>
groupEvents
.
closed
.
push
(
e
));
group
.
onEditorActivated
(
e
=>
groupEvents
.
activated
.
push
(
e
));
group
.
onEditorPinned
(
e
=>
groupEvents
.
pinned
.
push
(
e
));
group
.
onEditorUnpinned
(
e
=>
groupEvents
.
unpinned
.
push
(
e
));
return
groupEvents
;
}
class
TestEditorInput
extends
EditorInput
{
}
function
input
():
EditorInput
{
return
new
TestEditorInput
();
}
suite
(
'
Editor Stacks Model
'
,
()
=>
{
test
(
'
Groups
'
,
function
()
{
const
model
=
create
();
const
events
=
group
Listener
(
model
);
const
events
=
model
Listener
(
model
);
assert
.
equal
(
model
.
groups
.
length
,
0
);
assert
.
ok
(
!
model
.
activeGroup
);
...
...
@@ -75,4 +110,136 @@ suite('Editor Stacks Model', () => {
model
.
closeGroup
(
fourth
);
assert
.
equal
(
second
,
model
.
activeGroup
);
});
test
(
'
Stack - One Editor
'
,
function
()
{
const
model
=
create
();
const
group
=
model
.
openGroup
(
'
first
'
);
const
events
=
groupListener
(
group
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
// Active && Pinned
const
input1
=
input
();
group
.
openEditor
(
input1
,
{
active
:
true
,
pinned
:
true
});
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input1
);
assert
.
equal
(
group
.
isActive
(
input1
),
true
);
assert
.
equal
(
group
.
isPreview
(
input1
),
false
);
assert
.
equal
(
group
.
isPinned
(
input1
),
true
);
assert
.
equal
(
events
.
opened
[
0
],
input1
);
assert
.
equal
(
events
.
activated
[
0
],
input1
);
group
.
closeEditor
(
input1
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
0
],
input1
);
// Active && Preview
const
input2
=
input
();
group
.
openEditor
(
input2
,
{
active
:
true
,
pinned
:
false
});
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input2
);
assert
.
equal
(
group
.
isActive
(
input2
),
true
);
assert
.
equal
(
group
.
isPreview
(
input2
),
true
);
assert
.
equal
(
group
.
isPinned
(
input2
),
false
);
assert
.
equal
(
events
.
opened
[
1
],
input2
);
assert
.
equal
(
events
.
activated
[
1
],
input2
);
group
.
closeEditor
(
input2
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
1
],
input2
);
group
.
closeEditor
(
input2
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
1
],
input2
);
// Nonactive && Pinned => gets active because its first editor
const
input3
=
input
();
group
.
openEditor
(
input3
,
{
active
:
false
,
pinned
:
true
});
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
isActive
(
input3
),
true
);
assert
.
equal
(
group
.
isPreview
(
input3
),
false
);
assert
.
equal
(
group
.
isPinned
(
input3
),
true
);
assert
.
equal
(
events
.
opened
[
2
],
input3
);
assert
.
equal
(
events
.
activated
[
2
],
input3
);
group
.
closeEditor
(
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
2
],
input3
);
assert
.
equal
(
events
.
opened
[
2
],
input3
);
assert
.
equal
(
events
.
activated
[
2
],
input3
);
group
.
closeEditor
(
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
2
],
input3
);
// Nonactive && Preview => gets active because its first editor
const
input4
=
input
();
group
.
openEditor
(
input4
);
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input4
);
assert
.
equal
(
group
.
isActive
(
input4
),
true
);
assert
.
equal
(
group
.
isPreview
(
input4
),
true
);
assert
.
equal
(
group
.
isPinned
(
input4
),
false
);
assert
.
equal
(
events
.
opened
[
3
],
input4
);
assert
.
equal
(
events
.
activated
[
3
],
input4
);
group
.
closeEditor
(
input4
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
3
],
input4
);
});
test
(
'
Stack - Multiple Editors - Preview gets overwritten
'
,
function
()
{
const
model
=
create
();
const
group
=
model
.
openGroup
(
'
first
'
);
const
events
=
groupListener
(
group
);
const
input1
=
input
();
const
input2
=
input
();
const
input3
=
input
();
// Non active, preview
group
.
openEditor
(
input1
);
// becomes active, preview
group
.
openEditor
(
input2
);
// overwrites preview
group
.
openEditor
(
input3
);
// overwrites preview
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
isActive
(
input3
),
true
);
assert
.
equal
(
group
.
isPinned
(
input3
),
false
);
assert
.
equal
(
group
.
isPreview
(
input3
),
true
);
assert
.
equal
(
events
.
opened
[
0
],
input1
);
assert
.
equal
(
events
.
opened
[
1
],
input2
);
assert
.
equal
(
events
.
opened
[
2
],
input3
);
assert
.
equal
(
events
.
closed
[
0
],
input1
);
assert
.
equal
(
events
.
closed
[
1
],
input2
);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录