Browse Source

Merge pull request #1370 from AvaloniaUI/fixes/1354-textbox-truncated

Fix TextBox text truncation.
pull/1373/head
Steven Kirk 9 years ago
committed by GitHub
parent
commit
597da9d1ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 65
      src/Avalonia.Controls/TextBox.cs

65
src/Avalonia.Controls/TextBox.cs

@ -98,9 +98,19 @@ namespace Avalonia.Controls
var horizontalScrollBarVisibility = Observable.CombineLatest( var horizontalScrollBarVisibility = Observable.CombineLatest(
this.GetObservable(AcceptsReturnProperty), this.GetObservable(AcceptsReturnProperty),
this.GetObservable(TextWrappingProperty), this.GetObservable(TextWrappingProperty),
(acceptsReturn, wrapping) => acceptsReturn && wrapping == TextWrapping.NoWrap ? (acceptsReturn, wrapping) =>
ScrollBarVisibility.Auto : ScrollBarVisibility.Disabled); {
if (acceptsReturn)
{
return wrapping == TextWrapping.NoWrap ?
ScrollBarVisibility.Visible :
ScrollBarVisibility.Disabled;
}
else
{
return ScrollBarVisibility.Hidden;
}
});
Bind( Bind(
ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollViewer.HorizontalScrollBarVisibilityProperty,
horizontalScrollBarVisibility, horizontalScrollBarVisibility,
@ -487,37 +497,34 @@ namespace Avalonia.Controls
protected override void OnPointerPressed(PointerPressedEventArgs e) protected override void OnPointerPressed(PointerPressedEventArgs e)
{ {
if (e.Source == _presenter) var point = e.GetPosition(_presenter);
{ var index = CaretIndex = _presenter.GetCaretIndex(point);
var point = e.GetPosition(_presenter); var text = Text;
var index = CaretIndex = _presenter.GetCaretIndex(point);
var text = Text;
if (text != null) if (text != null)
{
switch (e.ClickCount)
{ {
switch (e.ClickCount) case 1:
{ SelectionStart = SelectionEnd = index;
case 1: break;
SelectionStart = SelectionEnd = index; case 2:
break; if (!StringUtils.IsStartOfWord(text, index))
case 2: {
if (!StringUtils.IsStartOfWord(text, index)) SelectionStart = StringUtils.PreviousWord(text, index);
{ }
SelectionStart = StringUtils.PreviousWord(text, index);
}
SelectionEnd = StringUtils.NextWord(text, index); SelectionEnd = StringUtils.NextWord(text, index);
break; break;
case 3: case 3:
SelectionStart = 0; SelectionStart = 0;
SelectionEnd = text.Length; SelectionEnd = text.Length;
break; break;
}
} }
e.Device.Capture(_presenter);
e.Handled = true;
} }
e.Device.Capture(_presenter);
e.Handled = true;
} }
protected override void OnPointerMoved(PointerEventArgs e) protected override void OnPointerMoved(PointerEventArgs e)

Loading…
Cancel
Save