Skip to content

Commit aad42a8

Browse files
committed
feature: select the cursor line by triple-click (#927)
Signed-off-by: leo <[email protected]>
1 parent 733ffe1 commit aad42a8

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

src/Views/CommitMessagePresenter.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,18 @@ protected override void OnPointerMoved(PointerEventArgs e)
172172

173173
protected override void OnPointerPressed(PointerPressedEventArgs e)
174174
{
175+
var point = e.GetCurrentPoint(this);
176+
175177
if (_lastHover != null)
176178
{
179+
var link = _lastHover.Link;
177180
e.Pointer.Capture(null);
178181

179182
if (_lastHover.IsCommitSHA)
180183
{
181184
var parentView = this.FindAncestorOfType<CommitBaseInfo>();
182185
if (parentView is { DataContext: ViewModels.CommitDetail detail })
183186
{
184-
var point = e.GetCurrentPoint(this);
185-
var link = _lastHover.Link;
186-
187187
if (point.Properties.IsLeftButtonPressed)
188188
{
189189
detail.NavigateTo(_lastHover.Link);
@@ -217,9 +217,6 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
217217
}
218218
else
219219
{
220-
var point = e.GetCurrentPoint(this);
221-
var link = _lastHover.Link;
222-
223220
if (point.Properties.IsLeftButtonPressed)
224221
{
225222
Native.OS.OpenBrowser(link);
@@ -255,6 +252,49 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
255252
return;
256253
}
257254

255+
if (point.Properties.IsLeftButtonPressed && e.ClickCount == 3)
256+
{
257+
var text = Inlines?.Text;
258+
if (string.IsNullOrEmpty(text))
259+
{
260+
e.Handled = true;
261+
return;
262+
}
263+
264+
var position = e.GetPosition(this) - new Point(Padding.Left, Padding.Top);
265+
var x = Math.Min(Math.Max(position.X, 0), Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0));
266+
var y = Math.Min(Math.Max(position.Y, 0), Math.Max(TextLayout.Height, 0));
267+
position = new Point(x, y);
268+
269+
var textPos = TextLayout.HitTestPoint(position).TextPosition;
270+
var lineStart = 0;
271+
var lineEnd = text.IndexOf('\n', lineStart);
272+
if (lineEnd <= 0)
273+
{
274+
lineEnd = text.Length;
275+
}
276+
else
277+
{
278+
while (lineEnd < textPos)
279+
{
280+
lineStart = lineEnd + 1;
281+
lineEnd = text.IndexOf('\n', lineStart);
282+
if (lineEnd == -1)
283+
{
284+
lineEnd = text.Length;
285+
break;
286+
}
287+
}
288+
}
289+
290+
SetCurrentValue(SelectionStartProperty, lineStart);
291+
SetCurrentValue(SelectionEndProperty, lineEnd);
292+
293+
e.Pointer.Capture(this);
294+
e.Handled = true;
295+
return;
296+
}
297+
258298
base.OnPointerPressed(e);
259299
}
260300

0 commit comments

Comments
 (0)