Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
30499c23
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,发现更多精彩内容 >>
提交
30499c23
编写于
5月 31, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grid: getNeighborViews
上级
1815c1dc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
136 addition
and
43 deletion
+136
-43
src/vs/base/browser/ui/grid/grid.ts
src/vs/base/browser/ui/grid/grid.ts
+39
-43
src/vs/base/test/browser/ui/grid/grid.test.ts
src/vs/base/test/browser/ui/grid/grid.test.ts
+97
-0
未找到文件。
src/vs/base/browser/ui/grid/grid.ts
浏览文件 @
30499c23
...
...
@@ -42,7 +42,7 @@ function getNode<T extends IView>(node: GridNode<T>, location: number[]): GridNo
return
getNode
(
node
.
children
[
index
],
rest
);
}
function
getViews
<
T
extends
IView
>
(
node
:
GridNode
<
T
>
):
T
[]
{
function
get
All
Views
<
T
extends
IView
>
(
node
:
GridNode
<
T
>
):
T
[]
{
const
result
:
T
[]
=
[];
function
collectViews
(
node
:
GridNode
<
T
>
):
void
{
...
...
@@ -246,61 +246,57 @@ export class Grid<T extends IView> implements IDisposable {
getNeighborViews
(
view
:
T
,
direction
:
Direction
,
wrap
:
boolean
=
false
):
T
[]
{
const
location
=
this
.
getViewLocation
(
view
);
const
locationOrientation
=
getLocationOrientation
(
this
.
orientation
,
location
);
const
directionOrientation
=
getDirectionOrientation
(
direction
);
const
diff
=
direction
===
Direction
.
Up
||
direction
===
Direction
.
Left
?
-
1
:
1
;
const
root
=
this
.
getViews
();
const
[
parentLocation
,
index
]
=
tail2
(
location
);
const
result
=
this
.
_getNeighborViews
(
location
,
direction
);
if
(
locationOrientation
===
directionOrientation
)
{
const
parent
=
getNode
(
root
,
parentLocation
);
if
(
!
isGridBranchNode
(
parent
))
{
throw
new
Error
(
'
Invalid location
'
);
if
(
result
.
length
>
0
||
!
wrap
)
{
return
result
;
}
let
neighborIndex
=
index
+
diff
;
const
directionOrientation
=
getDirectionOrientation
(
direction
);
const
ancestorLocation
=
location
.
slice
(
0
,
directionOrientation
===
this
.
orientation
?
0
:
1
);
const
root
=
this
.
getViews
();
const
ancestorParent
=
getNode
(
root
,
ancestorLocation
);
if
(
!
wrap
&&
(
neighborIndex
===
-
1
||
neighborIndex
>=
parent
.
children
.
length
))
{
return
[
];
if
(
!
isGridBranchNode
(
ancestorParent
))
{
return
[
ancestorParent
.
view
];
}
neighborIndex
=
neighborIndex
%
parent
.
children
.
length
;
const
neighbor
=
parent
.
children
[
neighborIndex
];
return
getViews
(
neighbor
);
if
(
direction
===
Direction
.
Up
||
direction
===
Direction
.
Left
)
{
return
getAllViews
(
ancestorParent
.
children
[
ancestorParent
.
children
.
length
-
1
]);
}
else
{
if
(
parentLocation
.
length
===
0
)
{
return
getAllViews
(
ancestorParent
.
children
[
0
]);
}
}
_getNeighborViews
(
location
:
number
[],
direction
:
Direction
):
T
[]
{
if
(
location
.
length
===
0
)
{
return
[];
}
const
[
grandParentLocation
,
parentIndex
]
=
tail2
(
parentLocation
);
const
grandParent
=
getNode
(
root
,
grandParentLocation
);
const
locationOrientation
=
getLocationOrientation
(
this
.
orientation
,
location
);
const
directionOrientation
=
getDirectionOrientation
(
direction
);
const
[
parentLocation
,
index
]
=
tail2
(
location
);
if
(
!
isGridBranchNode
(
grandParent
)
)
{
throw
new
Error
(
'
Invalid location
'
);
if
(
locationOrientation
!==
directionOrientation
)
{
return
this
.
_getNeighborViews
(
parentLocation
,
direction
);
}
let
uncleIndex
=
parentIndex
+
diff
;
const
root
=
this
.
getViews
();
const
parent
=
getNode
(
root
,
parentLocation
);
if
(
!
wrap
&&
(
uncleIndex
===
-
1
||
uncleIndex
>=
grandParent
.
children
.
length
))
{
return
[]
;
if
(
!
isGridBranchNode
(
parent
))
{
throw
new
Error
(
'
Invalid location
'
)
;
}
uncleIndex
=
uncleIndex
%
grandParent
.
children
.
length
;
const
uncle
=
grandParent
.
children
[
uncleIndex
];
const
diff
=
direction
===
Direction
.
Up
||
direction
===
Direction
.
Left
?
-
1
:
1
;
let
neighborIndex
=
index
+
diff
;
if
(
!
isGridBranchNode
(
uncle
)
)
{
return
[
uncle
.
view
]
;
if
(
neighborIndex
===
-
1
||
neighborIndex
>=
parent
.
children
.
length
)
{
return
this
.
_getNeighborViews
(
parentLocation
,
direction
)
;
}
const
uncleLocation
=
[...
grandParentLocation
,
uncleIndex
];
const
range
=
this
.
gridview
.
getViewRange
(
location
);
const
cousinIndexes
=
this
.
gridview
.
getChildrenInRange
(
uncleLocation
,
range
);
return
cousinIndexes
.
reduce
((
r
,
i
)
=>
[...
r
,
...
getViews
(
uncle
.
children
[
i
])],
[]
as
T
[]);
}
const
neighbor
=
parent
.
children
[
neighborIndex
];
return
getAllViews
(
neighbor
);
}
private
getViewLocation
(
view
:
T
):
number
[]
{
...
...
src/vs/base/test/browser/ui/grid/grid.test.ts
浏览文件 @
30499c23
...
...
@@ -288,6 +288,103 @@ suite('Grid', function () {
assert
.
deepEqual
(
view2
.
size
,
[
800
,
200
]);
assert
.
deepEqual
(
view4
.
size
,
[
800
,
200
]);
});
test
(
'
getNeighborViews should work on single view layout
'
,
function
()
{
const
view1
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
const
grid
=
new
Grid
(
container
,
view1
);
grid
.
layout
(
800
,
600
);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Up
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Down
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Up
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Right
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Down
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Left
,
true
),
[
view1
]);
});
test
(
'
getNeighborViews should work on simple layout
'
,
function
()
{
const
view1
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
const
grid
=
new
Grid
(
container
,
view1
);
grid
.
layout
(
800
,
600
);
const
view2
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view2
,
Sizing
.
Distribute
,
view1
,
Direction
.
Down
);
const
view3
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view3
,
Sizing
.
Distribute
,
view2
,
Direction
.
Down
);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Up
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Down
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Up
,
true
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Right
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Down
,
true
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Left
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Up
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Down
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Up
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Right
,
true
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Down
,
true
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Left
,
true
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Up
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Down
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Up
,
true
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Right
,
true
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Down
,
true
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Left
,
true
),
[
view3
]);
});
test
(
'
getNeighborViews should work on a complex layout
'
,
function
()
{
const
view1
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
const
grid
=
new
Grid
(
container
,
view1
);
grid
.
layout
(
800
,
600
);
const
view2
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view2
,
Sizing
.
Distribute
,
view1
,
Direction
.
Down
);
const
view3
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view3
,
Sizing
.
Distribute
,
view2
,
Direction
.
Down
);
const
view4
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view4
,
Sizing
.
Distribute
,
view2
,
Direction
.
Right
);
const
view5
=
new
TestView
(
50
,
Number
.
MAX_VALUE
,
50
,
Number
.
MAX_VALUE
);
grid
.
addView
(
view5
,
Sizing
.
Distribute
,
view4
,
Direction
.
Down
);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Up
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Down
),
[
view2
,
view4
,
view5
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view1
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Up
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Right
),
[
view4
,
view5
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Down
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view2
,
Direction
.
Left
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view4
,
Direction
.
Up
),
[
view1
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view4
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view4
,
Direction
.
Down
),
[
view5
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view4
,
Direction
.
Left
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view5
,
Direction
.
Up
),
[
view4
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view5
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view5
,
Direction
.
Down
),
[
view3
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view5
,
Direction
.
Left
),
[
view2
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Up
),
[
view2
,
view4
,
view5
]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Right
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Down
),
[]);
assert
.
deepEqual
(
grid
.
getNeighborViews
(
view3
,
Direction
.
Left
),
[]);
});
});
class
TestSerializableView
extends
TestView
implements
ISerializableView
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录