Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
20e9bd06
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
20e9bd06
编写于
8月 26, 2015
作者:
D
Dustin Campbell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement OpenLineAbove and OpenLineBelow behavior in XML doc comments
上级
aad19b4c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
119 addition
and
21 deletion
+119
-21
src/EditorFeatures/Core/Implementation/DocumentationComments/AbstractDocumentationCommentCommandHandler.cs
...ionComments/AbstractDocumentationCommentCommandHandler.cs
+119
-21
未找到文件。
src/EditorFeatures/Core/Implementation/DocumentationComments/AbstractDocumentationCommentCommandHandler.cs
浏览文件 @
20e9bd06
...
...
@@ -496,27 +496,7 @@ public void ExecuteCommand(ReturnKeyCommandArgs args, Action nextHandler)
return
;
}
var
document
=
args
.
SubjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
nextHandler
();
return
;
}
var
text
=
document
.
GetTextAsync
(
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
);
var
currentLine
=
text
.
Lines
.
GetLineFromPosition
(
caretPosition
);
var
currentLineText
=
currentLine
.
ToString
();
var
offset
=
currentLineText
.
GetFirstNonWhitespaceOffset
();
if
(
offset
==
null
)
{
nextHandler
();
return
;
}
if
(
currentLineText
.
IndexOf
(
ExteriorTriviaText
,
StringComparison
.
Ordinal
)
!=
offset
)
if
(!
CurrentLineStartsWithExteriorTrivia
(
args
.
SubjectBuffer
,
caretPosition
))
{
nextHandler
();
return
;
...
...
@@ -597,7 +577,26 @@ public CommandState GetCommandState(OpenLineAboveCommandArgs args, Func<CommandS
public
void
ExecuteCommand
(
OpenLineAboveCommandArgs
args
,
Action
nextHandler
)
{
// Check to see if the current line starts with exterior trivia. If so, we'll take over.
// If not, let the nextHandler run.
var
caretPosition
=
args
.
TextView
.
GetCaretPoint
(
args
.
SubjectBuffer
)
??
-
1
;
if
(
caretPosition
<
0
)
{
nextHandler
();
return
;
}
if
(!
CurrentLineStartsWithExteriorTrivia
(
args
.
SubjectBuffer
,
caretPosition
))
{
nextHandler
();
return
;
}
// Allow nextHandler() to run and then insert exterior trivia if necessary.
nextHandler
();
InsertExteriorTriviaIfNeeded
(
args
.
TextView
,
args
.
SubjectBuffer
);
}
public
CommandState
GetCommandState
(
OpenLineBelowCommandArgs
args
,
Func
<
CommandState
>
nextHandler
)
...
...
@@ -607,7 +606,106 @@ public CommandState GetCommandState(OpenLineBelowCommandArgs args, Func<CommandS
public
void
ExecuteCommand
(
OpenLineBelowCommandArgs
args
,
Action
nextHandler
)
{
// Check to see if the current line starts with exterior trivia. If so, we'll take over.
// If not, let the nextHandler run.
var
caretPosition
=
args
.
TextView
.
GetCaretPoint
(
args
.
SubjectBuffer
)
??
-
1
;
if
(
caretPosition
<
0
)
{
nextHandler
();
return
;
}
if
(!
CurrentLineStartsWithExteriorTrivia
(
args
.
SubjectBuffer
,
caretPosition
))
{
nextHandler
();
return
;
}
// Allow nextHandler() to run and the insert exterior trivia if necessary.
nextHandler
();
InsertExteriorTriviaIfNeeded
(
args
.
TextView
,
args
.
SubjectBuffer
);
}
private
void
InsertExteriorTriviaIfNeeded
(
ITextView
view
,
ITextBuffer
subjectBuffer
)
{
var
caretPosition
=
view
.
GetCaretPoint
(
subjectBuffer
)
??
-
1
;
if
(
caretPosition
<
0
)
{
return
;
}
var
document
=
subjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
;
}
var
text
=
document
.
GetTextAsync
(
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
);
// We only insert exterior trivia if the current line does not start with exterior trivia
// and the previous line does.
var
currentLine
=
text
.
Lines
.
GetLineFromPosition
(
caretPosition
);
if
(
currentLine
.
LineNumber
<=
0
)
{
return
;
}
var
previousLine
=
text
.
Lines
[
currentLine
.
LineNumber
-
1
];
if
(
LineStartsWithExteriorTrivia
(
currentLine
)
||
!
LineStartsWithExteriorTrivia
(
previousLine
))
{
return
;
}
var
useTabs
=
subjectBuffer
.
GetOption
(
FormattingOptions
.
UseTabs
);
var
tabSize
=
subjectBuffer
.
GetOption
(
FormattingOptions
.
TabSize
);
var
firstNonWhitespaceColumn
=
previousLine
.
GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine
(
tabSize
);
var
indentText
=
firstNonWhitespaceColumn
.
CreateIndentationString
(
useTabs
,
tabSize
)
+
ExteriorTriviaText
+
" "
;
var
firstNonWhitespaceOffset
=
currentLine
.
GetFirstNonWhitespaceOffset
();
var
replaceSpan
=
firstNonWhitespaceOffset
!=
null
?
TextSpan
.
FromBounds
(
currentLine
.
Start
,
firstNonWhitespaceOffset
.
Value
)
:
currentLine
.
Span
;
subjectBuffer
.
Replace
(
replaceSpan
.
ToSpan
(),
indentText
);
view
.
TryMoveCaretToAndEnsureVisible
(
subjectBuffer
.
CurrentSnapshot
.
GetPoint
(
replaceSpan
.
Start
+
indentText
.
Length
));
}
private
bool
CurrentLineStartsWithExteriorTrivia
(
ITextBuffer
subjectBuffer
,
int
position
)
{
var
document
=
subjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
false
;
}
var
text
=
document
.
GetTextAsync
(
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
);
var
currentLine
=
text
.
Lines
.
GetLineFromPosition
(
position
);
return
LineStartsWithExteriorTrivia
(
currentLine
);
}
private
bool
LineStartsWithExteriorTrivia
(
TextLine
line
)
{
var
lineText
=
line
.
ToString
();
var
lineOffset
=
lineText
.
GetFirstNonWhitespaceOffset
()
??
-
1
;
if
(
lineOffset
<
0
)
{
return
false
;
}
return
string
.
CompareOrdinal
(
lineText
,
lineOffset
,
ExteriorTriviaText
,
0
,
ExteriorTriviaText
.
Length
)
==
0
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录