From 49f0d98bfee40d0c8acec690a0367b410abfbda1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 11 Jul 2022 14:56:29 -0500 Subject: [PATCH 1/3] this is dumb but it works --- src/cascadia/TerminalControl/ControlCore.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 89512563e4c..6d47cdec5b8 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1912,13 +1912,23 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - This is related to work done for GH#2988. void ControlCore::GotFocus() { + // GH#13461 - temporarily turn off read-only mode, send the focus event, + // then turn it back on. Even in focus mode, focus events are fine to + // send. We don't want to pop a warning every time the control is + // focused. + const auto tmp = _isReadOnly; + _isReadOnly = false; _terminal->FocusChanged(true); + _isReadOnly = tmp; } // See GotFocus. void ControlCore::LostFocus() { + const auto tmp = _isReadOnly; + _isReadOnly = false; _terminal->FocusChanged(false); + _isReadOnly = tmp; } bool ControlCore::_isBackgroundTransparent() From c38e687dd6792546996bc399fb4e9048c56589e1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 12 Jul 2022 07:02:00 -0500 Subject: [PATCH 2/3] he's technically correct, the best kind of correct --- src/cascadia/TerminalControl/ControlCore.cpp | 25 ++++++++++---------- src/cascadia/TerminalControl/ControlCore.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 6d47cdec5b8..a17b9769249 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1912,23 +1912,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - This is related to work done for GH#2988. void ControlCore::GotFocus() { - // GH#13461 - temporarily turn off read-only mode, send the focus event, - // then turn it back on. Even in focus mode, focus events are fine to - // send. We don't want to pop a warning every time the control is - // focused. - const auto tmp = _isReadOnly; - _isReadOnly = false; - _terminal->FocusChanged(true); - _isReadOnly = tmp; + _focusChanged(true); } // See GotFocus. void ControlCore::LostFocus() { - const auto tmp = _isReadOnly; - _isReadOnly = false; - _terminal->FocusChanged(false); - _isReadOnly = tmp; + _focusChanged(false); + } + + void ControlCore::_focusChanged(bool focused) + { + // GH#13461 - temporarily turn off read-only mode, send the focus event, + // then turn it back on. Even in focus mode, focus events are fine to + // send. We don't want to pop a warning every time the control is + // focused. + const auto previous = std::exchange(_isReadOnly, false); + const auto restore = wil::scope_exit([&]() { _isReadOnly = tmp; }); + _terminal->FocusChanged(focused); } bool ControlCore::_isBackgroundTransparent() diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 4208798e10d..948a591bfc4 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -311,6 +311,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void _setOpacity(const double opacity); bool _isBackgroundTransparent(); + void _focusChanged(bool focused); inline bool _IsClosing() const noexcept { From 2996fd97758b63f11e2014bc611713d754c2adce Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 12 Jul 2022 12:19:31 -0500 Subject: [PATCH 3/3] that'll happen working in multiple clones at once --- src/cascadia/TerminalControl/ControlCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index a17b9769249..f71eef421f7 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1928,7 +1928,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // send. We don't want to pop a warning every time the control is // focused. const auto previous = std::exchange(_isReadOnly, false); - const auto restore = wil::scope_exit([&]() { _isReadOnly = tmp; }); + const auto restore = wil::scope_exit([&]() { _isReadOnly = previous; }); _terminal->FocusChanged(focused); }