Browse Source

Handle empty text when double-clicking TextBox.

Fixes #458
pull/478/head
Steven Kirk 11 years ago
parent
commit
1d6813b918
  1. 35
      src/Perspex.Controls/TextBox.cs
  2. 5
      src/Perspex.Controls/Utils/StringUtils.cs

35
src/Perspex.Controls/TextBox.cs

@ -373,23 +373,26 @@ namespace Perspex.Controls
var index = CaretIndex = _presenter.GetCaretIndex(point);
var text = Text;
switch (e.ClickCount)
if (text != null)
{
case 1:
SelectionStart = SelectionEnd = index;
break;
case 2:
if (!StringUtils.IsStartOfWord(text, index))
{
SelectionStart = StringUtils.PreviousWord(text, index, false);
}
SelectionEnd = StringUtils.NextWord(text, index, false);
break;
case 3:
SelectionStart = 0;
SelectionEnd = text.Length;
break;
switch (e.ClickCount)
{
case 1:
SelectionStart = SelectionEnd = index;
break;
case 2:
if (!StringUtils.IsStartOfWord(text, index))
{
SelectionStart = StringUtils.PreviousWord(text, index, false);
}
SelectionEnd = StringUtils.NextWord(text, index, false);
break;
case 3:
SelectionStart = 0;
SelectionEnd = text.Length;
break;
}
}
e.Device.Capture(_presenter);

5
src/Perspex.Controls/Utils/StringUtils.cs

@ -21,6 +21,11 @@ namespace Perspex.Controls.Utils
public static bool IsStartOfWord(string text, int index)
{
if (index >= text.Length)
{
return false;
}
// A 'word' starts with an AlphaNumeric or some punctuation symbols immediately
// preceeded by lwsp.
if (index > 0 && !char.IsWhiteSpace(text[index - 1]))

Loading…
Cancel
Save