根据Visual Studio中的行和列来获取当前打开的文件的角度位置
我正在在Visual Studio中创建一个扩展名,该扩展名应该在当前打开的文件中给出Caret的当前行和当前列。
using System.Linq;
using Microsoft.VisualStudio.Text;
namespace TestProject
{
[Command(PackageIds.MyCommand)]
internal sealed class MyCommand : BaseCommand<MyCommand>
{
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
var docView = await VS.Documents.GetActiveDocumentViewAsync();
SnapshotPoint position = docView.TextView.Caret.Position.BufferPosition;
var selection = docView?.TextView.Selection.SelectedSpans.FirstOrDefault();
if (selection.HasValue)
{
var guid = Guid.NewGuid().ToString();
docView.TextBuffer.Replace(selection.Value, position.ToString());
}
}
}
}
该程序以字符打印位置(例如Caret当前在POS 15),但在行和列方面却没有。
有帮助吗?
I am creating an extension in Visual Studio that should give the current row and current column of the caret in the currently opened file.
using System.Linq;
using Microsoft.VisualStudio.Text;
namespace TestProject
{
[Command(PackageIds.MyCommand)]
internal sealed class MyCommand : BaseCommand<MyCommand>
{
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
var docView = await VS.Documents.GetActiveDocumentViewAsync();
SnapshotPoint position = docView.TextView.Caret.Position.BufferPosition;
var selection = docView?.TextView.Selection.SelectedSpans.FirstOrDefault();
if (selection.HasValue)
{
var guid = Guid.NewGuid().ToString();
docView.TextBuffer.Replace(selection.Value, position.ToString());
}
}
}
}
This program prints the position in terms of character ( Like the caret is currently at pos 15) but not in terms of row and columns.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论