feature: select the cursor line by triple-click (#927)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-01-25 11:14:15 +08:00
parent 733ffe1af2
commit aad42a8297
No known key found for this signature in database

View file

@ -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<CommitBaseInfo>();
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);
}