Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9bab4c5a
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,发现更多精彩内容 >>
提交
9bab4c5a
编写于
1月 17, 2019
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor list focus navigation
上级
3de2f5d0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
17 deletion
+82
-17
src/vs/base/browser/ui/list/listWidget.ts
src/vs/base/browser/ui/list/listWidget.ts
+82
-17
未找到文件。
src/vs/base/browser/ui/list/listWidget.ts
浏览文件 @
9bab4c5a
...
...
@@ -1228,41 +1228,54 @@ export class List<T> implements ISpliceable<T>, IDisposable {
this
.
focus
.
set
(
indexes
,
browserEvent
);
}
focusNext
(
n
=
1
,
loop
=
false
,
browserEvent
?:
UIEvent
):
void
{
focusNext
(
n
=
1
,
loop
=
false
,
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
if
(
this
.
length
===
0
)
{
return
;
}
const
focus
=
this
.
focus
.
get
();
let
index
=
focus
.
length
>
0
?
focus
[
0
]
+
n
:
0
;
this
.
setFocus
(
loop
?
[
index
%
this
.
length
]
:
[
Math
.
min
(
index
,
this
.
length
-
1
)],
browserEvent
);
const
index
=
this
.
findNextIndex
(
focus
.
length
>
0
?
focus
[
0
]
+
n
:
0
,
loop
,
filter
);
if
(
index
>
-
1
)
{
this
.
setFocus
([
index
],
browserEvent
);
}
}
focusPrevious
(
n
=
1
,
loop
=
false
,
browserEvent
?:
UIEvent
):
void
{
focusPrevious
(
n
=
1
,
loop
=
false
,
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
if
(
this
.
length
===
0
)
{
return
;
}
const
focus
=
this
.
focus
.
get
();
let
index
=
focus
.
length
>
0
?
focus
[
0
]
-
n
:
0
;
if
(
loop
&&
index
<
0
)
{
index
=
(
this
.
length
+
(
index
%
this
.
length
))
%
this
.
length
;
}
this
.
setFocus
([
Math
.
max
(
index
,
0
)],
browserEvent
);
const
index
=
this
.
findPreviousIndex
(
focus
.
length
>
0
?
focus
[
0
]
-
n
:
0
,
loop
,
filter
);
if
(
index
>
-
1
)
{
this
.
setFocus
([
index
],
browserEvent
);
}
}
focusNextPage
(
browserEvent
?:
UIEvent
):
void
{
focusNextPage
(
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
let
lastPageIndex
=
this
.
view
.
indexAt
(
this
.
view
.
getScrollTop
()
+
this
.
view
.
renderHeight
);
lastPageIndex
=
lastPageIndex
===
0
?
0
:
lastPageIndex
-
1
;
const
lastPageElement
=
this
.
view
.
element
(
lastPageIndex
);
const
currentlyFocusedElement
=
this
.
getFocusedElements
()[
0
];
if
(
currentlyFocusedElement
!==
lastPageElement
)
{
this
.
setFocus
([
lastPageIndex
],
browserEvent
);
const
lastGoodPageIndex
=
this
.
findPreviousIndex
(
lastPageIndex
,
false
,
filter
);
if
(
lastGoodPageIndex
>
-
1
&&
currentlyFocusedElement
!==
this
.
view
.
element
(
lastGoodPageIndex
))
{
this
.
setFocus
([
lastGoodPageIndex
],
browserEvent
);
}
else
{
this
.
setFocus
([
lastPageIndex
],
browserEvent
);
}
}
else
{
const
previousScrollTop
=
this
.
view
.
getScrollTop
();
this
.
view
.
setScrollTop
(
previousScrollTop
+
this
.
view
.
renderHeight
-
this
.
view
.
elementHeight
(
lastPageIndex
));
if
(
this
.
view
.
getScrollTop
()
!==
previousScrollTop
)
{
// Let the scroll event listener run
setTimeout
(()
=>
this
.
focusNextPage
(
browserEvent
),
0
);
setTimeout
(()
=>
this
.
focusNextPage
(
browserEvent
,
filter
),
0
);
}
}
}
focusPreviousPage
(
browserEvent
?:
UIEvent
):
void
{
focusPreviousPage
(
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
let
firstPageIndex
:
number
;
const
scrollTop
=
this
.
view
.
getScrollTop
();
...
...
@@ -1276,26 +1289,78 @@ export class List<T> implements ISpliceable<T>, IDisposable {
const
currentlyFocusedElement
=
this
.
getFocusedElements
()[
0
];
if
(
currentlyFocusedElement
!==
firstPageElement
)
{
this
.
setFocus
([
firstPageIndex
],
browserEvent
);
const
firstGoodPageIndex
=
this
.
findNextIndex
(
firstPageIndex
,
false
,
filter
);
if
(
firstGoodPageIndex
>
-
1
&&
currentlyFocusedElement
!==
this
.
view
.
element
(
firstGoodPageIndex
))
{
this
.
setFocus
([
firstGoodPageIndex
],
browserEvent
);
}
else
{
this
.
setFocus
([
firstPageIndex
],
browserEvent
);
}
}
else
{
const
previousScrollTop
=
scrollTop
;
this
.
view
.
setScrollTop
(
scrollTop
-
this
.
view
.
renderHeight
);
if
(
this
.
view
.
getScrollTop
()
!==
previousScrollTop
)
{
// Let the scroll event listener run
setTimeout
(()
=>
this
.
focusPreviousPage
(
browserEvent
),
0
);
setTimeout
(()
=>
this
.
focusPreviousPage
(
browserEvent
,
filter
),
0
);
}
}
}
focusLast
(
browserEvent
?:
UIEvent
):
void
{
focusLast
(
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
if
(
this
.
length
===
0
)
{
return
;
}
this
.
setFocus
([
this
.
length
-
1
],
browserEvent
);
const
index
=
this
.
findPreviousIndex
(
this
.
length
-
1
,
false
,
filter
);
if
(
index
>
-
1
)
{
this
.
setFocus
([
index
],
browserEvent
);
}
}
focusFirst
(
browserEvent
?:
UIEvent
):
void
{
focusFirst
(
browserEvent
?:
UIEvent
,
filter
?:
(
element
:
T
)
=>
boolean
):
void
{
if
(
this
.
length
===
0
)
{
return
;
}
this
.
setFocus
([
0
],
browserEvent
);
const
index
=
this
.
findNextIndex
(
0
,
false
,
filter
);
if
(
index
>
-
1
)
{
this
.
setFocus
([
index
],
browserEvent
);
}
}
private
findNextIndex
(
index
:
number
,
loop
=
false
,
filter
?:
(
element
:
T
)
=>
boolean
):
number
{
for
(
let
i
=
0
;
i
<
this
.
length
;
i
++
)
{
if
(
index
>=
this
.
length
&&
!
loop
)
{
return
-
1
;
}
index
=
index
%
this
.
length
;
if
(
!
filter
||
filter
(
this
.
element
(
index
)))
{
return
index
;
}
index
++
;
}
return
-
1
;
}
private
findPreviousIndex
(
index
:
number
,
loop
=
false
,
filter
?:
(
element
:
T
)
=>
boolean
):
number
{
for
(
let
i
=
0
;
i
<
this
.
length
;
i
++
)
{
if
(
index
<
0
&&
!
loop
)
{
return
-
1
;
}
index
=
(
this
.
length
+
(
index
%
this
.
length
))
%
this
.
length
;
if
(
!
filter
||
filter
(
this
.
element
(
index
)))
{
return
index
;
}
index
--
;
}
return
-
1
;
}
getFocus
():
number
[]
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录