Skip to content

Commit 8c0d7c6

Browse files
committed
clear quick fix on interaction
1 parent d8c8807 commit 8c0d7c6

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,16 +4854,20 @@ namespace winrt::TerminalApp::implementation
48544854
return;
48554855
}
48564856

4857-
// Helper lambda for dispatching an ActionAndArgs onto the
4857+
// Helper lambda for dispatching a SendInput ActionAndArgs onto the
48584858
// ShortcutActionDispatch. Used below to wire up each menu entry to the
4859-
// respective action.
4860-
4859+
// respective action. Then clear the quick fix menu.
48614860
auto weak = get_weak();
4862-
auto makeCallback = [weak](const ActionAndArgs& actionAndArgs) {
4863-
return [weak, actionAndArgs](auto&&, auto&&) {
4861+
auto makeCallback = [weak](const hstring& suggestion) {
4862+
return [weak, suggestion](auto&&, auto&&) {
48644863
if (auto page{ weak.get() })
48654864
{
4865+
const auto actionAndArgs = ActionAndArgs{ ShortcutAction::SendInput, SendInputArgs{ hstring{ L"\u0003" } + suggestion } };
48664866
page->_actionDispatch->DoAction(actionAndArgs);
4867+
if (auto ctrl = page->_GetActiveControl())
4868+
{
4869+
ctrl.ClearQuickFix();
4870+
}
48674871
}
48684872
};
48694873
};
@@ -4881,7 +4885,7 @@ namespace winrt::TerminalApp::implementation
48814885
}
48824886

48834887
item.Text(label);
4884-
item.Click(makeCallback(ActionAndArgs{ ShortcutAction::SendInput, SendInputArgs{ hstring{ L"\u0003" } + suggestion } }));
4888+
item.Click(makeCallback(suggestion));
48854889
menu.Items().Append(item);
48864890
};
48874891

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
835835
if (Feature_QuickFix::IsEnabled())
836836
{
837837
// update the position of the quick fix menu (in case we changed the padding)
838-
if (_quickFixesAvailable)
839-
{
840-
ShowQuickFixMenu();
841-
}
838+
ShowQuickFixMenu();
842839
}
843840
}
844841

@@ -2341,10 +2338,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
23412338
_updateSelectionMarkers(nullptr, winrt::make<UpdateSelectionMarkersEventArgs>(false));
23422339
}
23432340

2344-
if (_quickFixesAvailable)
2345-
{
2346-
ShowQuickFixMenu();
2347-
}
2341+
ShowQuickFixMenu();
23482342
}
23492343

23502344
hstring TermControl::Title()
@@ -3527,10 +3521,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
35273521
auto quickFixBtn = QuickFixButton();
35283522
quickFixBtn.Height(args.Height() / dpiScale);
35293523
QuickFixIcon().FontSize(std::min(static_cast<double>(args.Width() / dpiScale), GetPadding().Left));
3530-
if (quickFixBtn.Visibility() == Visibility::Visible)
3531-
{
3532-
ShowQuickFixMenu();
3533-
}
3524+
ShowQuickFixMenu();
35343525
}
35353526
}
35363527

@@ -3830,8 +3821,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
38303821

38313822
void TermControl::ShowQuickFixMenu()
38323823
{
3824+
if (!_quickFixesAvailable)
3825+
{
3826+
QuickFixButton().Visibility(Visibility::Collapsed);
3827+
return;
3828+
}
3829+
38333830
auto quickFixBtn{ QuickFixButton() };
3834-
_quickFixesAvailable = true;
38353831

38363832
// If the gutter is narrow, display the collapsed version
38373833
const auto& termPadding = GetPadding();
@@ -3857,10 +3853,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
38573853
quickFixBtn.Visibility(Visibility::Visible);
38583854
}
38593855

3856+
void TermControl::_bubbleSearchMissingCommand(const IInspectable& /*sender*/, const Control::SearchMissingCommandEventArgs& args)
3857+
{
3858+
_quickFixesAvailable = true;
3859+
SearchMissingCommand.raise(*this, args);
3860+
}
3861+
38603862
void TermControl::_clearQuickFix(const IInspectable& /*sender*/, const IInspectable& /*args*/)
38613863
{
38623864
_quickFixesAvailable = false;
3863-
QuickFixButton().Visibility(Visibility::Collapsed);
3865+
ShowQuickFixMenu();
3866+
}
3867+
3868+
void TermControl::ClearQuickFix()
3869+
{
3870+
_clearQuickFix(nullptr, nullptr);
38643871
}
38653872

38663873
void TermControl::_PasteCommandHandler(const IInspectable& /*sender*/,

src/cascadia/TerminalControl/TermControl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
182182

183183
void ShowContextMenu();
184184
void ShowQuickFixMenu();
185+
void ClearQuickFix();
185186

186187
void Detach();
187188

@@ -206,6 +207,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
206207
til::typed_event<IInspectable, Control::KeySentEventArgs> KeySent;
207208
til::typed_event<IInspectable, Control::CharSentEventArgs> CharSent;
208209
til::typed_event<IInspectable, Control::StringSentEventArgs> StringSent;
210+
til::typed_event<IInspectable, Control::SearchMissingCommandEventArgs> SearchMissingCommand;
209211

210212
// UNDER NO CIRCUMSTANCES SHOULD YOU ADD A (PROJECTED_)FORWARDED_TYPED_EVENT HERE
211213
// Those attach the handler to the core directly, and will explode if
@@ -218,7 +220,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
218220
BUBBLED_FORWARDED_TYPED_EVENT(CloseTerminalRequested, IInspectable, IInspectable);
219221
BUBBLED_FORWARDED_TYPED_EVENT(CompletionsChanged, IInspectable, Control::CompletionsChangedEventArgs);
220222
BUBBLED_FORWARDED_TYPED_EVENT(RestartTerminalRequested, IInspectable, IInspectable);
221-
BUBBLED_FORWARDED_TYPED_EVENT(SearchMissingCommand, IInspectable, Control::SearchMissingCommandEventArgs);
222223

223224
BUBBLED_FORWARDED_TYPED_EVENT(PasteFromClipboard, IInspectable, Control::PasteFromClipboardEventArgs);
224225

@@ -403,6 +404,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
403404

404405
void _contextMenuHandler(IInspectable sender, Control::ContextMenuRequestedEventArgs args);
405406
void _showContextMenuAt(const til::point& controlRelativePos);
407+
408+
void _bubbleSearchMissingCommand(const IInspectable& sender, const Control::SearchMissingCommandEventArgs& args);
406409
void _clearQuickFix(const IInspectable& sender, const IInspectable& args);
407410

408411
void _PasteCommandHandler(const IInspectable& sender, const IInspectable& args);

src/cascadia/TerminalControl/TermControl.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace Microsoft.Terminal.Control
149149

150150
void ShowContextMenu();
151151
void ShowQuickFixMenu();
152+
void ClearQuickFix();
152153

153154
void Detach();
154155
}

0 commit comments

Comments
 (0)