- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Visual Studio SDK 2013,我正在尝试开发一个简单的扩展,旨在修改选定的文本以将其包含在特定的 XML 文档标记中。
我遇到的问题是在替换所选文本时,它只适用于我想避免/改进的非常具体的条件。
要进行真实比较,请注意 Visual Studio 在使用 Ctrl + K + C 和 Ctrl + 注释取消注释所选行时管理所选行缩进的方式的完美性K + U 热键,无论选择索引从哪里开始或结束,因为整个(和非空的)选定行都将被注释并保留缩进级别:
这是我自己面临的挑战,这是我的扩展的奇怪结果,只有当我完全选择包括左侧空格的行时它才能正常工作,否则,我会得到不想要的结果:
在 VB.Net 或 C# 中,如何改进我的代码逻辑以修复上述比较的缺陷?
缺陷基本上是我的扩展不能像 VisualStudio 那样正确处理所选行的起始空格来执行正确的文本替换,所以我得到了我提到的意想不到的结果。
这是我正在使用的相关代码:
Const XmlCommentCharsVB As String = "'''"
Const XmlCommentCharsCS As String = "///"
Private Sub ModifySelectedText()
Dim viewhost As IWpfTextViewHost = Me.GetCurrentViewHost()
Dim textView As IWpfTextView = viewhost.TextView
Dim selectionSpan As VirtualSnapshotSpan = textView.Selection.StreamSelectionSpan
Dim selectedText As String = selectionSpan.SnapshotSpan.GetText
Dim language As String = textView.TextDataModel.ContentType.DisplayName
Dim xmlCommentChars As String = ""
Dim marginLength As Integer =
(From c As Char In selectedText.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).First
Take While Char.IsWhiteSpace(c)
).Count
If String.IsNullOrEmpty(selectedText) Then
Exit Sub
End If
Dim sb As New StringBuilder
Select Case language.ToUpper
Case "BASIC"
xmlCommentChars = XmlCommentCharsVB
Case "CSHARP"
xmlCommentChars = XmlCommentCharsCS
Case Else ' VC++
' Not implemented.
End Select
With sb
.AppendLine(String.Format("{0} <example> This is a code example.", xmlCommentChars))
.AppendLine(String.Format("{0} <code>", xmlCommentChars))
For Each line As String In selectedText.Split({Environment.NewLine}, StringSplitOptions.None)
sb.AppendLine(String.Format("{0} {1}", xmlCommentChars, line.Remove(0, marginLength)))
Next
.AppendLine(String.Format("{0} </code>", xmlCommentChars))
.AppendLine(String.Format("{0} </example>", xmlCommentChars))
End With
selectionSpan.Snapshot.TextBuffer.Replace(selectionSpan.SnapshotSpan, sb.ToString)
End Sub
VisualStudio SDK 没有任何简单的,在 MSDN 引用中找到任何代码示例,或者让最终用户理解 SDK 的“X”成员的目的的非专家解释,真的是一场噩梦,所以我应该自己想象一下“X”成员可以做什么,并将其付诸实践,看看会发生什么……我完全不知道如何解决这个问题。
无论如何,我把目光放在 ITrackingSpan
接口(interface)的 TrackingMode
属性上,它解释了一些关于编辑器边缘的东西......但我测试了它并且似乎它不是指空白边缘。
此外,我认为一个主要问题可能是我以这种方式获取选定的文本:
viewhost.TextView.Selection.StreamSelectionSpan.SnapshotSpan.GetText
我只是得到一个字符串,但 SDK 提供了一个 ITextSnapshot
接口(interface),在 Lines
属性中包含一组字符串,但是,我试图检索所选文本的属性 Snapshot
但我总是获取当前编辑器 View 的所有文本...
最佳答案
// Get the selection object.
var viewHost = GetCurrentViewHost();
ITextSelection selection = viewHost.TextView.Selection;
// Get the start and end points of the selection.
VirtualSnapshotPoint start = selection.Start;
VirtualSnapshotPoint end = selection.End;
// Get the lines that contain the start and end points.
IWpfTextViewLine startLine =
viewHost.TextView.GetTextViewLineContainingBufferPosition(start.Position);
IWpfTextViewLine endLine =
viewHost.TextView.GetTextViewLineContainingBufferPosition(end.Position);
// Get the start and end points of the lines.
SnapshotPoint startLinePoint = startLine.Start;
SnapshotPoint endLinePoint = endLine.End;
// Create a SnapshotSpan for all text to be replaced.
SnapshotSpan span = new SnapshotSpan(startLinePoint, endLinePoint);
// Compute margin.
string[] lines = span.GetText().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
int margin = lines.Select(line =>
{
int count = 0;
while (char.IsWhiteSpace(line[count++])) ;
return --count;
}).Min();
// Construct the replacement string.
StringBuilder sb = new StringBuilder();
foreach (string line in lines)
{
sb.AppendLine(String.Format("{0}{1} {2}", new string(' ', margin), "///", line.Remove(0, margin)));
}
// Perform the replacement.
span.Snapshot.TextBuffer.Replace(span, sb.ToString());
关于c# - VS 2013 SDK : Indentation issues with selected text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165631/
我正在细读 http://www.khronos.org/网站,只找到了 OpenCL 的头文件(不是我不关心的 OpenGL)。如何获取 OpenCL SDK? 最佳答案 AMD 的 ATI Str
Android 项目中最低(最低 sdk)和最高(目标 sdk)级别是否有任何影响。这些东西是否会影响项目的可靠性和效率。 最佳答案 没有影响,如果您以 SDK 级别 8 为目标,那么您的应用将以 9
“min sdk version/target sdk version”和“compile sdk version”有什么区别?我知道 min 和 target sdk 是什么意思,但是 compil
我正在尝试运行 Dji Mobile-Sdk-Android:https://github.com/dji-sdk/Mobile-SDK-Android使用 dji 网站上的说明:https://de
我目前正在向我的 iPhone 应用程序添加新的 Facebook iOS sdk 3.1.1。我看到 sdk 有重大变化。例如。我的旧 sdk 创建一个 Facebook 对象并从 FBReques
我最近刚刚下载了 Xcode 4.6 with mac 10.8.4 with iOS 6.0 SDK package,我立即注意到我无法使用我的 iPhone 3Gs with iOS 4.6 进行
我尝试下载 OpenCL SDK。但是没办法。我有一个 AMD GPU,所以我在谷歌上搜索了 AMD SDK,但是来自谷歌的所有链接和一些教程都被破坏了,不可能通过 AMD 开发者网站找到 sdk。
安装 Google Cloud SDK 后,当我运行时 gcloud 授权登录 我收到一条错误消息: Your browser has been opened to visit: https://a
我一直在 nvidia 网站上搜索 GPU 计算 SDK,因为我正在尝试构建具有 cuda 支持的点云库 (PCL)。但是,在 nvidia 网站上,我只能找到工具包的链接,而不是 SDK 的单个下载
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post一个问题。 2
当我打开 Android SDK 管理器时,会出现一个屏幕“选择要安装的包”。它列出了一堆带有绿色复选标记(已经安装)的软件包,还有一些带有 x's 的软件包,它们没有安装。如果我选择“全部接受”,它
在开发过程中,我发布了 SDK 21 Lollipop,但我无法在我的 KitKat 设备上使用它。应用程序非常简单,我只将 SDK 用于动画和 Material 设计,但是当我尝试对 Play 商店
enter image description here friend 们好 在使用 Linux、jenkins 和 docker 探索 dotnet 核心时,我遇到了构建问题,该问题在标题“/usr
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我创建了一个flutter项目,运行flutter packages get,输出如下:【二】flutter包搞定等待另一个 flutter 命令释放启动锁...第二次运行“flutter packa
这个问题在这里已经有了答案: What are the Android SDK build-tools, platform-tools and tools? And which version sh
我使用 Corona SDK 已经快一年了,并且开发了几个简单的游戏。我现在正在寻找的是在 Corona SDK 中创建 3D 幻觉的某种方法。如果有人有 Corona 3D 方面的经验,我将不胜感激
我有一个CLDC 1.1 / MIDP 2.0项目,可以使用Java ME SDK 3.2很好地进行编译。 最近,我已将Java SE升级到8,结果Java ME SDK开始在Windows启动时显示
有没有办法以编程方式控制连接到华擎主板的 RGB 照明?我知道华硕有一个 Aura SDK,但华擎是否也有一个用于他们的硬件? 如果是,我在哪里可以找到它? 最佳答案 没有用于华擎多彩的 sdk。但是
如何使用 crm 2011 sdk 和 XrmServiceContext 创建事务? 在下一个示例中,'new_brand' 是一些自定义实体。我想创建三个品牌。第三个拥有错误的 OwnerID g
我是一名优秀的程序员,十分优秀!