Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
fd13aebb
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd13aebb
编写于
2月 05, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
list: handle mouse click
上级
7be0d79a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
128 addition
and
35 deletion
+128
-35
src/vs/base/browser/ui/list/list.ts
src/vs/base/browser/ui/list/list.ts
+11
-0
src/vs/base/browser/ui/list/listView.ts
src/vs/base/browser/ui/list/listView.ts
+81
-22
src/vs/base/browser/ui/list/listWidget.ts
src/vs/base/browser/ui/list/listWidget.ts
+36
-13
未找到文件。
src/vs/base/browser/ui/list/list.ts
浏览文件 @
fd13aebb
...
...
@@ -14,3 +14,14 @@ export interface IRenderer<TElement, TTemplateData> {
renderElement
(
element
:
TElement
,
index
:
number
,
templateData
:
TTemplateData
):
void
;
disposeTemplate
(
templateData
:
TTemplateData
):
void
;
}
export
interface
IListElementEvent
<
T
,
E
>
{
element
:
T
;
index
:
number
;
event
:
E
;
}
export
interface
IListMouseEvent
<
T
>
extends
MouseEvent
{
element
:
T
;
index
:
number
;
}
\ No newline at end of file
src/vs/base/browser/ui/list/listView.ts
浏览文件 @
fd13aebb
...
...
@@ -5,14 +5,14 @@
import
{
IScrollable
}
from
'
vs/base/common/scrollable
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
toObject
}
from
'
vs/base/common/objects
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
toObject
,
assign
}
from
'
vs/base/common/objects
'
;
import
{
IDisposable
,
dispose
All
}
from
'
vs/base/common/lifecycle
'
;
import
{
Gesture
}
from
'
vs/base/browser/touch
'
;
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
{
IScrollableElement
}
from
'
vs/base/browser/ui/scrollbar/scrollableElement
'
;
import
{
ScrollableElement
}
from
'
vs/base/browser/ui/scrollbar/impl/scrollableElement
'
;
import
{
RangeMap
,
IRange
}
from
'
./rangeMap
'
;
import
{
IDelegate
,
IRenderer
}
from
'
./list
'
;
import
{
IDelegate
,
IRenderer
,
IListElementEvent
}
from
'
./list
'
;
import
{
RowCache
,
IRow
}
from
'
./rowCache
'
;
import
{
LcsDiff
,
ISequence
}
from
'
vs/base/common/diff/diff
'
;
...
...
@@ -42,7 +42,17 @@ function toSequence<T>(itemRanges: IItemRange<T>[]): ISequence {
};
}
export
class
ListView
<
T
>
implements
IScrollable
{
const
MouseEventTypes
=
[
'
click
'
,
'
dblclick
'
,
'
mouseup
'
,
'
mousedown
'
,
'
mouseover
'
,
'
mousemove
'
,
'
mouseout
'
,
'
contextmenu
'
];
export
class
ListView
<
T
>
implements
IScrollable
,
IDisposable
{
private
items
:
IItem
<
T
>
[];
private
itemId
:
number
;
...
...
@@ -53,12 +63,15 @@ export class ListView<T> implements IScrollable {
private
renderTop
:
number
;
private
renderHeight
:
number
;
private
domNode
:
HTMLElement
;
private
_
domNode
:
HTMLElement
;
private
gesture
:
Gesture
;
private
rowsContainer
:
HTMLElement
;
private
onScroll
:
Emitter
<
IScrollEvent
>
;
private
scrollableElement
:
IScrollableElement
;
private
_onScroll
=
new
Emitter
<
IScrollEvent
>
()
private
toDispose
:
IDisposable
[];
constructor
(
container
:
HTMLElement
,
private
delegate
:
IDelegate
<
T
>
,
...
...
@@ -73,15 +86,14 @@ export class ListView<T> implements IScrollable {
this
.
renderTop
=
0
;
this
.
renderHeight
=
0
;
this
.
domNode
=
document
.
createElement
(
'
div
'
);
this
.
domNode
.
className
=
'
monaco-list
'
;
this
.
domNode
.
tabIndex
=
0
;
this
.
_
domNode
=
document
.
createElement
(
'
div
'
);
this
.
_
domNode
.
className
=
'
monaco-list
'
;
this
.
_
domNode
.
tabIndex
=
0
;
this
.
rowsContainer
=
document
.
createElement
(
'
div
'
);
this
.
rowsContainer
.
className
=
'
monaco-list-rows
'
;
this
.
gesture
=
new
Gesture
(
this
.
rowsContainer
);
this
.
onScroll
=
new
Emitter
<
IScrollEvent
>
();
this
.
scrollableElement
=
new
ScrollableElement
(
this
.
rowsContainer
,
{
forbidTranslate3dUse
:
true
,
scrollable
:
this
,
...
...
@@ -91,12 +103,18 @@ export class ListView<T> implements IScrollable {
saveLastScrollTimeOnClassName
:
'
monaco-list-row
'
});
this
.
domNode
.
appendChild
(
this
.
scrollableElement
.
getDomNode
());
container
.
appendChild
(
this
.
domNode
);
this
.
_domNode
.
appendChild
(
this
.
scrollableElement
.
getDomNode
());
container
.
appendChild
(
this
.
_domNode
);
this
.
toDispose
=
[
this
.
rangeMap
,
this
.
gesture
,
this
.
scrollableElement
,
this
.
_onScroll
];
this
.
layout
();
}
get
domNode
():
HTMLElement
{
return
this
.
_domNode
;
}
splice
(
start
:
number
,
deleteCount
:
number
,
...
elements
:
T
[]):
T
[]
{
const
before
=
this
.
getRenderedItemRanges
();
const
inserted
=
elements
.
map
<
IItem
<
T
>>
(
element
=>
({
...
...
@@ -152,7 +170,7 @@ export class ListView<T> implements IScrollable {
}
layout
(
height
?:
number
):
void
{
this
.
setRenderHeight
(
height
||
DOM
.
getContentHeight
(
this
.
domNode
));
this
.
setRenderHeight
(
height
||
DOM
.
getContentHeight
(
this
.
_
domNode
));
this
.
setScrollTop
(
this
.
renderTop
);
this
.
scrollableElement
.
onElementDimensions
();
this
.
scrollableElement
.
onElementInternalDimensions
();
...
...
@@ -228,6 +246,7 @@ export class ListView<T> implements IScrollable {
const
renderer
=
this
.
renderers
[
item
.
templateId
];
item
.
row
.
domNode
.
style
.
top
=
`
${
this
.
elementTop
(
index
)
}
px`
;
item
.
row
.
domNode
.
style
.
height
=
`
${
item
.
size
}
px`
;
item
.
row
.
domNode
.
setAttribute
(
'
data-index
'
,
`
${
index
}
`
);
renderer
.
renderElement
(
item
.
element
,
index
,
item
.
row
.
templateData
);
}
...
...
@@ -265,24 +284,64 @@ export class ListView<T> implements IScrollable {
this
.
render
(
scrollTop
,
this
.
renderHeight
);
this
.
renderTop
=
scrollTop
;
this
.
onScroll
.
fire
({
vertical
:
true
,
horizontal
:
false
});
this
.
_
onScroll
.
fire
({
vertical
:
true
,
horizontal
:
false
});
}
addScrollListener
(
callback
:
()
=>
void
):
IDisposable
{
return
this
.
onScroll
.
event
(
callback
);
return
this
.
_
onScroll
.
event
(
callback
);
}
// Events
addListener
(
type
:
string
,
handler
:
(
event
:
any
)
=>
void
,
useCapture
?:
boolean
):
IDisposable
{
if
(
MouseEventTypes
.
indexOf
(
type
)
>
-
1
)
{
const
userHandler
=
handler
;
handler
=
(
event
:
MouseEvent
)
=>
{
const
index
=
this
.
getItemIndex
(
event
);
if
(
index
<
0
)
{
return
;
}
const
element
=
this
.
items
[
index
].
element
;
userHandler
(
assign
(
event
,
{
element
,
index
}));
};
}
return
DOM
.
addDisposableListener
(
this
.
domNode
,
type
,
handler
,
useCapture
);
}
private
getItemIndex
(
event
:
MouseEvent
):
number
{
let
target
=
event
.
target
;
while
(
target
instanceof
HTMLElement
&&
target
!==
this
.
rowsContainer
)
{
const
element
=
target
as
HTMLElement
;
const
rawIndex
=
element
.
getAttribute
(
'
data-index
'
);
if
(
rawIndex
)
{
const
index
=
Number
(
rawIndex
);
if
(
!
isNaN
(
index
))
{
return
index
;
}
}
target
=
element
.
parentElement
;
}
return
-
1
;
}
// Dispose
dispose
()
{
this
.
items
=
null
;
if
(
this
.
domNode
&&
this
.
domNode
.
parentElement
)
{
this
.
domNode
.
parentNode
.
removeChild
(
this
.
domNode
);
this
.
domNode
=
null
;
if
(
this
.
_domNode
&&
this
.
_
domNode
.
parentElement
)
{
this
.
_domNode
.
parentNode
.
removeChild
(
this
.
_
domNode
);
this
.
_
domNode
=
null
;
}
this
.
rangeMap
=
dispose
(
this
.
rangeMap
);
this
.
gesture
=
dispose
(
this
.
gesture
);
this
.
scrollableElement
=
dispose
(
this
.
scrollableElement
);
this
.
onScroll
=
dispose
(
this
.
onScroll
);
this
.
toDispose
=
disposeAll
(
this
.
toDispose
);
}
}
src/vs/base/browser/ui/list/listWidget.ts
浏览文件 @
fd13aebb
...
...
@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./list
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
dispose
,
disposeAll
}
from
'
vs/base/common/lifecycle
'
;
import
{
isNumber
}
from
'
vs/base/common/types
'
;
import
{
toggleClass
}
from
'
vs/base/browser/dom
'
;
import
{
IDelegate
,
IRenderer
}
from
'
./list
'
;
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
{
IDelegate
,
IRenderer
,
IListMouseEvent
}
from
'
./list
'
;
import
{
ListView
}
from
'
./listView
'
;
interface
ITraitTemplateData
<
D
>
{
...
...
@@ -20,7 +20,7 @@ class TraitRenderer<T, D> implements IRenderer<T, ITraitTemplateData<D>>
private
elements
:
{
[
id
:
string
]:
T
};
constructor
(
private
controller
:
Trait
Controller
,
private
controller
:
Trait
,
private
renderer
:
IRenderer
<
T
,
D
>
)
{}
...
...
@@ -34,7 +34,7 @@ class TraitRenderer<T, D> implements IRenderer<T, ITraitTemplateData<D>>
}
renderElement
(
element
:
T
,
index
:
number
,
templateData
:
ITraitTemplateData
<
D
>
):
void
{
toggleClass
(
templateData
.
container
,
this
.
controller
.
trait
,
this
.
controller
.
contains
(
index
));
DOM
.
toggleClass
(
templateData
.
container
,
this
.
controller
.
trait
,
this
.
controller
.
contains
(
index
));
this
.
renderer
.
renderElement
(
element
,
index
,
templateData
.
data
);
}
...
...
@@ -43,7 +43,7 @@ class TraitRenderer<T, D> implements IRenderer<T, ITraitTemplateData<D>>
}
}
class
Trait
Controller
{
class
Trait
{
private
indexes
:
number
[];
...
...
@@ -71,7 +71,7 @@ class TraitController {
return
this
.
_trait
;
}
set
(
indexes
:
number
[]):
number
[]
{
set
(
...
indexes
:
number
[]):
number
[]
{
const
result
=
this
.
indexes
;
this
.
indexes
=
indexes
;
return
result
;
...
...
@@ -102,19 +102,41 @@ class TraitController {
}
}
class
Controller
<
T
>
implements
IDisposable
{
private
toDispose
:
IDisposable
[];
constructor
(
private
list
:
List
<
T
>
,
private
view
:
ListView
<
T
>
)
{
this
.
toDispose
=
[];
this
.
toDispose
.
push
(
view
.
addListener
(
'
click
'
,
e
=>
this
.
onClick
(
e
)));
}
private
onClick
(
e
:
IListMouseEvent
<
T
>
)
{
this
.
list
.
setSelection
(
e
.
index
);
}
dispose
()
{
this
.
toDispose
=
disposeAll
(
this
.
toDispose
);
}
}
export
class
List
<
T
>
implements
IDisposable
{
private
focus
:
Trait
;
private
selection
:
Trait
;
private
view
:
ListView
<
T
>
;
private
focus
:
TraitController
;
private
selection
:
TraitController
;
private
controller
:
Controller
<
T
>
;
constructor
(
container
:
HTMLElement
,
delegate
:
IDelegate
<
T
>
,
renderers
:
IRenderer
<
T
,
any
>
[]
)
{
this
.
focus
=
new
Trait
Controller
(
'
focused
'
);
this
.
selection
=
new
Trait
Controller
(
'
selected
'
);
this
.
focus
=
new
Trait
(
'
focused
'
);
this
.
selection
=
new
Trait
(
'
selected
'
);
renderers
=
renderers
.
map
(
r
=>
{
r
=
this
.
focus
.
wrapRenderer
(
r
);
...
...
@@ -123,6 +145,7 @@ export class List<T> implements IDisposable {
});
this
.
view
=
new
ListView
(
container
,
delegate
,
renderers
);
this
.
controller
=
new
Controller
(
this
,
this
.
view
);
}
splice
(
start
:
number
,
deleteCount
:
number
,
...
elements
:
T
[]):
void
{
...
...
@@ -144,12 +167,12 @@ export class List<T> implements IDisposable {
}
setSelection
(...
indexes
:
number
[]):
void
{
indexes
=
indexes
.
concat
(
this
.
selection
.
set
(
indexes
));
indexes
=
indexes
.
concat
(
this
.
selection
.
set
(
...
indexes
));
indexes
.
forEach
(
i
=>
this
.
view
.
splice
(
i
,
1
,
this
.
view
.
element
(
i
)));
}
setFocus
(...
indexes
:
number
[]):
void
{
indexes
=
indexes
.
concat
(
this
.
focus
.
set
(
indexes
));
indexes
=
indexes
.
concat
(
this
.
focus
.
set
(
...
indexes
));
indexes
.
forEach
(
i
=>
this
.
view
.
splice
(
i
,
1
,
this
.
view
.
element
(
i
)));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录