Skip to content

Commit 868ffe8

Browse files
authored
Merge pull request #2631 from cwensley/curtis/mac-fix-textarea-visibility
Mac: Fix Rich/TextArea to show text when initially shown.
2 parents 2753ba5 + 4818b79 commit 868ffe8

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/Eto.Mac/Forms/Controls/TextAreaHandler.cs

+15-26
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public interface ITextAreaHandler
2222

2323
Range<int> lastSelection { get; set; }
2424
int? lastCaretIndex { get; set; }
25-
26-
void PerformLayout();
2725
}
2826

2927
public class EtoTextAreaDelegate : NSTextViewDelegate
@@ -81,7 +79,7 @@ public EtoTextView(ITextAreaHandler handler)
8179
{
8280
Delegate = new EtoTextAreaDelegate { Handler = handler };
8381
AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
84-
HorizontallyResizable = true;
82+
HorizontallyResizable = false;
8583
VerticallyResizable = true;
8684
Editable = true;
8785
RichText = false;
@@ -92,15 +90,6 @@ public EtoTextView(ITextAreaHandler handler)
9290
MaxSize = new CGSize(float.MaxValue, float.MaxValue);
9391
TextContainer.WidthTracksTextView = true;
9492
}
95-
96-
public override void Layout()
97-
{
98-
if (MacView.NewLayout)
99-
base.Layout();
100-
(Handler as ITextAreaHandler)?.PerformLayout();
101-
if (!MacView.NewLayout)
102-
base.Layout();
103-
}
10493
}
10594

10695
public class TextAreaHandler<TControl, TCallback> : MacView<NSTextView, TControl, TCallback>, TextArea.IHandler, ITextAreaHandler
@@ -294,19 +283,28 @@ public Font Font
294283

295284
public bool Wrap
296285
{
297-
get
298-
{
299-
return Control.TextContainer.WidthTracksTextView;
300-
}
286+
get => Control.TextContainer.WidthTracksTextView;
301287
set
302288
{
289+
if (value == Wrap)
290+
return;
291+
303292
if (value)
304293
{
294+
Control.HorizontallyResizable = false;
305295
Control.TextContainer.WidthTracksTextView = true;
306-
Control.NeedsLayout = true;
296+
if (Widget.Loaded)
297+
{
298+
// shrink the control and text container to the current width of the visible rectangle
299+
var width = Scroll.DocumentVisibleRect.Size.Width;
300+
Control.SetFrameSize(new CGSize(width, Control.Frame.Height));
301+
Control.TextContainer.Size = new CGSize(width, float.MaxValue);
302+
Control.NeedsLayout = true;
303+
}
307304
}
308305
else
309306
{
307+
Control.HorizontallyResizable = true;
310308
Control.TextContainer.WidthTracksTextView = false;
311309
Control.TextContainer.ContainerSize = new CGSize(float.MaxValue, float.MaxValue);
312310
}
@@ -414,15 +412,6 @@ TextArea ITextAreaHandler.Widget
414412
get { return Widget; }
415413
}
416414

417-
public void PerformLayout()
418-
{
419-
if (Wrap)
420-
{
421-
// set width of content to the size of the control when wrapping
422-
Control.TextContainer.ContainerSize = new CGSize(Scroll.DocumentVisibleRect.Size.Width, float.MaxValue);
423-
}
424-
}
425-
426415
public TextReplacements TextReplacements
427416
{
428417
get

0 commit comments

Comments
 (0)