Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
faadee87
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
未验证
提交
faadee87
编写于
8月 17, 2018
作者:
C
Christopher Leidigh
提交者:
GitHub
8月 17, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SelectBox: Prevent layout/hide on no room/offscreen Fixes: #55750 (#56173)
上级
5399233b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
22 deletion
+65
-22
src/vs/base/browser/ui/contextview/contextview.ts
src/vs/base/browser/ui/contextview/contextview.ts
+5
-0
src/vs/base/browser/ui/selectBox/selectBoxCustom.ts
src/vs/base/browser/ui/selectBox/selectBoxCustom.ts
+60
-22
未找到文件。
src/vs/base/browser/ui/contextview/contextview.ts
浏览文件 @
faadee87
...
...
@@ -173,6 +173,11 @@ export class ContextView {
}
private
doLayout
():
void
{
// Check that we still have a delegate - this.delegate.layout may have hidden
if
(
!
this
.
isVisible
())
{
return
;
}
// Get anchor
let
anchor
=
this
.
delegate
.
getAnchor
();
...
...
src/vs/base/browser/ui/selectBox/selectBoxCustom.ts
浏览文件 @
faadee87
...
...
@@ -82,7 +82,7 @@ class SelectListRenderer implements IRenderer<ISelectOptionItem, ISelectListTemp
export
class
SelectBoxList
implements
ISelectBoxDelegate
,
IVirtualDelegate
<
ISelectOptionItem
>
{
private
static
readonly
DEFAULT_DROPDOWN_MINIMUM_BOTTOM_MARGIN
=
32
;
private
static
readonly
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
=
4
2
;
private
static
readonly
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
=
2
;
private
static
readonly
DEFAULT_MINIMUM_VISIBLE_OPTIONS
=
3
;
private
_isVisible
:
boolean
;
...
...
@@ -393,9 +393,11 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
}
// Set drop-down position above/below from required height and margins
this
.
layoutSelectDropDown
(
true
);
// If pre-layout cannot fit at least one option do not show drop-down
if
(
!
this
.
layoutSelectDropDown
(
true
))
{
return
;
}
this
.
_isVisible
=
true
;
this
.
cloneElementFont
(
this
.
selectElement
,
this
.
selectDropDownContainer
);
this
.
contextViewProvider
.
showContextView
({
...
...
@@ -411,6 +413,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
// Track initial selection the case user escape, blur
this
.
_currentSelection
=
this
.
selected
;
this
.
_isVisible
=
true
;
}
private
hideSelectDropDown
(
focusSelect
:
boolean
)
{
...
...
@@ -423,6 +426,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
if
(
focusSelect
)
{
this
.
selectElement
.
focus
();
}
this
.
contextViewProvider
.
hideContextView
();
}
...
...
@@ -443,7 +447,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
};
}
private
layoutSelectDropDown
(
preLayoutPosition
?:
boolean
)
{
private
layoutSelectDropDown
(
preLayoutPosition
?:
boolean
)
:
boolean
{
// Layout ContextView drop down select list and container
// Have to manage our vertical overflow, sizing, position below or above
...
...
@@ -454,30 +458,54 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
const
selectPosition
=
dom
.
getDomNodePagePosition
(
this
.
selectElement
);
const
styles
=
getComputedStyle
(
this
.
selectElement
);
const
verticalPadding
=
parseFloat
(
styles
.
getPropertyValue
(
'
--dropdown-padding-top
'
))
+
parseFloat
(
styles
.
getPropertyValue
(
'
--dropdown-padding-bottom
'
));
let
maxSelectDropDownHeight
=
0
;
maxSelectDropDownHeight
=
(
window
.
innerHeight
-
selectPosition
.
top
-
selectPosition
.
height
-
this
.
selectBoxOptions
.
minBottomMargin
);
const
maxSelectDropDownHeightBelow
=
(
window
.
innerHeight
-
selectPosition
.
top
-
selectPosition
.
height
-
this
.
selectBoxOptions
.
minBottomMargin
)
;
const
maxSelectDropDownHeightAbove
=
(
selectPosition
.
top
-
SelectBoxList
.
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
);
// Get initial list height and determine space above and below
this
.
selectList
.
layout
();
let
listHeight
=
this
.
selectList
.
contentHeight
;
const
minRequiredDropDownHeight
=
listHeight
+
verticalPadding
;
const
maxVisibleOptionsBelow
=
((
Math
.
floor
((
maxSelectDropDownHeightBelow
-
verticalPadding
)
/
this
.
getHeight
())));
const
maxVisibleOptionsAbove
=
((
Math
.
floor
((
maxSelectDropDownHeightAbove
-
verticalPadding
)
/
this
.
getHeight
())));
// If we are only doing pre-layout check/adjust position only
// Calculate vertical space available, flip up if insufficient
// Use reflected padding on parent select, ContextView style properties not available before DOM attachment
// Use reflected padding on parent select, ContextView style
// properties not available before DOM attachment
if
(
preLayoutPosition
)
{
// Check if select moved out of viewport , do not open
// If at least one option cannot be shown, don't open the drop-down or hide/remove if open
if
((
selectPosition
.
top
+
selectPosition
.
height
)
>
(
window
.
innerHeight
-
22
)
||
selectPosition
.
top
<
SelectBoxList
.
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
||
((
maxVisibleOptionsBelow
<
1
)
&&
(
maxVisibleOptionsAbove
<
1
)))
{
// Indicate we cannot open
return
false
;
}
// Determine if we have to flip up
// Always show complete list items - never more than Max available vertical height
if
(
listHeight
+
verticalPadding
>
maxSelectDropDownHeight
)
{
const
maxVisibleOptions
=
((
Math
.
floor
((
maxSelectDropDownHeight
-
verticalPadding
)
/
this
.
getHeight
())));
// Check if we can at least show min items otherwise flip above
if
(
maxVisibleOptions
<
SelectBoxList
.
DEFAULT_MINIMUM_VISIBLE_OPTIONS
)
{
this
.
_dropDownPosition
=
AnchorPosition
.
ABOVE
;
}
else
{
this
.
_dropDownPosition
=
AnchorPosition
.
BELOW
;
}
if
(
maxVisibleOptionsBelow
<
SelectBoxList
.
DEFAULT_MINIMUM_VISIBLE_OPTIONS
&&
maxVisibleOptionsAbove
>
maxVisibleOptionsBelow
&&
this
.
options
.
length
>
maxVisibleOptionsBelow
)
{
this
.
_dropDownPosition
=
AnchorPosition
.
ABOVE
;
}
else
{
this
.
_dropDownPosition
=
AnchorPosition
.
BELOW
;
}
// Do full layout on showSelectDropDown only
return
;
return
true
;
}
// Check if select out of viewport or cutting into status bar
if
((
selectPosition
.
top
+
selectPosition
.
height
)
>
(
window
.
innerHeight
-
22
)
||
selectPosition
.
top
<
SelectBoxList
.
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
||
(
this
.
_dropDownPosition
===
AnchorPosition
.
BELOW
&&
maxVisibleOptionsBelow
<
1
)
||
(
this
.
_dropDownPosition
===
AnchorPosition
.
ABOVE
&&
maxVisibleOptionsAbove
<
1
))
{
// Cannot properly layout, close and hide
this
.
hideSelectDropDown
(
true
);
return
false
;
}
// Make visible to enable measurements
...
...
@@ -486,15 +514,22 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
// SetUp list dimensions and layout - account for container padding
// Use position to check above or below available space
if
(
this
.
_dropDownPosition
===
AnchorPosition
.
BELOW
)
{
if
(
this
.
_isVisible
&&
maxVisibleOptionsBelow
+
maxVisibleOptionsAbove
<
1
)
{
// If drop-down is visible, must be doing a DOM re-layout, hide since we don't fit
// Hide drop-down, hide contextview, focus on parent select
this
.
hideSelectDropDown
(
true
);
return
false
;
}
// Set container height to max from select bottom to margin (default/minBottomMargin)
if
(
listHeight
+
verticalPadding
>
maxSelectDropDownHeight
)
{
listHeight
=
(
(
Math
.
floor
((
maxSelectDropDownHeight
-
verticalPadding
)
/
this
.
getHeight
()))
*
this
.
getHeight
()
);
if
(
minRequiredDropDownHeight
>
maxSelectDropDownHeightBelow
)
{
listHeight
=
(
maxVisibleOptionsBelow
*
this
.
getHeight
()
+
verticalPadding
);
}
}
else
{
// Set container height to max from select top to margin (default/minTopMargin)
maxSelectDropDownHeight
=
(
selectPosition
.
top
-
SelectBoxList
.
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
);
if
(
listHeight
+
verticalPadding
>
maxSelectDropDownHeight
)
{
listHeight
=
(
(
Math
.
floor
((
maxSelectDropDownHeight
-
SelectBoxList
.
DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN
)
/
this
.
getHeight
()))
*
this
.
getHeight
()
);
if
(
minRequiredDropDownHeight
>
maxSelectDropDownHeightAbove
)
{
// listHeight = ((Math.floor((maxSelectDropDownHeightBelow - verticalPadding) / this.getHeight())) * this.getHeight());
listHeight
=
(
maxVisibleOptionsAbove
*
this
.
getHeight
()
+
verticalPadding
);
}
}
...
...
@@ -522,6 +557,9 @@ export class SelectBoxList implements ISelectBoxDelegate, IVirtualDelegate<ISele
this
.
selectDropDownListContainer
.
setAttribute
(
'
tabindex
'
,
'
0
'
);
dom
.
toggleClass
(
this
.
selectElement
,
'
synthetic-focus
'
,
true
);
dom
.
toggleClass
(
this
.
selectDropDownContainer
,
'
synthetic-focus
'
,
true
);
return
true
;
}
else
{
return
false
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录