Skip to content

Commit 1a56bc5

Browse files
zadjii-msftDHowett
authored andcommitted
Send focus events even in ReadOnly mode (#13483)
Does what it says on the tin. When we get focused, temporarily turn off readonly mode, as to not pop the dialog when the focus sequence is eventually sent to the connection. * closes #13461 (cherry picked from commit b4a52c8) Service-Card-Id: 84111370 Service-Version: 1.14
1 parent ec6dc8d commit 1a56bc5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/cascadia/TerminalControl/ControlCore.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1743,13 +1743,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
17431743
// - This is related to work done for GH#2988.
17441744
void ControlCore::GotFocus()
17451745
{
1746-
_terminal->FocusChanged(true);
1746+
_focusChanged(true);
17471747
}
17481748

17491749
// See GotFocus.
17501750
void ControlCore::LostFocus()
17511751
{
1752-
_terminal->FocusChanged(false);
1752+
_focusChanged(false);
1753+
}
1754+
1755+
void ControlCore::_focusChanged(bool focused)
1756+
{
1757+
// GH#13461 - temporarily turn off read-only mode, send the focus event,
1758+
// then turn it back on. Even in focus mode, focus events are fine to
1759+
// send. We don't want to pop a warning every time the control is
1760+
// focused.
1761+
const auto previous = std::exchange(_isReadOnly, false);
1762+
const auto restore = wil::scope_exit([&]() { _isReadOnly = previous; });
1763+
_terminal->FocusChanged(focused);
17531764
}
17541765

17551766
bool ControlCore::_isBackgroundTransparent()

src/cascadia/TerminalControl/ControlCore.h

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
288288
void _setOpacity(const double opacity);
289289

290290
bool _isBackgroundTransparent();
291+
void _focusChanged(bool focused);
291292

292293
inline bool _IsClosing() const noexcept
293294
{

0 commit comments

Comments
 (0)