Skip to content

Commit 056446c

Browse files
committed
guard some GetActiveTerminalControl calls
1 parent 25947c2 commit 056446c

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,21 +1416,24 @@ namespace winrt::TerminalApp::implementation
14161416
{
14171417
if (const auto terminalTab{ _GetFocusedTabImpl() })
14181418
{
1419-
uint32_t realRowsToScroll;
1420-
if (rowsToScroll == nullptr)
1419+
if (const auto& termControl{ terminalTab->GetActiveTerminalControl() })
14211420
{
1422-
// The magic value of WHEEL_PAGESCROLL indicates that we need to scroll the entire page
1423-
realRowsToScroll = _systemRowsToScroll == WHEEL_PAGESCROLL ?
1424-
terminalTab->GetActiveTerminalControl().ViewHeight() :
1425-
_systemRowsToScroll;
1426-
}
1427-
else
1428-
{
1429-
// use the custom value specified in the command
1430-
realRowsToScroll = rowsToScroll.Value();
1421+
uint32_t realRowsToScroll;
1422+
if (rowsToScroll == nullptr)
1423+
{
1424+
// The magic value of WHEEL_PAGESCROLL indicates that we need to scroll the entire page
1425+
realRowsToScroll = _systemRowsToScroll == WHEEL_PAGESCROLL ?
1426+
termControl.ViewHeight() :
1427+
_systemRowsToScroll;
1428+
}
1429+
else
1430+
{
1431+
// use the custom value specified in the command
1432+
realRowsToScroll = rowsToScroll.Value();
1433+
}
1434+
auto scrollDelta = _ComputeScrollDelta(scrollDirection, realRowsToScroll);
1435+
terminalTab->Scroll(scrollDelta);
14311436
}
1432-
auto scrollDelta = _ComputeScrollDelta(scrollDirection, realRowsToScroll);
1433-
terminalTab->Scroll(scrollDelta);
14341437
}
14351438
}
14361439

@@ -2093,8 +2096,10 @@ namespace winrt::TerminalApp::implementation
20932096
if (warnMultiLine)
20942097
{
20952098
const auto focusedTab = _GetFocusedTabImpl();
2099+
const auto& termControl{ focusedTab->GetActiveTerminalControl() };
20962100
// Do not warn about multi line pasting if the current tab has bracketed paste enabled.
2097-
warnMultiLine = warnMultiLine && !focusedTab->GetActiveTerminalControl().BracketedPasteEnabled();
2101+
warnMultiLine = warnMultiLine &&
2102+
(termControl && !termControl.BracketedPasteEnabled());
20982103
}
20992104

21002105
// We have to initialize the dialog here to be able to change the text of the text block within it
@@ -2402,11 +2407,14 @@ namespace winrt::TerminalApp::implementation
24022407
// TODO GH#5047 If we cache the NewTerminalArgs, we no longer need to do this.
24032408
profile = GetClosestProfileForDuplicationOfProfile(profile);
24042409
controlSettings = TerminalSettings::CreateWithProfile(_settings, profile, *_bindings);
2405-
const auto workingDirectory = focusedTab->GetActiveTerminalControl().WorkingDirectory();
2406-
const auto validWorkingDirectory = !workingDirectory.empty();
2407-
if (validWorkingDirectory)
2410+
if (const auto& control{ focusedTab->GetActiveTerminalControl() })
24082411
{
2409-
controlSettings.DefaultSettings().StartingDirectory(workingDirectory);
2412+
const auto workingDirectory = control.WorkingDirectory();
2413+
const auto validWorkingDirectory = !workingDirectory.empty();
2414+
if (validWorkingDirectory)
2415+
{
2416+
controlSettings.DefaultSettings().StartingDirectory(workingDirectory);
2417+
}
24102418
}
24112419
}
24122420
}

0 commit comments

Comments
 (0)