Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Simple TextBuffer Insert

$
0
0

I have a simple piece of code that uses ITextBuffer interface to insert some text.  Basically, I have to delete the line and then add some new text. I am not sure if this is the best way to do it but I have had some success in getting the code into the correct location using the following:

var buffer = (ITextBuffer) sender; var startOfLine = curerntLine.Start.Position; buffer.Delete(new Span(curerntLine.Start, curerntLine.Length));

// Insert code into the current line. var edit = buffer.CreateEdit(); edit.Insert(startOfLine, text); edit.Apply(); // Finished.


One of the problems is that when the code it inserted the cursor automatically ends up at the end of the document. The next. This is a problem for me. I need the cursor to be at the end of the inserted text so that more user input can be added directly after. 

I would still like to use the ITextBuffer interface instead of TextDocument. 


jwize



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>