Skip to content

Commit

Permalink
Add the ability to toggle a pane's split direction
Browse files Browse the repository at this point in the history
- Switch from horizontal to vertical split (and vice versa)
- Propogate new borders through to children.
  • Loading branch information
Rosefield committed Jul 19, 2021
1 parent 7f3bc3c commit a4fa0ae
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"toggleFocusMode",
"toggleFullscreen",
"togglePaneZoom",
"togglePaneSplit",
"toggleReadOnlyMode",
"toggleShaderEffects",
"wt",
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ namespace winrt::TerminalApp::implementation
}
}

void TerminalPage::_HandleTogglePaneSplit(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
_TogglePaneSplit();
args.Handled(true);
}

void TerminalPage::_HandleTogglePaneZoom(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
Expand Down
66 changes: 60 additions & 6 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,26 @@ void Pane::_UpdateBorders()
_border.BorderThickness(ThicknessHelper::FromLengths(left, top, right, bottom));
}

// Method Description:
// - Find the borders for the leaf pane, or the shared borders for child panes.
// Arguments:
// - <none>
// Return Value:
// - <none>
Borders Pane::_GetCommonBorders()
{
if (_IsLeaf())
{
return _borders;
}

return _firstChild->_GetCommonBorders() & _secondChild->_GetCommonBorders();
}

// Method Description:
// - Sets the row/column of our child UI elements, to match our current split type.
// - In case the split definition or parent borders were changed, this recursively
// updates the children as well.
// Arguments:
// - <none>
// Return Value:
Expand All @@ -1135,9 +1153,8 @@ void Pane::_ApplySplitDefinitions()
_secondChild->_borders = _borders | Borders::Left;
_borders = Borders::None;

_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();
_firstChild->_ApplySplitDefinitions();
_secondChild->_ApplySplitDefinitions();
}
else if (_splitState == SplitState::Horizontal)
{
Expand All @@ -1148,10 +1165,10 @@ void Pane::_ApplySplitDefinitions()
_secondChild->_borders = _borders | Borders::Top;
_borders = Borders::None;

_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();
_firstChild->_ApplySplitDefinitions();
_secondChild->_ApplySplitDefinitions();
}
_UpdateBorders();
}

// Method Description:
Expand Down Expand Up @@ -1412,6 +1429,43 @@ std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Pane::Split(SplitState s
return _Split(splitType, splitSize, profile, control);
}

// Method Description:
// - Toggle the split orientation of the currently focused pane
// Arguments:
// - <none>
// Return Value:
// - true if a split was changed
bool Pane::TogglePaneSplit()
{
// If we are a leaf there is no split to toggle.
if (_IsLeaf())
{
return false;
}

// Check if either our first or second child is the currently focused leaf.
// If they are then switch the split orientation on the current pane.
const bool firstIsFocused = _firstChild->_IsLeaf() && _firstChild->_lastActive;
const bool secondIsFocused = _secondChild->_IsLeaf() && _secondChild->_lastActive;
if (firstIsFocused || secondIsFocused)
{
// Switch the split orientation
_splitState = _splitState == SplitState::Horizontal ? SplitState::Vertical : SplitState::Horizontal;

// then update the borders and positioning on ourselves and our children.
_borders = _GetCommonBorders();
// Since we changed if we are using rows/columns, make sure we remove the old definitions
_root.ColumnDefinitions().Clear();
_root.RowDefinitions().Clear();
_CreateRowColDefinitions();
_ApplySplitDefinitions();

return true;
}

return _firstChild->TogglePaneSplit() || _secondChild->TogglePaneSplit();
}

// Method Description:
// - Converts an "automatic" split type into either Vertical or Horizontal,
// based upon the current dimensions of the Pane.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Pane : public std::enable_shared_from_this<Pane>
const float splitSize,
const GUID& profile,
const winrt::Microsoft::Terminal::Control::TermControl& control);
bool TogglePaneSplit();
float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;
std::optional<winrt::Microsoft::Terminal::Settings::Model::SplitState> PreCalculateAutoSplit(const std::shared_ptr<Pane> target,
const winrt::Windows::Foundation::Size parentSize) const;
Expand Down Expand Up @@ -135,6 +136,7 @@ class Pane : public std::enable_shared_from_this<Pane>
void _ApplySplitDefinitions();
void _SetupEntranceAnimation();
void _UpdateBorders();
Borders _GetCommonBorders();

bool _Resize(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction);
bool _NavigateFocus(const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction);
Expand Down
15 changes: 15 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,21 @@ namespace winrt::TerminalApp::implementation
CATCH_LOG();
}

// Method Description:
// - Switches the split orientation of the currently focused pane.
// Arguments:
// - <none>
// Return Value:
// - <none>
void TerminalPage::_TogglePaneSplit()
{
if (const auto terminalTab{ _GetFocusedTabImpl() })
{
_UnZoomIfNeeded();
terminalTab->TogglePaneSplit();
}
}

// Method Description:
// - Attempt to move a separator between panes, as to resize each child on
// either size of the separator. See Pane::ResizePane for details.
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ namespace winrt::TerminalApp::implementation
const float splitSize = 0.5f,
const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs = nullptr);
void _ResizePane(const Microsoft::Terminal::Settings::Model::ResizeDirection& direction);
void _TogglePaneSplit();

void _ScrollPage(ScrollDirection scrollDirection);
void _ScrollToBufferEdge(ScrollDirection scrollDirection);
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@ namespace winrt::TerminalApp::implementation
_UpdateActivePane(second);
}

// Method Description:
// - Find the currently active pane, and then switch the split direction of
// its parent. E.g. switch from Horizontal to Vertical.
// Return Value:
// - <none>
void TerminalTab::TogglePaneSplit()
{
_rootPane->TogglePaneSplit();
}

// Method Description:
// - See Pane::CalcSnappedDimension
float TerminalTab::CalcSnappedDimension(const bool widthOrHeight, const float dimension) const
Expand Down Expand Up @@ -1188,6 +1198,7 @@ namespace winrt::TerminalApp::implementation
EnterZoom();
}
}

void TerminalTab::EnterZoom()
{
_zoomedPane = _activePane;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace winrt::TerminalApp::implementation
const GUID& profile,
winrt::Microsoft::Terminal::Control::TermControl& control);

void TogglePaneSplit();
winrt::fire_and_forget UpdateIcon(const winrt::hstring iconPath);
winrt::fire_and_forget HideIcon(const bool hide);

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static constexpr std::string_view ToggleCommandPaletteKey{ "commandPalette" };
static constexpr std::string_view ToggleFocusModeKey{ "toggleFocusMode" };
static constexpr std::string_view ToggleFullscreenKey{ "toggleFullscreen" };
static constexpr std::string_view TogglePaneZoomKey{ "togglePaneZoom" };
static constexpr std::string_view TogglePaneSplitKey{ "togglePaneSplit" };
static constexpr std::string_view LegacyToggleRetroEffectKey{ "toggleRetroEffect" };
static constexpr std::string_view ToggleShaderEffectsKey{ "toggleShaderEffects" };
static constexpr std::string_view MoveTabKey{ "moveTab" };
Expand Down Expand Up @@ -347,6 +348,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::ToggleFocusMode, RS_(L"ToggleFocusModeCommandKey") },
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
{ ShortcutAction::TogglePaneZoom, RS_(L"TogglePaneZoomCommandKey") },
{ ShortcutAction::TogglePaneSplit, RS_(L"TogglePaneSplitCommandKey") },
{ ShortcutAction::ToggleShaderEffects, RS_(L"ToggleShaderEffectsCommandKey") },
{ ShortcutAction::MoveTab, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::BreakIntoDebugger, RS_(L"BreakIntoDebuggerCommandKey") },
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ON_ALL_ACTIONS(PrevTab) \
ON_ALL_ACTIONS(SendInput) \
ON_ALL_ACTIONS(SplitPane) \
ON_ALL_ACTIONS(TogglePaneSplit) \
ON_ALL_ACTIONS(TogglePaneZoom) \
ON_ALL_ACTIONS(SwitchToTab) \
ON_ALL_ACTIONS(AdjustFontSize) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@
<data name="ToggleFullscreenCommandKey" xml:space="preserve">
<value>Toggle fullscreen</value>
</data>
<data name="TogglePaneSplitCommandKey" xml:space="preserve">
<value>Toggle pane split</value>
</data>
<data name="TogglePaneZoomCommandKey" xml:space="preserve">
<value>Toggle pane zoom</value>
</data>
Expand Down Expand Up @@ -417,4 +420,4 @@
<value>Windows Console Host</value>
<comment>Name describing the usage of the classic windows console as the terminal UI. (`conhost.exe`)</comment>
</data>
</root>
</root>
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
{ "command": { "action": "moveFocus", "direction": "up" }, "keys": "alt+up" },
{ "command": { "action": "moveFocus", "direction": "previous" }, "keys": "ctrl+alt+left" },
{ "command": "togglePaneZoom" },
{ "command": "togglePaneSplit" },
{ "command": "toggleReadOnlyMode" },

// Clipboard Integration
Expand Down

0 comments on commit a4fa0ae

Please sign in to comment.