Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a25ffe6b
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,发现更多精彩内容 >>
提交
a25ffe6b
编写于
6月 06, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #6710: Correctly model the case where the slider is artificially inflated in size
上级
31a42937
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
68 deletion
+66
-68
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
+51
-66
src/vs/base/test/browser/ui/scrollbar/scrollbarState.test.ts
src/vs/base/test/browser/ui/scrollbar/scrollbarState.test.ts
+15
-2
未找到文件。
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
浏览文件 @
a25ffe6b
...
...
@@ -54,23 +54,13 @@ export class ScrollbarState {
* `visibleSize` - `oppositeScrollbarSize`
*/
private
_computedAvailableSize
:
number
;
/**
* `computedAvailableSize` - 2 * `arrowSize`
*/
private
_computedRepresentableSize
:
number
;
/**
* `computedRepresentableSize` / `scrollSize`
*/
private
_computedRatio
:
number
;
/**
* (`scrollSize` > `visibleSize`)
* (`scrollSize` > 0 && `scrollSize` > `visibleSize`)
*/
private
_computedIsNeeded
:
boolean
;
private
_computedSliderSize
:
number
;
private
_computedSliderRatio
:
number
;
private
_computedSliderPosition
:
number
;
constructor
(
arrowSize
:
number
,
scrollbarSize
:
number
,
oppositeScrollbarSize
:
number
)
{
...
...
@@ -83,10 +73,9 @@ export class ScrollbarState {
this
.
_scrollPosition
=
0
;
this
.
_computedAvailableSize
=
0
;
this
.
_computedRepresentableSize
=
0
;
this
.
_computedRatio
=
0.1
;
this
.
_computedIsNeeded
=
false
;
this
.
_computedSliderSize
=
0
;
this
.
_computedSliderRatio
=
0
;
this
.
_computedSliderPosition
=
0
;
this
.
_refreshComputedValues
();
...
...
@@ -130,56 +119,46 @@ export class ScrollbarState {
return
false
;
}
private
_refreshComputedValues
():
void
{
const
oppositeScrollbarSize
=
this
.
_oppositeScrollbarSize
;
const
arrowSize
=
this
.
_arrowSize
;
const
visibleSize
=
this
.
_visibleSize
;
const
scrollSize
=
this
.
_scrollSize
;
const
scrollPosition
=
this
.
_scrollPosition
;
let
computedAvailableSize
=
Math
.
max
(
0
,
visibleSize
-
oppositeScrollbarSize
);
let
computedRepresentableSize
=
Math
.
max
(
0
,
computedAvailableSize
-
2
*
arrowSize
);
let
computedRatio
=
scrollSize
>
0
?
(
computedRepresentableSize
/
scrollSize
)
:
0
;
let
computedIsNeeded
=
(
scrollSize
>
visibleSize
);
let
computedSliderSize
:
number
;
let
computedSliderPosition
:
number
;
private
static
_computeValues
(
oppositeScrollbarSize
:
number
,
arrowSize
:
number
,
visibleSize
:
number
,
scrollSize
:
number
,
scrollPosition
:
number
)
{
const
computedAvailableSize
=
Math
.
max
(
0
,
visibleSize
-
oppositeScrollbarSize
);
const
computedRepresentableSize
=
Math
.
max
(
0
,
computedAvailableSize
-
2
*
arrowSize
);
const
computedIsNeeded
=
(
scrollSize
>
0
&&
scrollSize
>
visibleSize
);
if
(
!
computedIsNeeded
)
{
computedSliderSize
=
computedRepresentableSize
;
computedSliderPosition
=
0
;
}
else
{
computedSliderSize
=
Math
.
floor
(
visibleSize
*
computedRatio
);
computedSliderPosition
=
Math
.
floor
(
scrollPosition
*
computedRatio
);
if
(
computedSliderSize
<
MINIMUM_SLIDER_SIZE
)
{
// We must artificially increase the size of the slider, since the slider would be too small otherwise
// The effort is to keep the slider centered around the original position, but we must take into
// account the cases when the slider is too close to the top or too close to the bottom
let
sliderArtificialOffset
=
(
MINIMUM_SLIDER_SIZE
-
computedSliderSize
)
/
2
;
computedSliderSize
=
MINIMUM_SLIDER_SIZE
;
computedSliderPosition
-=
sliderArtificialOffset
;
if
(
computedSliderPosition
+
computedSliderSize
>
computedRepresentableSize
)
{
// Slider is too close to the bottom, so we glue it to the bottom
computedSliderPosition
=
computedRepresentableSize
-
computedSliderSize
;
}
if
(
computedSliderPosition
<
0
)
{
// Slider is too close to the top, so we glue it to the top
computedSliderPosition
=
0
;
}
}
// There is no need for a slider
return
{
computedAvailableSize
:
Math
.
round
(
computedAvailableSize
),
computedIsNeeded
:
computedIsNeeded
,
computedSliderSize
:
Math
.
round
(
computedRepresentableSize
),
computedSliderRatio
:
0
,
computedSliderPosition
:
0
,
};
}
this
.
_computedAvailableSize
=
Math
.
round
(
computedAvailableSize
);
this
.
_computedRepresentableSize
=
Math
.
round
(
computedRepresentableSize
);
this
.
_computedRatio
=
computedRatio
;
this
.
_computedIsNeeded
=
computedIsNeeded
;
this
.
_computedSliderSize
=
Math
.
round
(
computedSliderSize
);
this
.
_computedSliderPosition
=
Math
.
round
(
computedSliderPosition
);
// We must artificially increase the size of the slider if needed, since the slider would be too small to grab with the mouse otherwise
const
computedSliderSize
=
Math
.
round
(
Math
.
max
(
MINIMUM_SLIDER_SIZE
,
Math
.
floor
(
visibleSize
*
computedRepresentableSize
/
scrollSize
)));
// The slider can move from 0 to `computedRepresentableSize` - `computedSliderSize`
// in the same way `scrollPosition` can move from 0 to `scrollSize` - `visibleSize`.
const
computedSliderRatio
=
(
computedRepresentableSize
-
computedSliderSize
)
/
(
scrollSize
-
visibleSize
);
const
computedSliderPosition
=
(
scrollPosition
*
computedSliderRatio
);
return
{
computedAvailableSize
:
Math
.
round
(
computedAvailableSize
),
computedIsNeeded
:
computedIsNeeded
,
computedSliderSize
:
Math
.
round
(
computedSliderSize
),
computedSliderRatio
:
computedSliderRatio
,
computedSliderPosition
:
Math
.
round
(
computedSliderPosition
),
};
}
private
_refreshComputedValues
():
void
{
const
r
=
ScrollbarState
.
_computeValues
(
this
.
_oppositeScrollbarSize
,
this
.
_arrowSize
,
this
.
_visibleSize
,
this
.
_scrollSize
,
this
.
_scrollPosition
);
this
.
_computedAvailableSize
=
r
.
computedAvailableSize
;
this
.
_computedIsNeeded
=
r
.
computedIsNeeded
;
this
.
_computedSliderSize
=
r
.
computedSliderSize
;
this
.
_computedSliderRatio
=
r
.
computedSliderRatio
;
this
.
_computedSliderPosition
=
r
.
computedSliderPosition
;
}
public
getArrowSize
():
number
{
...
...
@@ -214,24 +193,30 @@ export class ScrollbarState {
return
(
this
.
_computedSliderPosition
+
this
.
_computedSliderSize
/
2
);
}
private
_convertSliderPositionToScrollPosition
(
desiredSliderPosition
:
number
):
number
{
return
desiredSliderPosition
/
this
.
_computedRatio
;
}
/**
* Compute a desired `scrollPosition` such that `offset` ends up in the center of the slider.
* `offset` is based on the same coordinate system as the `sliderPosition`.
*/
public
getDesiredScrollPositionFromOffset
(
offset
:
number
):
number
{
if
(
!
this
.
_computedIsNeeded
)
{
// no need for a slider
return
0
;
}
let
desiredSliderPosition
=
offset
-
this
.
_arrowSize
-
this
.
_computedSliderSize
/
2
;
return
this
.
_convertSliderPositionToScrollPosition
(
desiredSliderPosition
);
return
Math
.
round
(
desiredSliderPosition
/
this
.
_computedSliderRatio
);
}
/**
* Compute a desired `scrollPosition` such that the slider moves by `delta`.
*/
public
getDesiredScrollPositionFromDelta
(
delta
:
number
):
number
{
if
(
!
this
.
_computedIsNeeded
)
{
// no need for a slider
return
0
;
}
let
desiredSliderPosition
=
this
.
_computedSliderPosition
+
delta
;
return
this
.
_convertSliderPositionToScrollPosition
(
desiredSliderPosition
);
return
Math
.
round
(
desiredSliderPosition
/
this
.
_computedSliderRatio
);
}
}
src/vs/base/test/browser/ui/scrollbar/scrollbarState.test.ts
浏览文件 @
a25ffe6b
...
...
@@ -15,11 +15,24 @@ suite('ScrollbarState', () => {
actual
.
setScrollPosition
(
32787
);
assert
.
equal
(
actual
.
getArrowSize
(),
0
);
assert
.
equal
(
actual
.
getScrollPosition
(),
32787
);
assert
.
equal
(
actual
.
getRectangleLargeSize
(),
339
);
assert
.
equal
(
actual
.
getRectangleSmallSize
(),
14
);
assert
.
equal
(
actual
.
isNeeded
(),
true
);
assert
.
equal
(
actual
.
getSliderSize
(),
20
);
assert
.
equal
(
actual
.
getSliderPosition
(),
252
);
assert
.
equal
(
actual
.
getSliderCenter
(),
262
);
assert
.
equal
(
actual
.
getSliderPosition
(),
249
);
assert
.
equal
(
actual
.
getSliderCenter
(),
259
);
assert
.
equal
(
actual
.
getDesiredScrollPositionFromOffset
(
259
),
32849
);
actual
.
setScrollPosition
(
32849
);
assert
.
equal
(
actual
.
getArrowSize
(),
0
);
assert
.
equal
(
actual
.
getScrollPosition
(),
32849
);
assert
.
equal
(
actual
.
getRectangleLargeSize
(),
339
);
assert
.
equal
(
actual
.
getRectangleSmallSize
(),
14
);
assert
.
equal
(
actual
.
isNeeded
(),
true
);
assert
.
equal
(
actual
.
getSliderSize
(),
20
);
assert
.
equal
(
actual
.
getSliderPosition
(),
249
);
assert
.
equal
(
actual
.
getSliderCenter
(),
259
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录