Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d58da594
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,发现更多精彩内容 >>
提交
d58da594
编写于
8月 04, 2015
作者:
A
Andrew Casey
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4320 from amcasey/GH4235
Fix Interactive window indentation
上级
3ba5bd07
cda9d126
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
129 addition
and
4 deletion
+129
-4
src/InteractiveWindow/Editor/InteractiveWindow.cs
src/InteractiveWindow/Editor/InteractiveWindow.cs
+9
-3
src/InteractiveWindow/EditorTest/InteractiveWindowEditorsFactoryService.cs
...ndow/EditorTest/InteractiveWindowEditorsFactoryService.cs
+3
-1
src/InteractiveWindow/EditorTest/InteractiveWindowTest.csproj
...InteractiveWindow/EditorTest/InteractiveWindowTest.csproj
+1
-0
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
+59
-0
src/InteractiveWindow/EditorTest/TestSmartIndent.cs
src/InteractiveWindow/EditorTest/TestSmartIndent.cs
+57
-0
未找到文件。
src/InteractiveWindow/Editor/InteractiveWindow.cs
浏览文件 @
d58da594
...
...
@@ -527,12 +527,18 @@ private void IndentCurrentLine(SnapshotPoint caretPosition)
var
caretLine
=
caretPosition
.
GetContainingLine
();
var
indentation
=
_smartIndenterService
.
GetDesiredIndentation
(
_textView
,
caretLine
);
if
(
indentation
!=
null
)
if
(
indentation
.
HasValue
)
{
var
promptSpan
=
_projectionSpans
[
_promptLineMapping
[
_promptLineMapping
.
GetMappingIndexByLineNumber
(
caretLine
.
LineNumber
)].
Value
];
Debug
.
Assert
(
promptSpan
.
Kind
==
ReplSpanKind
.
Prompt
||
promptSpan
.
Kind
==
ReplSpanKind
.
SecondaryPrompt
||
promptSpan
.
Kind
==
ReplSpanKind
.
StandardInputPrompt
);
int
promptLength
=
promptSpan
.
Length
;
Debug
.
Assert
(
promptLength
==
2
||
promptLength
==
0
);
// Not required, just expected.
var
adjustedIndentationValue
=
indentation
.
GetValueOrDefault
()
-
promptLength
;
if
(
caretPosition
==
caretLine
.
End
)
{
// create virtual space:
_textView
.
Caret
.
MoveTo
(
new
VirtualSnapshotPoint
(
caretPosition
,
indentation
.
Value
));
_textView
.
Caret
.
MoveTo
(
new
VirtualSnapshotPoint
(
caretPosition
,
adjustedIndentation
Value
));
}
else
{
...
...
@@ -544,7 +550,7 @@ private void IndentCurrentLine(SnapshotPoint caretPosition)
// insert whitespace indentation:
var
options
=
_textView
.
Options
;
string
whitespace
=
GetWhiteSpaceForVirtualSpace
(
indentation
.
Value
,
options
.
IsConvertTabsToSpacesEnabled
()
?
default
(
int
?)
:
options
.
GetTabSize
());
string
whitespace
=
GetWhiteSpaceForVirtualSpace
(
adjustedIndentation
Value
,
options
.
IsConvertTabsToSpacesEnabled
()
?
default
(
int
?)
:
options
.
GetTabSize
());
_currentLanguageBuffer
.
Insert
(
langCaret
.
Value
,
whitespace
);
}
}
...
...
src/InteractiveWindow/EditorTest/InteractiveWindowEditorsFactoryService.cs
浏览文件 @
d58da594
...
...
@@ -10,6 +10,8 @@ namespace Microsoft.VisualStudio.InteractiveWindow.UnitTests
[
Export
(
typeof
(
IInteractiveWindowEditorFactoryService
))]
internal
class
InteractiveWindowEditorsFactoryService
:
IInteractiveWindowEditorFactoryService
{
public
const
string
ContentType
=
"text"
;
private
readonly
ITextBufferFactoryService
_textBufferFactoryService
;
private
readonly
ITextEditorFactoryService
_textEditorFactoryService
;
private
readonly
IContentTypeRegistryService
_contentTypeRegistry
;
...
...
@@ -33,7 +35,7 @@ ITextBuffer IInteractiveWindowEditorFactoryService.CreateAndActivateBuffer(IInte
IContentType
contentType
;
if
(!
window
.
Properties
.
TryGetProperty
(
typeof
(
IContentType
),
out
contentType
))
{
contentType
=
_contentTypeRegistry
.
GetContentType
(
"text"
);
contentType
=
_contentTypeRegistry
.
GetContentType
(
ContentType
);
}
return
_textBufferFactoryService
.
CreateTextBuffer
(
contentType
);
...
...
src/InteractiveWindow/EditorTest/InteractiveWindowTest.csproj
浏览文件 @
d58da594
...
...
@@ -88,6 +88,7 @@
<Compile
Include=
"InteractiveWindowTests.cs"
/>
<Compile
Include=
"TestContentTypeDefinition.cs"
/>
<Compile
Include=
"TestInteractiveEngine.cs"
/>
<Compile
Include=
"TestSmartIndent.cs"
/>
<Compile
Include=
"TestWaitIndicator.cs"
/>
</ItemGroup>
<ItemGroup>
...
...
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
浏览文件 @
d58da594
...
...
@@ -408,5 +408,64 @@ public void CallCancelOnNonUIThread()
{
Task
.
Run
(()
=>
Window
.
Operations
.
Cancel
()).
PumpingWait
();
}
[
WorkItem
(
4235
,
"https://github.com/dotnet/roslyn/issues/4235"
)]
[
Fact
]
public
void
TestIndentation1
()
{
TestIndentation
(
indentSize
:
1
);
}
[
WorkItem
(
4235
,
"https://github.com/dotnet/roslyn/issues/4235"
)]
[
Fact
]
public
void
TestIndentation2
()
{
TestIndentation
(
indentSize
:
2
);
}
[
WorkItem
(
4235
,
"https://github.com/dotnet/roslyn/issues/4235"
)]
[
Fact
]
public
void
TestIndentation3
()
{
TestIndentation
(
indentSize
:
3
);
}
[
WorkItem
(
4235
,
"https://github.com/dotnet/roslyn/issues/4235"
)]
[
Fact
]
public
void
TestIndentation4
()
{
TestIndentation
(
indentSize
:
4
);
}
private
void
TestIndentation
(
int
indentSize
)
{
const
int
promptWidth
=
2
;
_testHost
.
ExportProvider
.
GetExport
<
TestSmartIndentProvider
>().
Value
.
SmartIndent
=
new
TestSmartIndent
(
promptWidth
,
promptWidth
+
indentSize
,
promptWidth
);
AssertCaretVirtualPosition
(
0
,
promptWidth
);
Window
.
InsertCode
(
"{"
);
AssertCaretVirtualPosition
(
0
,
promptWidth
+
1
);
Window
.
Operations
.
BreakLine
();
AssertCaretVirtualPosition
(
1
,
promptWidth
+
indentSize
);
Window
.
InsertCode
(
"Console.WriteLine();"
);
Window
.
Operations
.
BreakLine
();
AssertCaretVirtualPosition
(
2
,
promptWidth
);
Window
.
InsertCode
(
"}"
);
AssertCaretVirtualPosition
(
2
,
promptWidth
+
1
);
}
private
void
AssertCaretVirtualPosition
(
int
expectedLine
,
int
expectedColumn
)
{
ITextSnapshotLine
actualLine
;
int
actualColumn
;
Window
.
TextView
.
Caret
.
Position
.
VirtualBufferPosition
.
GetLineAndColumn
(
out
actualLine
,
out
actualColumn
);
Assert
.
Equal
(
expectedLine
,
actualLine
.
LineNumber
);
Assert
.
Equal
(
expectedColumn
,
actualColumn
);
}
}
}
src/InteractiveWindow/EditorTest/TestSmartIndent.cs
0 → 100644
浏览文件 @
d58da594
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.ComponentModel.Composition
;
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor
;
using
Microsoft.VisualStudio.Utilities
;
namespace
Microsoft.VisualStudio.InteractiveWindow.UnitTests
{
internal
class
TestSmartIndent
:
ISmartIndent
{
private
readonly
int
[]
_lineToIndentMap
;
public
TestSmartIndent
(
params
int
[]
lineToIndentMap
)
{
_lineToIndentMap
=
lineToIndentMap
;
}
int
?
ISmartIndent
.
GetDesiredIndentation
(
ITextSnapshotLine
line
)
{
return
_lineToIndentMap
[
line
.
LineNumber
];
}
void
IDisposable
.
Dispose
()
{
}
}
internal
class
DummySmartIndent
:
ISmartIndent
{
public
static
readonly
ISmartIndent
Instance
=
new
DummySmartIndent
();
private
DummySmartIndent
()
{
}
int
?
ISmartIndent
.
GetDesiredIndentation
(
ITextSnapshotLine
line
)
{
return
null
;
}
void
IDisposable
.
Dispose
()
{
}
}
[
Export
(
typeof
(
TestSmartIndentProvider
))]
[
Export
(
typeof
(
ISmartIndentProvider
))]
[
ContentType
(
InteractiveWindowEditorsFactoryService
.
ContentType
)]
internal
class
TestSmartIndentProvider
:
ISmartIndentProvider
{
public
ISmartIndent
SmartIndent
;
ISmartIndent
ISmartIndentProvider
.
CreateSmartIndent
(
ITextView
textView
)
=>
SmartIndent
??
DummySmartIndent
.
Instance
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录