Skip to content

Instantly share code, notes, and snippets.

//// Moving to a new visual line
// Assuming you have ITextView textView
// 1. Assuming you have the new line number
var bufferLine = textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
var viewLine = textView.GetTextViewLineContainingBufferPosition(bufferLine.Start);
textView.Caret.MoveTo(viewLine); // preserves x coordinate
//// Using the caret directly
// assuming you have ITextView textView
// assuming you have the int line/offset (where offset is from the start of the line)
var position = textView.TextSnapshot.GetLineFromLineNumber(line) + offset;
textView.Caret.MoveTo(position);
textView.Selection.Select(new SnapshotSpan(position, position), false);
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows.Media;
using Microsoft.VisualStudio.ApplicationModel.Environments;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;
testing gist