Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d5b9f669
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,发现更多精彩内容 >>
提交
d5b9f669
编写于
6月 07, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
goto error - extract quick fix widget
上级
7d8f715c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
119 addition
and
101 deletion
+119
-101
src/vs/editor/contrib/gotoError/browser/gotoError.ts
src/vs/editor/contrib/gotoError/browser/gotoError.ts
+119
-101
未找到文件。
src/vs/editor/contrib/gotoError/browser/gotoError.ts
浏览文件 @
d5b9f669
...
...
@@ -29,7 +29,7 @@ import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/edito
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditorBrowserRegistry
}
from
'
vs/editor/browser/editorBrowserExtensions
'
;
import
{
IOptions
,
ZoneWidget
}
from
'
vs/editor/contrib/zoneWidget/browser/zoneWidget
'
;
import
{
getCodeActions
}
from
'
vs/editor/contrib/quickFix/common/quickFix
'
;
import
{
getCodeActions
,
IQuickFix2
}
from
'
vs/editor/contrib/quickFix/common/quickFix
'
;
class
MarkerModel
{
...
...
@@ -181,6 +181,117 @@ class MarkerModel {
}
}
class
FixesWidget
{
domNode
:
HTMLDivElement
;
private
_disposeOnUpdate
:
IDisposable
[]
=
[];
private
_listener
:
IDisposable
;
constructor
(
container
:
HTMLElement
,
@
IKeybindingService
private
_keybindingService
:
IKeybindingService
)
{
this
.
domNode
=
document
.
createElement
(
'
div
'
);
container
.
appendChild
(
this
.
domNode
);
this
.
_listener
=
dom
.
addStandardDisposableListener
(
container
,
'
keydown
'
,
(
e
)
=>
{
switch
(
e
.
asKeybinding
())
{
case
CommonKeybindings
.
LEFT_ARROW
:
this
.
_move
(
true
);
// this._goLeft();
e
.
preventDefault
();
e
.
stopPropagation
();
break
;
case
CommonKeybindings
.
RIGHT_ARROW
:
this
.
_move
(
false
);
// this._goRight();
e
.
preventDefault
();
e
.
stopPropagation
();
break
;
}
});
}
dispose
():
void
{
this
.
_disposeOnUpdate
=
dispose
(
this
.
_disposeOnUpdate
);
this
.
_listener
=
dispose
(
this
.
_listener
);
}
update
(
fixes
:
TPromise
<
IQuickFix2
[]
>
):
TPromise
<
any
>
{
this
.
_disposeOnUpdate
=
dispose
(
this
.
_disposeOnUpdate
);
this
.
domNode
.
style
.
display
=
'
none
'
;
return
fixes
.
then
(
fixes
=>
this
.
_doUpdate
(
fixes
),
onUnexpectedError
);
}
private
_doUpdate
(
fixes
:
IQuickFix2
[]):
void
{
dom
.
clearNode
(
this
.
domNode
);
if
(
!
fixes
||
fixes
.
length
===
0
)
{
return
;
}
// light bulb and label
let
quickfixhead
=
document
.
createElement
(
'
span
'
);
quickfixhead
.
className
=
'
quickfixhead
'
;
quickfixhead
.
appendChild
(
document
.
createTextNode
(
fixes
.
length
>
1
?
nls
.
localize
(
'
quickfix.multiple.label
'
,
'
Suggested fixes:
'
)
:
nls
.
localize
(
'
quickfix.single.label
'
,
'
Suggested fix:
'
)));
this
.
domNode
.
appendChild
(
quickfixhead
);
// each fix as entry
const
container
=
document
.
createElement
(
'
span
'
);
container
.
className
=
'
quickfixcontainer
'
;
fixes
.
forEach
((
fix
,
idx
,
arr
)
=>
{
if
(
idx
>
0
)
{
let
separator
=
document
.
createElement
(
'
span
'
);
separator
.
appendChild
(
document
.
createTextNode
(
'
,
'
));
container
.
appendChild
(
separator
);
}
let
entry
=
document
.
createElement
(
'
a
'
);
entry
.
tabIndex
=
0
;
entry
.
className
=
`quickfixentry`
;
entry
.
dataset
[
'
idx
'
]
=
String
(
idx
);
entry
.
dataset
[
'
next
'
]
=
String
(
idx
<
arr
.
length
-
1
?
idx
+
1
:
0
);
entry
.
dataset
[
'
prev
'
]
=
String
(
idx
>
0
?
idx
-
1
:
arr
.
length
-
1
);
entry
.
appendChild
(
document
.
createTextNode
(
fix
.
command
.
title
));
this
.
_disposeOnUpdate
.
push
(
dom
.
addDisposableListener
(
entry
,
dom
.
EventType
.
CLICK
,
()
=>
{
this
.
_keybindingService
.
executeCommand
(
fix
.
command
.
id
,
...
fix
.
command
.
arguments
);
return
true
;
}));
this
.
_disposeOnUpdate
.
push
(
dom
.
addStandardDisposableListener
(
entry
,
'
keydown
'
,
(
e
)
=>
{
switch
(
e
.
asKeybinding
())
{
case
CommonKeybindings
.
ENTER
:
case
CommonKeybindings
.
SPACE
:
this
.
_keybindingService
.
executeCommand
(
fix
.
command
.
id
,
...
fix
.
command
.
arguments
);
e
.
preventDefault
();
e
.
stopPropagation
();
}
}));
container
.
appendChild
(
entry
);
});
this
.
domNode
.
appendChild
(
container
);
this
.
domNode
.
style
.
display
=
''
;
}
private
_move
(
left
:
boolean
):
void
{
let
target
:
HTMLElement
;
if
(
document
.
activeElement
.
classList
.
contains
(
'
quickfixentry
'
))
{
let
current
=
<
HTMLElement
>
document
.
activeElement
;
let
idx
=
left
?
current
.
dataset
[
'
prev
'
]
:
current
.
dataset
[
'
next
'
];
target
=
<
HTMLElement
>
this
.
domNode
.
querySelector
(
`a[data-idx='
${
idx
}
']`
);
}
else
{
target
=
<
HTMLElement
>
this
.
domNode
.
querySelector
(
'
.quickfixentry
'
);
}
target
.
focus
();
}
}
var
zoneOptions
:
IOptions
=
{
showFrame
:
true
,
showArrow
:
true
,
...
...
@@ -191,10 +302,8 @@ class MarkerNavigationWidget extends ZoneWidget {
private
_container
:
HTMLElement
;
private
_element
:
HTMLElement
;
private
_
quickFixSection
:
HTMLElemen
t
;
private
_
fixesWidget
:
FixesWidge
t
;
private
_callOnDispose
:
IDisposable
[]
=
[];
private
_localCleanup
:
IDisposable
[]
=
[];
private
_quickFixEntries
:
HTMLElement
[];
constructor
(
editor
:
ICodeEditor
,
private
_model
:
MarkerModel
,
private
_keybindingService
:
IKeybindingService
)
{
super
(
editor
,
zoneOptions
);
...
...
@@ -215,45 +324,8 @@ class MarkerNavigationWidget extends ZoneWidget {
this
.
_element
.
setAttribute
(
'
role
'
,
'
alert
'
);
this
.
_container
.
appendChild
(
this
.
_element
);
this
.
_quickFixSection
=
document
.
createElement
(
'
div
'
);
this
.
_container
.
appendChild
(
this
.
_quickFixSection
);
this
.
_callOnDispose
.
push
(
dom
.
addStandardDisposableListener
(
this
.
_container
,
'
keydown
'
,
(
e
)
=>
{
switch
(
e
.
asKeybinding
())
{
case
CommonKeybindings
.
LEFT_ARROW
:
this
.
_goLeft
();
e
.
preventDefault
();
e
.
stopPropagation
();
break
;
case
CommonKeybindings
.
RIGHT_ARROW
:
this
.
_goRight
();
e
.
preventDefault
();
e
.
stopPropagation
();
break
;
}
}));
}
private
_goLeft
():
void
{
if
(
!
this
.
_quickFixEntries
)
{
return
;
}
let
idx
=
this
.
_quickFixEntries
.
indexOf
(
<
HTMLElement
>
document
.
activeElement
);
if
(
idx
===
-
1
)
{
idx
=
1
;
}
idx
=
(
idx
+
this
.
_quickFixEntries
.
length
-
1
)
%
this
.
_quickFixEntries
.
length
;
this
.
_quickFixEntries
[
idx
].
focus
();
}
private
_goRight
():
void
{
if
(
!
this
.
_quickFixEntries
)
{
return
;
}
let
idx
=
this
.
_quickFixEntries
.
indexOf
(
<
HTMLElement
>
document
.
activeElement
);
idx
=
(
idx
+
1
)
%
this
.
_quickFixEntries
.
length
;
this
.
_quickFixEntries
[
idx
].
focus
();
this
.
_fixesWidget
=
new
FixesWidget
(
this
.
_container
,
this
.
_keybindingService
);
this
.
_callOnDispose
.
push
(
this
.
_fixesWidget
);
}
public
show
(
where
:
editorCommon
.
IPosition
,
heightInLines
:
number
):
void
{
...
...
@@ -282,8 +354,6 @@ class MarkerNavigationWidget extends ZoneWidget {
break
;
}
this
.
_localCleanup
=
dispose
(
this
.
_localCleanup
);
// update label and show
let
text
=
strings
.
format
(
'
({0}/{1})
'
,
this
.
_model
.
indexOf
(
marker
)
+
1
,
this
.
_model
.
length
());
if
(
marker
.
source
)
{
...
...
@@ -292,62 +362,10 @@ class MarkerNavigationWidget extends ZoneWidget {
dom
.
clearNode
(
this
.
_element
);
this
.
_element
.
appendChild
(
document
.
createTextNode
(
text
));
this
.
_element
.
appendChild
(
renderHtml
(
marker
.
message
));
this
.
_quickFixSection
.
style
.
display
=
'
none
'
;
getCodeActions
(
this
.
editor
.
getModel
(),
Range
.
lift
(
marker
)).
then
(
result
=>
{
dom
.
clearNode
(
this
.
_quickFixSection
);
if
(
result
.
length
>
0
)
{
this
.
_localCleanup
.
push
({
dispose
:
()
=>
{
this
.
_quickFixEntries
=
[];
}
});
let
quickfixhead
=
document
.
createElement
(
'
span
'
);
quickfixhead
.
className
=
'
quickfixhead
'
;
quickfixhead
.
appendChild
(
document
.
createTextNode
(
result
.
length
>
1
?
nls
.
localize
(
'
quickfix.multiple.label
'
,
'
Suggested fixes:
'
)
:
nls
.
localize
(
'
quickfix.single.label
'
,
'
Suggested fix:
'
)));
this
.
_quickFixSection
.
appendChild
(
quickfixhead
);
this
.
_quickFixEntries
=
[];
let
quickfixcontainer
=
document
.
createElement
(
'
span
'
);
quickfixcontainer
.
className
=
'
quickfixcontainer
'
;
result
.
forEach
((
fix
,
idx
,
arr
)
=>
{
var
container
=
quickfixcontainer
;
if
(
idx
>
0
)
{
let
separator
=
document
.
createElement
(
'
span
'
);
separator
.
appendChild
(
document
.
createTextNode
(
'
,
'
));
container
.
appendChild
(
separator
);
}
let
entry
=
document
.
createElement
(
'
a
'
);
entry
.
tabIndex
=
0
;
entry
.
className
=
'
quickfixentry
'
;
entry
.
appendChild
(
document
.
createTextNode
(
fix
.
command
.
title
));
this
.
_localCleanup
.
push
(
dom
.
addDisposableListener
(
entry
,
dom
.
EventType
.
CLICK
,
()
=>
{
this
.
_keybindingService
.
executeCommand
(
fix
.
command
.
id
,
...
fix
.
command
.
arguments
);
return
true
;
}));
this
.
_localCleanup
.
push
(
dom
.
addStandardDisposableListener
(
entry
,
'
keydown
'
,
(
e
)
=>
{
switch
(
e
.
asKeybinding
())
{
case
CommonKeybindings
.
ENTER
:
case
CommonKeybindings
.
SPACE
:
this
.
_keybindingService
.
executeCommand
(
fix
.
command
.
id
,
...
fix
.
command
.
arguments
);
e
.
preventDefault
();
e
.
stopPropagation
();
}
}));
container
.
appendChild
(
entry
);
this
.
_quickFixEntries
.
push
(
entry
);
});
this
.
_quickFixSection
.
appendChild
(
quickfixcontainer
);
this
.
_quickFixSection
.
style
.
display
=
''
;
this
.
show
(
new
Position
(
marker
.
startLineNumber
,
marker
.
startColumn
),
4
);
}
},
onUnexpectedError
);
this
.
_fixesWidget
.
update
(
getCodeActions
(
this
.
editor
.
getModel
(),
Range
.
lift
(
marker
)))
.
then
(()
=>
this
.
show
(
new
Position
(
marker
.
startLineNumber
,
marker
.
startColumn
),
4
));
this
.
_model
.
withoutWatchingEditorPosition
(()
=>
this
.
show
(
new
Position
(
marker
.
startLineNumber
,
marker
.
startColumn
),
3
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录