Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a9ad68e7
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,发现更多精彩内容 >>
提交
a9ad68e7
编写于
5月 14, 2018
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some code cleanup
上级
db6e2f13
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
129 deletion
+57
-129
src/vs/workbench/parts/comments/electron-browser/commentGlyphWidget.ts
...nch/parts/comments/electron-browser/commentGlyphWidget.ts
+0
-1
src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts
...s/comments/electron-browser/commentsEditorContribution.ts
+57
-128
未找到文件。
src/vs/workbench/parts/comments/electron-browser/commentGlyphWidget.ts
浏览文件 @
a9ad68e7
...
...
@@ -33,7 +33,6 @@ export class CommentGlyphWidget implements IContentWidget {
return
this
.
_id
;
}
getPosition
():
IContentWidgetPosition
{
return
{
position
:
{
...
...
src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts
浏览文件 @
a9ad68e7
...
...
@@ -8,7 +8,7 @@ import 'vs/css!./media/review';
import
{
$
}
from
'
vs/base/browser/builder
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditor
,
IEditorMouseEvent
,
IViewZone
,
MouseTargetType
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ICodeEditor
,
IEditorMouseEvent
,
IViewZone
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
registerEditorContribution
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/browser/services/codeEditorService
'
;
import
{
EmbeddedCodeEditorWidget
}
from
'
vs/editor/browser/widget/embeddedCodeEditorWidget
'
;
...
...
@@ -65,8 +65,8 @@ export class ReviewController implements IEditorContribution {
private
decorationIDs
:
string
[];
private
commentingRangeDecorationMap
:
Map
<
number
,
string
[]
>
;
private
commentingRangeDecorations
:
string
[];
private
_
zone
Widget
:
ReviewZoneWidget
;
private
_
zone
Widgets
:
ReviewZoneWidget
[];
private
_
newComment
Widget
:
ReviewZoneWidget
;
private
_
comment
Widgets
:
ReviewZoneWidget
[];
private
_reviewPanelVisible
:
IContextKey
<
boolean
>
;
private
_commentInfos
:
modes
.
CommentInfo
[];
private
_reviewModel
:
ReviewModel
;
...
...
@@ -86,10 +86,9 @@ export class ReviewController implements IEditorContribution {
this
.
decorationIDs
=
[];
this
.
commentingRangeDecorations
=
[];
this
.
commentingRangeDecorationMap
=
new
Map
();
this
.
mouseDownInfo
=
null
;
this
.
_commentInfos
=
[];
this
.
_
zone
Widgets
=
[];
this
.
_
zone
Widget
=
null
;
this
.
_
comment
Widgets
=
[];
this
.
_
newComment
Widget
=
null
;
this
.
_newCommentGlyph
=
null
;
this
.
_reviewPanelVisible
=
ctxReviewPanelVisible
.
bindTo
(
contextKeyService
);
...
...
@@ -100,12 +99,12 @@ export class ReviewController implements IEditorContribution {
this
.
decorationIDs
=
accessor
.
deltaDecorations
(
this
.
decorationIDs
,
[]);
});
if
(
this
.
_
zone
Widget
)
{
this
.
_
zone
Widget
.
dispose
();
this
.
_
zone
Widget
=
null
;
if
(
this
.
_
newComment
Widget
)
{
this
.
_
newComment
Widget
.
dispose
();
this
.
_
newComment
Widget
=
null
;
}
this
.
_
zone
Widgets
.
forEach
(
zone
=>
{
this
.
_
comment
Widgets
.
forEach
(
zone
=>
{
zone
.
dispose
();
});
...
...
@@ -113,7 +112,7 @@ export class ReviewController implements IEditorContribution {
info
.
threads
.
forEach
(
thread
=>
{
let
zoneWidget
=
new
ReviewZoneWidget
(
this
.
editor
,
info
.
owner
,
thread
,
info
.
reply
,
{},
this
.
themeService
,
this
.
commandService
);
zoneWidget
.
display
(
thread
.
range
.
startLineNumber
);
this
.
_
zone
Widgets
.
push
(
zoneWidget
);
this
.
_
comment
Widgets
.
push
(
zoneWidget
);
});
});
});
...
...
@@ -133,7 +132,7 @@ export class ReviewController implements IEditorContribution {
}
public
revealCommentThread
(
threadId
:
string
):
void
{
const
commentThreadWidget
=
this
.
_
zone
Widgets
.
filter
(
widget
=>
widget
.
commentThread
.
threadId
===
threadId
);
const
commentThreadWidget
=
this
.
_
comment
Widgets
.
filter
(
widget
=>
widget
.
commentThread
.
threadId
===
threadId
);
if
(
commentThreadWidget
.
length
===
1
)
{
commentThreadWidget
[
0
].
reveal
();
}
...
...
@@ -147,28 +146,26 @@ export class ReviewController implements IEditorContribution {
this
.
globalToDispose
=
dispose
(
this
.
globalToDispose
);
this
.
localToDispose
=
dispose
(
this
.
localToDispose
);
if
(
this
.
_
zone
Widget
)
{
this
.
_
zone
Widget
.
dispose
();
this
.
_
zone
Widget
=
null
;
if
(
this
.
_
newComment
Widget
)
{
this
.
_
newComment
Widget
.
dispose
();
this
.
_
newComment
Widget
=
null
;
}
this
.
editor
=
null
;
}
public
onModelChanged
():
void
{
this
.
localToDispose
=
dispose
(
this
.
localToDispose
);
if
(
this
.
_
zone
Widget
)
{
if
(
this
.
_
newComment
Widget
)
{
// todo store view state.
this
.
_
zone
Widget
.
dispose
();
this
.
_
zone
Widget
=
null
;
this
.
_
newComment
Widget
.
dispose
();
this
.
_
newComment
Widget
=
null
;
}
this
.
_
zone
Widgets
.
forEach
(
zone
=>
{
this
.
_
comment
Widgets
.
forEach
(
zone
=>
{
zone
.
dispose
();
});
this
.
_
zone
Widgets
=
[];
this
.
_
comment
Widgets
=
[];
this
.
localToDispose
.
push
(
this
.
editor
.
onMouseDown
(
e
=>
this
.
onEditorMouseDown
(
e
)));
this
.
localToDispose
.
push
(
this
.
editor
.
onMouseUp
(
e
=>
this
.
onEditorMouseUp
(
e
)));
this
.
localToDispose
.
push
(
this
.
editor
.
onMouseMove
(
e
=>
this
.
onEditorMouseMove
(
e
)));
this
.
localToDispose
.
push
(
this
.
commentService
.
onDidUpdateCommentThreads
(
e
=>
{
const
editorURI
=
this
.
editor
&&
this
.
editor
.
getModel
()
&&
this
.
editor
.
getModel
().
uri
;
...
...
@@ -180,16 +177,16 @@ export class ReviewController implements IEditorContribution {
let
changed
=
e
.
changed
.
filter
(
thread
=>
thread
.
resource
.
toString
()
===
editorURI
.
toString
());
removed
.
forEach
(
thread
=>
{
let
matchedZones
=
this
.
_
zone
Widgets
.
filter
(
zoneWidget
=>
zoneWidget
.
owner
===
e
.
owner
&&
zoneWidget
.
commentThread
.
threadId
===
thread
.
threadId
);
let
matchedZones
=
this
.
_
comment
Widgets
.
filter
(
zoneWidget
=>
zoneWidget
.
owner
===
e
.
owner
&&
zoneWidget
.
commentThread
.
threadId
===
thread
.
threadId
);
if
(
matchedZones
.
length
)
{
let
matchedZone
=
matchedZones
[
0
];
let
index
=
this
.
_
zone
Widgets
.
indexOf
(
matchedZone
);
this
.
_
zone
Widgets
.
splice
(
index
,
1
);
let
index
=
this
.
_
comment
Widgets
.
indexOf
(
matchedZone
);
this
.
_
comment
Widgets
.
splice
(
index
,
1
);
}
});
changed
.
forEach
(
thread
=>
{
let
matchedZones
=
this
.
_
zone
Widgets
.
filter
(
zoneWidget
=>
zoneWidget
.
owner
===
e
.
owner
&&
zoneWidget
.
commentThread
.
threadId
===
thread
.
threadId
);
let
matchedZones
=
this
.
_
comment
Widgets
.
filter
(
zoneWidget
=>
zoneWidget
.
owner
===
e
.
owner
&&
zoneWidget
.
commentThread
.
threadId
===
thread
.
threadId
);
if
(
matchedZones
.
length
)
{
let
matchedZone
=
matchedZones
[
0
];
matchedZone
.
update
(
thread
);
...
...
@@ -198,88 +195,12 @@ export class ReviewController implements IEditorContribution {
added
.
forEach
(
thread
=>
{
let
zoneWidget
=
new
ReviewZoneWidget
(
this
.
editor
,
e
.
owner
,
thread
,
thread
.
reply
,
{},
this
.
themeService
,
this
.
commandService
);
zoneWidget
.
display
(
thread
.
range
.
startLineNumber
);
this
.
_
zone
Widgets
.
push
(
zoneWidget
);
this
.
_
comment
Widgets
.
push
(
zoneWidget
);
this
.
_commentInfos
.
filter
(
info
=>
info
.
owner
===
e
.
owner
)[
0
].
threads
.
push
(
thread
);
});
}));
}
private
mouseDownInfo
:
{
lineNumber
:
number
,
iconClicked
:
boolean
};
private
onEditorMouseDown
(
e
:
IEditorMouseEvent
):
void
{
if
(
!
e
.
event
.
leftButton
)
{
return
;
}
let
range
=
e
.
target
.
range
;
if
(
!
range
)
{
return
;
}
let
iconClicked
=
false
;
switch
(
e
.
target
.
type
)
{
case
MouseTargetType
.
GUTTER_LINE_DECORATIONS
:
iconClicked
=
true
;
break
;
default
:
return
;
}
this
.
mouseDownInfo
=
{
lineNumber
:
range
.
startLineNumber
,
iconClicked
};
}
private
onEditorMouseUp
(
e
:
IEditorMouseEvent
):
void
{
if
(
!
this
.
mouseDownInfo
)
{
return
;
}
let
lineNumber
=
this
.
mouseDownInfo
.
lineNumber
;
let
iconClicked
=
this
.
mouseDownInfo
.
iconClicked
;
let
range
=
e
.
target
.
range
;
if
(
!
range
||
range
.
startLineNumber
!==
lineNumber
)
{
return
;
}
if
(
iconClicked
)
{
if
(
e
.
target
.
type
!==
MouseTargetType
.
GUTTER_LINE_DECORATIONS
)
{
return
;
}
}
if
(
this
.
_zoneWidget
&&
this
.
_zoneWidget
.
position
&&
this
.
_zoneWidget
.
position
.
lineNumber
===
lineNumber
)
{
return
;
}
if
(
this
.
canAddNewCommentToLine
(
lineNumber
))
{
let
newCommentInfo
=
this
.
getNewCommentAction
(
lineNumber
);
if
(
!
newCommentInfo
)
{
return
;
}
// add new comment
this
.
_reviewPanelVisible
.
set
(
true
);
const
{
replyCommand
,
ownerId
}
=
newCommentInfo
;
this
.
_zoneWidget
=
new
ReviewZoneWidget
(
this
.
editor
,
ownerId
,
{
threadId
:
null
,
resource
:
null
,
comments
:
[],
range
:
{
startLineNumber
:
lineNumber
,
startColumn
:
0
,
endLineNumber
:
lineNumber
,
endColumn
:
0
},
reply
:
replyCommand
,
collapsibleState
:
CommentThreadCollapsibleState
.
Expanded
,
},
replyCommand
,
{},
this
.
themeService
,
this
.
commandService
);
this
.
_zoneWidget
.
onDidClose
(
e
=>
{
this
.
_zoneWidget
=
null
;
});
this
.
_zoneWidget
.
display
(
lineNumber
);
}
}
private
addComment
(
lineNumber
:
number
)
{
let
newCommentInfo
=
this
.
getNewCommentAction
(
lineNumber
);
if
(
!
newCommentInfo
)
{
...
...
@@ -289,7 +210,7 @@ export class ReviewController implements IEditorContribution {
// add new comment
this
.
_reviewPanelVisible
.
set
(
true
);
const
{
replyCommand
,
ownerId
}
=
newCommentInfo
;
this
.
_
zone
Widget
=
new
ReviewZoneWidget
(
this
.
editor
,
ownerId
,
{
this
.
_
newComment
Widget
=
new
ReviewZoneWidget
(
this
.
editor
,
ownerId
,
{
threadId
:
null
,
resource
:
null
,
comments
:
[],
...
...
@@ -303,10 +224,10 @@ export class ReviewController implements IEditorContribution {
collapsibleState
:
CommentThreadCollapsibleState
.
Expanded
,
},
replyCommand
,
{},
this
.
themeService
,
this
.
commandService
);
this
.
_
zone
Widget
.
onDidClose
(
e
=>
{
this
.
_
zone
Widget
=
null
;
this
.
_
newComment
Widget
.
onDidClose
(
e
=>
{
this
.
_
newComment
Widget
=
null
;
});
this
.
_
zone
Widget
.
display
(
lineNumber
);
this
.
_
newComment
Widget
.
display
(
lineNumber
);
}
private
onEditorMouseMove
(
e
:
IEditorMouseEvent
):
void
{
...
...
@@ -315,16 +236,18 @@ export class ReviewController implements IEditorContribution {
this
.
editor
.
removeContentWidget
(
this
.
_newCommentGlyph
);
}
const
showNewCommentHintAtLineNumber
=
e
.
target
.
position
.
lineNumber
;
this
.
_newCommentGlyph
=
this
.
canAddNewCommentToLine
(
e
.
target
.
position
.
lineNumber
)
?
this
.
_newCommentGlyph
=
new
CommentGlyphWidget
(
'
comment-hint
'
,
this
.
editor
,
showNewCommentHintAtLineNumber
,
false
,
()
=>
{
this
.
addComment
(
showNewCommentHintAtLineNumber
);
})
:
this
.
_newCommentGlyph
=
new
CommentGlyphWidget
(
'
comment-hint
'
,
this
.
editor
,
e
.
target
.
position
.
lineNumber
,
true
,
()
=>
{
this
.
notificationService
.
warn
(
'
Commenting is not supported outside of diff chunk areas.
'
);
});
const
lineNumber
=
e
.
target
.
position
.
lineNumber
;
if
(
!
this
.
isExistingCommentThreadAtLine
(
lineNumber
))
{
this
.
_newCommentGlyph
=
this
.
isLineInCommentingRange
(
lineNumber
)
?
this
.
_newCommentGlyph
=
new
CommentGlyphWidget
(
'
comment-hint
'
,
this
.
editor
,
lineNumber
,
false
,
()
=>
{
this
.
addComment
(
lineNumber
);
})
:
this
.
_newCommentGlyph
=
new
CommentGlyphWidget
(
'
comment-hint
'
,
this
.
editor
,
lineNumber
,
true
,
()
=>
{
this
.
notificationService
.
warn
(
'
Commenting is not supported outside of diff chunk areas.
'
);
});
this
.
editor
.
layoutContentWidget
(
this
.
_newCommentGlyph
);
this
.
editor
.
layoutContentWidget
(
this
.
_newCommentGlyph
);
}
}
}
...
...
@@ -346,18 +269,24 @@ export class ReviewController implements IEditorContribution {
return
null
;
}
canAddNewCommentToLin
e
(
line
:
number
):
boolean
{
private
isLineInCommentingRang
e
(
line
:
number
):
boolean
{
return
this
.
_commentInfos
.
some
(
commentInfo
=>
{
const
isInCommentRange
=
commentInfo
.
commentingRanges
.
some
(
range
=>
return
commentInfo
.
commentingRanges
.
some
(
range
=>
range
.
startLineNumber
<=
line
&&
line
<=
range
.
endLineNumber
);
});
}
const
existingCommentThreadAtLine
=
commentInfo
.
threads
.
some
(
thread
=>
private
isExistingCommentThreadAtLine
(
line
:
number
):
boolean
{
const
existingThread
=
this
.
_commentInfos
.
some
(
commentInfo
=>
{
return
commentInfo
.
threads
.
some
(
thread
=>
thread
.
range
.
startLineNumber
===
line
);
return
isInCommentRange
&&
!
existingCommentThreadAtLine
;
});
const
existingNewComment
=
this
.
_newCommentWidget
&&
this
.
_newCommentWidget
.
position
&&
this
.
_newCommentWidget
.
position
.
lineNumber
===
line
;
return
existingThread
||
existingNewComment
;
}
setComments
(
commentInfos
:
modes
.
CommentInfo
[]):
void
{
...
...
@@ -394,7 +323,7 @@ export class ReviewController implements IEditorContribution {
});
// create viewzones
this
.
_
zone
Widgets
.
forEach
(
zone
=>
{
this
.
_
comment
Widgets
.
forEach
(
zone
=>
{
zone
.
dispose
();
});
...
...
@@ -402,7 +331,7 @@ export class ReviewController implements IEditorContribution {
info
.
threads
.
forEach
(
thread
=>
{
let
zoneWidget
=
new
ReviewZoneWidget
(
this
.
editor
,
info
.
owner
,
thread
,
info
.
reply
,
{},
this
.
themeService
,
this
.
commandService
);
zoneWidget
.
display
(
thread
.
range
.
startLineNumber
);
this
.
_
zone
Widgets
.
push
(
zoneWidget
);
this
.
_
comment
Widgets
.
push
(
zoneWidget
);
});
});
}
...
...
@@ -411,13 +340,13 @@ export class ReviewController implements IEditorContribution {
public
closeWidget
():
void
{
this
.
_reviewPanelVisible
.
reset
();
if
(
this
.
_
zone
Widget
)
{
this
.
_
zone
Widget
.
dispose
();
this
.
_
zone
Widget
=
null
;
if
(
this
.
_
newComment
Widget
)
{
this
.
_
newComment
Widget
.
dispose
();
this
.
_
newComment
Widget
=
null
;
}
if
(
this
.
_
zone
Widgets
)
{
this
.
_
zone
Widgets
.
forEach
(
widget
=>
widget
.
dispose
());
if
(
this
.
_
comment
Widgets
)
{
this
.
_
comment
Widgets
.
forEach
(
widget
=>
widget
.
dispose
());
}
this
.
editor
.
focus
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录