diff --git a/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs b/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs index b55a89698..330ada5fd 100644 --- a/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs +++ b/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs @@ -22,8 +22,6 @@ public interface ITextAreaHandler Range lastSelection { get; set; } int? lastCaretIndex { get; set; } - - void PerformLayout(); } public class EtoTextAreaDelegate : NSTextViewDelegate @@ -81,7 +79,7 @@ public EtoTextView(ITextAreaHandler handler) { Delegate = new EtoTextAreaDelegate { Handler = handler }; AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; - HorizontallyResizable = true; + HorizontallyResizable = false; VerticallyResizable = true; Editable = true; RichText = false; @@ -92,15 +90,6 @@ public EtoTextView(ITextAreaHandler handler) MaxSize = new CGSize(float.MaxValue, float.MaxValue); TextContainer.WidthTracksTextView = true; } - - public override void Layout() - { - if (MacView.NewLayout) - base.Layout(); - (Handler as ITextAreaHandler)?.PerformLayout(); - if (!MacView.NewLayout) - base.Layout(); - } } public class TextAreaHandler : MacView, TextArea.IHandler, ITextAreaHandler @@ -294,19 +283,28 @@ public Font Font public bool Wrap { - get - { - return Control.TextContainer.WidthTracksTextView; - } + get => Control.TextContainer.WidthTracksTextView; set { + if (value == Wrap) + return; + if (value) { + Control.HorizontallyResizable = false; Control.TextContainer.WidthTracksTextView = true; - Control.NeedsLayout = true; + if (Widget.Loaded) + { + // shrink the control and text container to the current width of the visible rectangle + var width = Scroll.DocumentVisibleRect.Size.Width; + Control.SetFrameSize(new CGSize(width, Control.Frame.Height)); + Control.TextContainer.Size = new CGSize(width, float.MaxValue); + Control.NeedsLayout = true; + } } else { + Control.HorizontallyResizable = true; Control.TextContainer.WidthTracksTextView = false; Control.TextContainer.ContainerSize = new CGSize(float.MaxValue, float.MaxValue); } @@ -414,15 +412,6 @@ TextArea ITextAreaHandler.Widget get { return Widget; } } - public void PerformLayout() - { - if (Wrap) - { - // set width of content to the size of the control when wrapping - Control.TextContainer.ContainerSize = new CGSize(Scroll.DocumentVisibleRect.Size.Width, float.MaxValue); - } - } - public TextReplacements TextReplacements { get