Browse Source

Only follow hyperlinks on MouseUp if the mouse wasn't moved since MouseDown.

This allows selecting text inside hyperlinks. Closes #704
pull/909/merge
Daniel Grunwald 8 years ago
parent
commit
c202b9145b
  1. 2
      ILSpy/ILSpy.csproj
  2. 35
      ILSpy/TextView/DecompilerTextView.cs
  3. 10
      ILSpy/TextView/ReferenceElementGenerator.cs

2
ILSpy/ILSpy.csproj

@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="5.0.3" />
<PackageReference Include="AvalonEdit" Version="5.0.4" />
</ItemGroup>
<ItemGroup>

35
ILSpy/TextView/DecompilerTextView.cs

@ -106,7 +106,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -106,7 +106,8 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.Options.RequireControlModifierForHyperlinkClick = false;
textEditor.TextArea.TextView.MouseHover += TextViewMouseHover;
textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
textEditor.TextArea.TextView.MouseDown += TextViewMouseDown;
textEditor.TextArea.PreviewMouseDown += TextAreaMouseDown;
textEditor.TextArea.PreviewMouseUp += TextAreaMouseUp;
textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") });
textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") });
@ -602,12 +603,36 @@ namespace ICSharpCode.ILSpy.TextView @@ -602,12 +603,36 @@ namespace ICSharpCode.ILSpy.TextView
MainWindow.Instance.JumpToReference(reference);
}
void TextViewMouseDown(object sender, MouseButtonEventArgs e)
Point? mouseDownPos;
void TextAreaMouseDown(object sender, MouseButtonEventArgs e)
{
if (GetReferenceSegmentAtMousePosition() == null)
ClearLocalReferenceMarks();
mouseDownPos = e.GetPosition(this);
}
void TextAreaMouseUp(object sender, MouseButtonEventArgs e)
{
if (mouseDownPos == null)
return;
Vector dragDistance = e.GetPosition(this) - mouseDownPos.Value;
if (Math.Abs(dragDistance.X) < SystemParameters.MinimumHorizontalDragDistance
&& Math.Abs(dragDistance.Y) < SystemParameters.MinimumVerticalDragDistance
&& e.ChangedButton == MouseButton.Left)
{
// click without moving mouse
var referenceSegment = GetReferenceSegmentAtMousePosition();
if (referenceSegment == null) {
ClearLocalReferenceMarks();
} else {
JumpToReference(referenceSegment);
textEditor.TextArea.ClearSelection();
}
// cancel mouse selection to avoid AvalonEdit selecting between the new
// cursor position and the mouse position.
textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None;
}
}
void ClearLocalReferenceMarks()
{
foreach (var mark in localReferenceMarks) {

10
ILSpy/TextView/ReferenceElementGenerator.cs

@ -105,16 +105,6 @@ namespace ICSharpCode.ILSpy.TextView @@ -105,16 +105,6 @@ namespace ICSharpCode.ILSpy.TextView
e.Cursor = referenceSegment.IsLocal ? Cursors.Arrow : Cursors.Hand;
}
/// <inheritdoc/>
protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && !e.Handled) {
parent.JumpToReference(referenceSegment);
if(!referenceSegment.IsLocal)
e.Handled = true;
}
}
/// <inheritdoc/>
protected override VisualLineText CreateInstance(int length)
{

Loading…
Cancel
Save