This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testing gist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.Composition; | |
using Microsoft.VisualStudio.Utilities; | |
using Microsoft.VisualStudio.Text.Editor; | |
using Microsoft.VisualStudio.Text.Outlining; | |
using System.Windows.Input; | |
using Microsoft.VisualStudio.Text; | |
namespace CollapseAllButThis | |
{ | |
[Export(typeof(IKeyProcessorProvider))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make the background goldenrod yellow :) | |
[Export(typeof(IWpfTextViewCreationListener))] | |
[ContentType("text")] | |
[TextViewRole(PredefinedTextViewRoles.Document)] | |
internal sealed class CreationListener : IWpfTextViewCreationListener | |
{ | |
public void TextViewCreated(IWpfTextView textView, IEnvironment context) | |
{ | |
textView.Background = Brushes.PaleGoldenrod; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// starting with a SnapshotPoint, text line, or SnapshotSpan | |
SnapshotPoint point; | |
ITextSnapshotLine line = point.GetContainingLine(); | |
SnapshotSpan extent = line.Extent; | |
SnapshotPoint start; | |
for (start = extent.Start; start < line.End && char.IsWhitespace(start.GetChar()); start++); | |
SnapshotSpan extentExcludingLeadingWhitespace = new SnapshotPoint(start, extent.End); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Export(typeof(ITaggerProvider))] | |
[TagType(typeof(SquiggleTag))] // this will probably be "IErrorTag" in the next release | |
[ContentType("text")] // "text" is the base of basically all content types | |
internal sealed class ToDoTaggerProvider : ITaggerProvider | |
{ | |
// Note: the "context" arg has been removed, but is still there in Beta 1 | |
public ITagger<T> GetTagger<T>(ITextBuffer buffer, IEnvironment context) where T : ITag | |
{ | |
return new ToDoTagger() as ITagger<T>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class ToDoTagger : ITagger<SquiggleTag> | |
{ | |
// Our simple tagger can ignore this for now | |
public Event<SnapshotSpanChangedArgs> TagsChanged; | |
public IEnumerable<ITagSpan<SquiggleTag>> GetTags(NormalizedSnapshotSpanCollection spans) | |
{ | |
foreach(SnapshotSpan span in spans) | |
{ | |
string spanText = span.GetText(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Export(typeof(ITaggerProvider))] | |
[TagType(typeof(SquiggleTag))] // this will probably be "IErrorTag" in the next release | |
[ContentType("text")] // "text" is the base of basically all content types | |
internal sealed class ToDoTaggerProvider : ITaggerProvider | |
{ | |
// Note: the "context" arg has been removed, but is still there in Beta 1 | |
public ITagger<T> GetTagger<T>(ITextBuffer buffer, IEnvironment context) where T : ITag | |
{ | |
return new ToDoTagger() as ITagger<T>; | |
} |
OlderNewer