Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d3cb5b21
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,发现更多精彩内容 >>
提交
d3cb5b21
编写于
4月 23, 2018
作者:
C
Christof Marti
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Validate input on Enter (#48116)
上级
2b4dfcc3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
15 deletion
+54
-15
src/vs/workbench/browser/parts/quickinput/quickInput.ts
src/vs/workbench/browser/parts/quickinput/quickInput.ts
+52
-13
src/vs/workbench/browser/parts/quickinput/quickInputBox.ts
src/vs/workbench/browser/parts/quickinput/quickInputBox.ts
+2
-2
未找到文件。
src/vs/workbench/browser/parts/quickinput/quickInput.ts
浏览文件 @
d3cb5b21
...
...
@@ -28,10 +28,10 @@ import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import
{
attachBadgeStyler
,
attachProgressBarStyler
,
attachButtonStyler
}
from
'
vs/platform/theme/common/styler
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
ProgressBar
}
from
'
vs/base/browser/ui/progressbar/progressbar
'
;
import
{
chain
}
from
'
vs/base/common/event
'
;
import
{
chain
,
debounceEvent
}
from
'
vs/base/common/event
'
;
import
{
Button
}
from
'
vs/base/browser/ui/button/button
'
;
import
{
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
onUnexpectedError
,
canceled
}
from
'
vs/base/common/errors
'
;
const
$
=
dom
.
$
;
...
...
@@ -69,7 +69,7 @@ interface InputController<R> {
readonly
showUI
:
{
[
k
in
keyof
QuickInputUI
]?:
boolean
;
}
&
{
ok
?:
boolean
;
};
readonly
result
:
TPromise
<
R
>
;
readonly
ready
:
TPromise
<
void
>
;
readonly
resolve
:
(
ok
?:
true
|
Thenable
<
never
>
)
=>
void
;
readonly
resolve
:
(
ok
?:
true
|
Thenable
<
never
>
)
=>
void
|
TPromise
<
void
>
;
}
class
SelectManyController
<
T
extends
IPickOpenEntry
>
implements
InputController
<
T
[]
>
{
...
...
@@ -112,13 +112,14 @@ class TextInputController implements InputController<string> {
public
showUI
=
{
inputBox
:
true
,
message
:
true
};
public
result
:
TPromise
<
string
>
;
public
ready
=
TPromise
.
as
(
null
);
public
resolve
:
(
ok
?:
true
|
Thenable
<
never
>
)
=>
void
;
public
resolve
Result
:
(
string
)
=>
void
;
private
validationValue
:
string
;
private
validation
:
TPromise
<
string
>
;
private
disposables
:
IDisposable
[]
=
[];
constructor
(
ui
:
QuickInputUI
,
parameters
:
TextInputParameters
)
{
constructor
(
private
ui
:
QuickInputUI
,
private
parameters
:
TextInputParameters
)
{
this
.
result
=
new
TPromise
<
string
>
((
resolve
,
reject
,
progress
)
=>
{
this
.
resolve
=
ok
=>
resolve
(
ok
===
true
?
ui
.
inputBox
.
value
:
ok
)
;
this
.
resolve
Result
=
resolve
;
});
this
.
result
.
then
(()
=>
this
.
dispose
());
...
...
@@ -130,19 +131,51 @@ class TextInputController implements InputController<string> {
ui
.
message
.
textContent
=
defaultMessage
;
if
(
parameters
.
validateInput
)
{
this
.
disposables
.
push
(
ui
.
inputBox
.
onDidChange
(
value
=>
{
this
.
validationValue
=
value
;
parameters
.
validateInput
(
value
)
const
onDidChange
=
debounceEvent
(
ui
.
inputBox
.
onDidChange
,
(
last
,
cur
)
=>
cur
,
100
);
this
.
disposables
.
push
(
onDidChange
(()
=>
{
this
.
updatedValidation
(
)
.
then
(
validationError
=>
{
if
(
this
.
validationValue
===
value
)
{
ui
.
message
.
textContent
=
validationError
||
defaultMessage
;
}
ui
.
message
.
textContent
=
validationError
||
defaultMessage
;
})
.
then
(
null
,
onUnexpectedError
);
}));
}
}
resolve
(
ok
?:
true
|
Thenable
<
never
>
)
{
if
(
ok
===
true
)
{
return
this
.
updatedValidation
()
.
then
(
validationError
=>
{
if
(
validationError
)
{
throw
canceled
();
}
this
.
resolveResult
(
this
.
ui
.
inputBox
.
value
);
});
}
else
{
this
.
resolveResult
(
ok
);
}
return
null
;
}
private
updatedValidation
()
{
if
(
this
.
parameters
.
validateInput
)
{
const
value
=
this
.
ui
.
inputBox
.
value
;
if
(
value
!==
this
.
validationValue
)
{
this
.
validationValue
=
value
;
this
.
validation
=
this
.
parameters
.
validateInput
(
value
)
.
then
(
validationError
=>
{
if
(
this
.
validationValue
!==
value
)
{
throw
canceled
();
}
return
validationError
;
});
}
}
else
if
(
!
this
.
validation
)
{
this
.
validation
=
TPromise
.
as
(
null
);
}
return
this
.
validation
;
}
private
dispose
()
{
this
.
disposables
=
dispose
(
this
.
disposables
);
}
...
...
@@ -315,7 +348,13 @@ export class QuickInputService extends Component implements IQuickInputService {
private
close
(
ok
?:
true
|
Thenable
<
never
>
)
{
if
(
this
.
controller
)
{
this
.
controller
.
resolve
(
ok
);
const
resolved
=
this
.
controller
.
resolve
(
ok
);
if
(
resolved
)
{
resolved
.
then
(()
=>
this
.
container
.
style
.
display
=
'
none
'
)
.
then
(
null
,
onUnexpectedError
);
return
;
}
}
this
.
container
.
style
.
display
=
'
none
'
;
}
...
...
src/vs/workbench/browser/parts/quickinput/quickInputBox.ts
浏览文件 @
d3cb5b21
...
...
@@ -40,13 +40,13 @@ export class QuickInputBox {
inputElement
.
setAttribute
(
'
aria-autocomplete
'
,
'
list
'
);
}
onKeyDown
(
handler
:
(
event
:
StandardKeyboardEvent
)
=>
void
):
IDisposable
{
onKeyDown
=
(
handler
:
(
event
:
StandardKeyboardEvent
)
=>
void
):
IDisposable
=>
{
return
dom
.
addDisposableListener
(
this
.
inputBox
.
inputElement
,
dom
.
EventType
.
KEY_DOWN
,
(
e
:
KeyboardEvent
)
=>
{
handler
(
new
StandardKeyboardEvent
(
e
));
});
}
onDidChange
(
handler
:
(
event
:
string
)
=>
void
):
IDisposable
{
onDidChange
=
(
handler
:
(
event
:
string
)
=>
void
):
IDisposable
=>
{
return
this
.
inputBox
.
onDidChange
(
handler
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录