Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a2ee9faf
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,发现更多精彩内容 >>
提交
a2ee9faf
编写于
5月 04, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more real world tests and fixes
上级
a2041dde
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
151 addition
and
25 deletion
+151
-25
src/vs/workbench/common/editor/editorStacksModel.ts
src/vs/workbench/common/editor/editorStacksModel.ts
+11
-4
src/vs/workbench/test/common/editorStacksModel.test.ts
src/vs/workbench/test/common/editorStacksModel.test.ts
+140
-21
未找到文件。
src/vs/workbench/common/editor/editorStacksModel.ts
浏览文件 @
a2ee9faf
...
...
@@ -14,6 +14,7 @@ export interface IEditorGroup {
activeEditor
:
EditorInput
;
previewEditor
:
EditorInput
;
count
:
number
;
onEditorActivated
:
Event
<
EditorInput
>
;
onEditorOpened
:
Event
<
EditorInput
>
;
...
...
@@ -112,6 +113,10 @@ export class EditorGroup implements IEditorGroup {
this
.
_onEditorUnpinned
=
new
Emitter
<
EditorInput
>
();
}
public
get
count
():
number
{
return
this
.
editors
.
length
;
}
public
get
onEditorActivated
():
Event
<
EditorInput
>
{
return
this
.
_onEditorActivated
.
event
;
}
...
...
@@ -155,7 +160,7 @@ export class EditorGroup implements IEditorGroup {
public
openEditor
(
editor
:
EditorInput
,
options
?:
IEditorOpenOptions
):
void
{
const
index
=
this
.
indexOf
(
editor
);
const
makeActive
=
(
options
&&
options
.
active
)
||
!
this
.
activeEditor
;
const
makeActive
=
(
options
&&
options
.
active
)
||
!
this
.
activeEditor
||
this
.
matches
(
this
.
preview
,
this
.
activeEditor
)
;
const
makePinned
=
options
&&
options
.
pinned
;
// New editor
...
...
@@ -182,11 +187,13 @@ export class EditorGroup implements IEditorGroup {
// Handle preview
if
(
!
makePinned
)
{
if
(
this
.
preview
)
{
const
indexOfPreview
=
this
.
indexOf
(
this
.
preview
);
this
.
closeEditor
(
this
.
preview
);
this
.
splice
(
indexOfPreview
,
false
,
editor
);
}
this
.
preview
=
editor
;
this
.
splice
(
indexOfPreview
,
true
,
editor
);
}
// Event
...
...
src/vs/workbench/test/common/editorStacksModel.test.ts
浏览文件 @
a2ee9faf
...
...
@@ -61,13 +61,15 @@ function groupListener(group: IEditorGroup): GroupEvents {
let
index
=
0
;
class
TestEditorInput
extends
EditorInput
{
public
id
=
index
++
;
constructor
(
public
id
:
string
)
{
super
();
}
public
getId
()
{
return
'
id
'
;
}
public
resolve
()
{
return
null
;
}
}
function
input
():
EditorInput
{
return
new
TestEditorInput
();
function
input
(
id
=
String
(
index
++
)
):
EditorInput
{
return
new
TestEditorInput
(
id
);
}
suite
(
'
Editor Stacks Model
'
,
()
=>
{
...
...
@@ -130,14 +132,14 @@ suite('Editor Stacks Model', () => {
const
group
=
model
.
openGroup
(
'
group
'
);
const
events
=
groupListener
(
group
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
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
.
count
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input1
);
assert
.
equal
(
group
.
isActive
(
input1
),
true
);
...
...
@@ -148,7 +150,7 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
events
.
activated
[
0
],
input1
);
group
.
closeEditor
(
input1
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
0
],
input1
);
...
...
@@ -157,7 +159,7 @@ suite('Editor Stacks Model', () => {
const
input2
=
input
();
group
.
openEditor
(
input2
,
{
active
:
true
,
pinned
:
false
});
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input2
);
assert
.
equal
(
group
.
isActive
(
input2
),
true
);
...
...
@@ -168,13 +170,13 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
events
.
activated
[
1
],
input2
);
group
.
closeEditor
(
input2
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
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
.
count
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
1
],
input2
);
...
...
@@ -183,7 +185,7 @@ suite('Editor Stacks Model', () => {
const
input3
=
input
();
group
.
openEditor
(
input3
,
{
active
:
false
,
pinned
:
true
});
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
isActive
(
input3
),
true
);
...
...
@@ -194,7 +196,7 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
events
.
activated
[
2
],
input3
);
group
.
closeEditor
(
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
2
],
input3
);
...
...
@@ -203,7 +205,7 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
events
.
activated
[
2
],
input3
);
group
.
closeEditor
(
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
2
],
input3
);
...
...
@@ -212,7 +214,7 @@ suite('Editor Stacks Model', () => {
const
input4
=
input
();
group
.
openEditor
(
input4
);
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input4
);
assert
.
equal
(
group
.
isActive
(
input4
),
true
);
...
...
@@ -223,7 +225,7 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
events
.
activated
[
3
],
input4
);
group
.
closeEditor
(
input4
);
assert
.
equal
(
group
.
getEditors
().
length
,
0
);
assert
.
equal
(
group
.
count
,
0
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
0
);
assert
.
equal
(
group
.
activeEditor
,
void
0
);
assert
.
equal
(
events
.
closed
[
3
],
input4
);
...
...
@@ -243,7 +245,7 @@ suite('Editor Stacks Model', () => {
group
.
openEditor
(
input2
,
{
pinned
:
true
,
active
:
true
});
group
.
openEditor
(
input3
,
{
pinned
:
true
,
active
:
true
});
assert
.
equal
(
group
.
getEditors
().
length
,
3
);
assert
.
equal
(
group
.
count
,
3
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
3
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
isActive
(
input1
),
false
);
...
...
@@ -299,7 +301,7 @@ suite('Editor Stacks Model', () => {
group
.
openEditor
(
input2
,
{
pinned
:
true
});
group
.
openEditor
(
input3
,
{
pinned
:
true
});
assert
.
equal
(
group
.
getEditors
().
length
,
3
);
assert
.
equal
(
group
.
count
,
3
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
3
);
assert
.
equal
(
group
.
activeEditor
,
input1
);
assert
.
equal
(
group
.
isActive
(
input1
),
true
);
...
...
@@ -332,7 +334,7 @@ suite('Editor Stacks Model', () => {
group
.
openEditor
(
input2
);
// overwrites preview
group
.
openEditor
(
input3
);
// overwrites preview
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
getEditors
(
true
).
length
,
1
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
isActive
(
input3
),
true
);
...
...
@@ -400,6 +402,7 @@ suite('Editor Stacks Model', () => {
group
.
openEditor
(
input3
,
{
pinned
:
false
,
active
:
true
});
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
count
,
3
);
group
.
pin
(
input3
);
...
...
@@ -408,6 +411,7 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
group
.
isPreview
(
input3
),
false
);
assert
.
equal
(
group
.
isActive
(
input3
),
true
);
assert
.
equal
(
events
.
pinned
[
0
],
input3
);
assert
.
equal
(
group
.
count
,
3
);
group
.
unpin
(
input1
);
...
...
@@ -416,21 +420,24 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
group
.
isPreview
(
input1
),
true
);
assert
.
equal
(
group
.
isActive
(
input1
),
false
);
assert
.
equal
(
events
.
unpinned
[
0
],
input1
);
assert
.
equal
(
group
.
count
,
3
);
group
.
unpin
(
input2
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
2
);
// 2 previews got merged into one
assert
.
equal
(
group
.
count
,
2
);
// 2 previews got merged into one
assert
.
equal
(
group
.
getEditors
()[
0
],
input2
);
assert
.
equal
(
group
.
getEditors
()[
1
],
input3
);
assert
.
equal
(
events
.
closed
[
0
],
input1
);
assert
.
equal
(
group
.
count
,
2
);
group
.
unpin
(
input3
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
getEditors
().
length
,
1
);
// pinning replaced the preview
assert
.
equal
(
group
.
count
,
1
);
// pinning replaced the preview
assert
.
equal
(
group
.
getEditors
()[
0
],
input3
);
assert
.
equal
(
events
.
closed
[
1
],
input2
);
assert
.
equal
(
group
.
count
,
1
);
});
test
(
'
Stack - Multiple Editors - closing picks next from MRU list
'
,
function
()
{
...
...
@@ -452,35 +459,147 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
group
.
activeEditor
,
input5
);
assert
.
equal
(
group
.
getEditors
(
true
)[
0
],
input5
);
assert
.
equal
(
group
.
count
,
5
);
group
.
closeEditor
(
input5
);
assert
.
equal
(
group
.
activeEditor
,
input4
);
assert
.
equal
(
events
.
activated
[
5
],
input4
);
assert
.
equal
(
group
.
count
,
4
);
group
.
setActive
(
input1
);
group
.
setActive
(
input4
);
group
.
closeEditor
(
input4
);
assert
.
equal
(
group
.
activeEditor
,
input1
);
assert
.
equal
(
group
.
count
,
3
);
group
.
closeEditor
(
input1
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
count
,
2
);
group
.
setActive
(
input2
);
group
.
closeEditor
(
input2
);
assert
.
equal
(
group
.
activeEditor
,
input3
);
assert
.
equal
(
group
.
count
,
1
);
group
.
closeEditor
(
input3
);
assert
.
ok
(
!
group
.
activeEditor
);
assert
.
equal
(
group
.
count
,
0
);
});
test
(
'
Stack - Multiple Editors - real user example
'
,
function
()
{
const
model
=
create
();
const
group
=
model
.
openGroup
(
'
group
'
);
// [] -> /index.html/
const
indexHtml
=
input
(
'
index.html
'
);
group
.
openEditor
(
indexHtml
);
assert
.
equal
(
group
.
activeEditor
,
indexHtml
);
assert
.
equal
(
group
.
previewEditor
,
indexHtml
);
assert
.
equal
(
group
.
getEditors
()[
0
],
indexHtml
);
assert
.
equal
(
group
.
count
,
1
);
// /index.html/ -> /style.css/
const
styleCss
=
input
(
'
style.css
'
);
group
.
openEditor
(
styleCss
);
assert
.
equal
(
group
.
activeEditor
,
styleCss
);
assert
.
equal
(
group
.
previewEditor
,
styleCss
);
assert
.
equal
(
group
.
getEditors
()[
0
],
styleCss
);
assert
.
equal
(
group
.
count
,
1
);
// /style.css/ -> [/style.css/, test.js]
const
testJs
=
input
(
'
test.js
'
);
group
.
openEditor
(
testJs
,
{
active
:
true
,
pinned
:
true
});
assert
.
equal
(
group
.
previewEditor
,
styleCss
);
assert
.
equal
(
group
.
activeEditor
,
testJs
);
assert
.
equal
(
group
.
isPreview
(
styleCss
),
true
);
assert
.
equal
(
group
.
isPinned
(
testJs
),
true
);
assert
.
equal
(
group
.
getEditors
()[
0
],
styleCss
);
assert
.
equal
(
group
.
getEditors
()[
1
],
testJs
);
assert
.
equal
(
group
.
count
,
2
);
// [/style.css/, test.js] -> [/indexHtml/, test.js]
group
.
openEditor
(
indexHtml
,
{
active
:
true
});
assert
.
equal
(
group
.
activeEditor
,
indexHtml
);
assert
.
equal
(
group
.
previewEditor
,
indexHtml
);
assert
.
equal
(
group
.
isPreview
(
indexHtml
),
true
);
assert
.
equal
(
group
.
isPinned
(
testJs
),
true
);
assert
.
equal
(
group
.
getEditors
()[
0
],
indexHtml
);
assert
.
equal
(
group
.
getEditors
()[
1
],
testJs
);
assert
.
equal
(
group
.
count
,
2
);
// make test.js active
group
.
setActive
(
testJs
);
assert
.
equal
(
group
.
activeEditor
,
testJs
);
assert
.
equal
(
group
.
isActive
(
testJs
),
true
);
assert
.
equal
(
group
.
count
,
2
);
// [/indexHtml/, test.js] -> [indexHtml, test.js]
group
.
pin
(
indexHtml
);
assert
.
equal
(
group
.
isPinned
(
indexHtml
),
true
);
assert
.
equal
(
group
.
isPreview
(
indexHtml
),
false
);
assert
.
equal
(
group
.
activeEditor
,
testJs
);
// [indexHtml, test.js] -> [indexHtml, test.js, file.ts]
const
fileTs
=
input
(
'
file.ts
'
);
group
.
openEditor
(
fileTs
,
{
active
:
true
,
pinned
:
true
});
assert
.
equal
(
group
.
isPinned
(
fileTs
),
true
);
assert
.
equal
(
group
.
isPreview
(
fileTs
),
false
);
assert
.
equal
(
group
.
count
,
3
);
assert
.
equal
(
group
.
activeEditor
,
fileTs
);
// [indexHtml, test.js, file.ts] -> [indexHtml, test.js, /file.ts/]
group
.
unpin
(
fileTs
);
assert
.
equal
(
group
.
count
,
3
);
assert
.
equal
(
group
.
isPinned
(
fileTs
),
false
);
assert
.
equal
(
group
.
isPreview
(
fileTs
),
true
);
assert
.
equal
(
group
.
activeEditor
,
fileTs
);
// [indexHtml, test.js, /file.ts/] -> [indexHtml, test.js, /other.ts/]
const
otherTs
=
input
(
'
other.ts
'
);
group
.
openEditor
(
otherTs
,
{
active
:
true
});
assert
.
equal
(
group
.
count
,
3
);
assert
.
equal
(
group
.
activeEditor
,
otherTs
);
assert
.
equal
(
group
.
getEditors
()[
0
],
indexHtml
);
assert
.
equal
(
group
.
getEditors
()[
1
],
testJs
);
assert
.
equal
(
group
.
getEditors
()[
2
],
otherTs
);
// make index.html active
group
.
setActive
(
indexHtml
);
assert
.
equal
(
group
.
activeEditor
,
indexHtml
);
// [indexHtml, test.js, /file.ts/] -> [test.js, /other.ts/]
group
.
closeEditor
(
indexHtml
);
assert
.
equal
(
group
.
count
,
2
);
assert
.
equal
(
group
.
activeEditor
,
otherTs
);
assert
.
equal
(
group
.
getEditors
()[
0
],
testJs
);
assert
.
equal
(
group
.
getEditors
()[
1
],
otherTs
);
// [test.js, /other.ts/] -> [test.js]
group
.
closeEditor
(
otherTs
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
activeEditor
,
testJs
);
assert
.
equal
(
group
.
getEditors
()[
0
],
testJs
);
// [test.js] -> /test.js/
group
.
unpin
(
testJs
);
assert
.
equal
(
group
.
count
,
1
);
assert
.
equal
(
group
.
activeEditor
,
testJs
);
assert
.
equal
(
group
.
getEditors
()[
0
],
testJs
);
assert
.
equal
(
group
.
isPinned
(
testJs
),
false
);
assert
.
equal
(
group
.
isPreview
(
testJs
),
true
);
// /test.js/ -> []
group
.
closeEditor
(
testJs
);
assert
.
equal
(
group
.
count
,
0
);
assert
.
equal
(
group
.
activeEditor
,
null
);
assert
.
equal
(
group
.
previewEditor
,
null
);
});
// TODO Open to the left (set DEFAULT_OPEN_EDITOR_DIRECTION)
// TODO complex working sample covering all with comments
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录