How to navigate in DocumentView when developing extensions for VS 2022? #355
StanislavKoncebovski
started this conversation in
General
Replies: 1 comment 4 replies
-
The Here are some examples. DocumentView document = await VS.Documents.GetActiveDocumentViewAsync();
// Insert at the start of the document.
document.TextBuffer.Insert(0, "I'm at the start.");
// Insert at the end of the document.
int end = document.TextBuffer.CurrentSnapshot.Length;
document.TextBuffer.Insert(end, "I'm at the end.");
// Inserting at the start of the second line.
ITextSnapshotLine secondLine = document.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1);
document.TextBuffer.Insert(secondLine.Start, "Now I am the second line\n."); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Mads Kristensen gave an enlightening explanation how to insert a GUID at a current caret position. But literally nowhere was I able to find a hint to how to insert a text at a different defined position in the document, e.g. at the very beginning. I failed to find any comprehensible documentation or tutorial to this topic. I guess, a possibility to navigate must be present, but very well hidden from a layman like myself. I spent a couple of hours trying to understand the classes, interfaces, etc. responsible for this episode by brute debugging, but, so far, failed, and I hope that someone in this universe could provide some explanation. TIA!
Beta Was this translation helpful? Give feedback.
All reactions