From c97c4b365078aa9100792078de0374300b89003d Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 15 Jan 2021 11:48:14 -0600 Subject: [PATCH] Added negative value check for resize newsize (#8792) ## Summary of the Pull Request Adds a negative value check for when the terminal window is hidden/show in VS ## References [Bug 1265984](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1265984): [Terminal] VS crashes when clicking the hidden terminal tab ## PR Checklist * [ ] Closes #xxx * [ ] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Manual validation. --- .../WpfTerminalControl/TerminalControl.xaml.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs index 87c2df25a06d..cb8fa0d255b0 100644 --- a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs +++ b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs @@ -143,11 +143,16 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { var dpiScale = VisualTreeHelper.GetDpi(this); - // termContainer requires scaled sizes. + var newSizeWidth = (sizeInfo.NewSize.Width - this.scrollbar.ActualWidth) * dpiScale.DpiScaleX; + newSizeWidth = newSizeWidth < 0 ? 0 : newSizeWidth; + + var newSizeHeight = sizeInfo.NewSize.Height * dpiScale.DpiScaleY; + newSizeHeight = newSizeHeight < 0 ? 0 : newSizeHeight; + this.termContainer.TerminalControlSize = new Size() { - Width = (sizeInfo.NewSize.Width - this.scrollbar.ActualWidth) * dpiScale.DpiScaleX, - Height = sizeInfo.NewSize.Height * dpiScale.DpiScaleY, + Width = newSizeWidth, + Height = newSizeHeight, }; if (!this.AutoResize)