diff --git a/src/Views/CommitMessagePresenter.cs b/src/Views/CommitMessagePresenter.cs index 0ae3d6cf..a6eee1b3 100644 --- a/src/Views/CommitMessagePresenter.cs +++ b/src/Views/CommitMessagePresenter.cs @@ -172,8 +172,11 @@ namespace SourceGit.Views protected override void OnPointerPressed(PointerPressedEventArgs e) { + var point = e.GetCurrentPoint(this); + if (_lastHover != null) { + var link = _lastHover.Link; e.Pointer.Capture(null); if (_lastHover.IsCommitSHA) @@ -181,9 +184,6 @@ namespace SourceGit.Views var parentView = this.FindAncestorOfType(); if (parentView is { DataContext: ViewModels.CommitDetail detail }) { - var point = e.GetCurrentPoint(this); - var link = _lastHover.Link; - if (point.Properties.IsLeftButtonPressed) { detail.NavigateTo(_lastHover.Link); @@ -217,9 +217,6 @@ namespace SourceGit.Views } else { - var point = e.GetCurrentPoint(this); - var link = _lastHover.Link; - if (point.Properties.IsLeftButtonPressed) { Native.OS.OpenBrowser(link); @@ -255,6 +252,49 @@ namespace SourceGit.Views return; } + if (point.Properties.IsLeftButtonPressed && e.ClickCount == 3) + { + var text = Inlines?.Text; + if (string.IsNullOrEmpty(text)) + { + e.Handled = true; + return; + } + + var position = e.GetPosition(this) - new Point(Padding.Left, Padding.Top); + var x = Math.Min(Math.Max(position.X, 0), Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0)); + var y = Math.Min(Math.Max(position.Y, 0), Math.Max(TextLayout.Height, 0)); + position = new Point(x, y); + + var textPos = TextLayout.HitTestPoint(position).TextPosition; + var lineStart = 0; + var lineEnd = text.IndexOf('\n', lineStart); + if (lineEnd <= 0) + { + lineEnd = text.Length; + } + else + { + while (lineEnd < textPos) + { + lineStart = lineEnd + 1; + lineEnd = text.IndexOf('\n', lineStart); + if (lineEnd == -1) + { + lineEnd = text.Length; + break; + } + } + } + + SetCurrentValue(SelectionStartProperty, lineStart); + SetCurrentValue(SelectionEndProperty, lineEnd); + + e.Pointer.Capture(this); + e.Handled = true; + return; + } + base.OnPointerPressed(e); }