Skip to content

Instantly share code, notes, and snippets.

@NoahRic
Created October 20, 2009 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahRic/214001 to your computer and use it in GitHub Desktop.
Save NoahRic/214001 to your computer and use it in GitHub Desktop.
/* TripleClickMouseProcessor.cs
* Copyright Noah Richards, licensed under the Ms-PL.
* Check out blogs.msdn.com/noahric for more information about the Visual Studio 2010 editor!
*/
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Input;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
namespace TripleClick
{
[Export(typeof(IMouseProcessorProvider))]
[Name("TripleClick")]
[Order(Before = "DragDrop")]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
internal sealed class TripleClickMouseProcessorProvider : IMouseProcessorProvider
{
public IMouseProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
{
return new TripleClickMouseProcessor(wpfTextView);
}
}
internal sealed class TripleClickMouseProcessor : MouseProcessorBase
{
private IWpfTextView _view;
public TripleClickMouseProcessor(IWpfTextView view)
{
_view = view;
}
public override void PreprocessMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (e.ClickCount != 3)
return;
Point viewPoint = RelativeToView(e.GetPosition(_view.VisualElement));
var line = _view.TextViewLines.GetTextViewLineContainingYCoordinate(viewPoint.Y);
if (line == null)
return;
var extent = line.Extent;
if (!extent.IsEmpty)
{
_view.Selection.Select(extent, false);
_view.Caret.MoveTo(_view.Selection.ActivePoint);
}
else
{
_view.Selection.Clear();
_view.Caret.MoveTo(extent.Start.TranslateTo(_view.TextSnapshot, PointTrackingMode.Negative));
}
e.Handled = true;
}
Point RelativeToView(Point position)
{
return new Point(position.X - _view.ViewportLeft, position.Y - _view.ViewportTop);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment