Skip to content

Commit dab113a

Browse files
author
RandomEngy
committed
Changing number box to only select all after the initial focusing click and if
the mouseup comes soon enough after the mousedown.
1 parent 28cd7b3 commit dab113a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

VidCoder/Controls/NumberBox.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
LostFocus="NumberBoxLostFocus"
139139
PreviewTextInput="NumberBoxPreviewTextInput"
140140
PreviewKeyDown="NumberBoxPreviewKeyDown"
141+
PreviewMouseDown="NumberBoxPreviewMouseDown"
141142
PreviewMouseUp="NumberBoxPreviewMouseUp"
142143
TextChanged="NumberBoxTextChanged" />
143144
<Grid

VidCoder/Controls/NumberBox.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ namespace VidCoder.Controls
1212
/// </summary>
1313
public partial class NumberBox : UserControl
1414
{
15+
private static readonly TimeSpan SelectAllThreshold = TimeSpan.FromMilliseconds(500);
16+
1517
private RefireControl refireControl;
1618

1719
private string noneCaption;
1820
private bool hasFocus;
21+
private DateTime lastFocusMouseDown;
1922

2023
public NumberBox()
2124
{
@@ -310,9 +313,18 @@ private void NumberBoxPreviewKeyDown(object sender, KeyEventArgs e)
310313
}
311314
}
312315

316+
private void NumberBoxPreviewMouseDown(object sender, MouseButtonEventArgs e)
317+
{
318+
if (!this.hasFocus)
319+
{
320+
this.lastFocusMouseDown = DateTime.Now;
321+
}
322+
}
323+
313324
private void NumberBoxPreviewMouseUp(object sender, MouseButtonEventArgs e)
314325
{
315-
if (this.SelectAllOnClick)
326+
// If this mouse up is soon enough after an initial click on the box, select all.
327+
if (this.SelectAllOnClick && DateTime.Now - this.lastFocusMouseDown < SelectAllThreshold)
316328
{
317329
this.Dispatcher.BeginInvoke(new Action(() => this.numberBox.SelectAll()));
318330
}

0 commit comments

Comments
 (0)