Skip to content

Commit

Permalink
Remove spaces from snippets in the SXNUI (microsoft#17261)
Browse files Browse the repository at this point in the history
Couple different issues: 
* The suggestions UI can't filter snippets without a name, that have a
space in them, because '␣' != ' '. This instead removes the visualized
space from the name shown in the SXN UI.
* Similarly, we generate an action with leading backspaces to remove the
current commandline. Then we visualize those BS's as a part of the
generated name. Same thing - can't filter to that.


Before in blue: 

![image](https://github.com/microsoft/terminal/assets/18356694/b65e102b-3d23-4d66-9fb9-cfcbb32cf963)

![image](https://github.com/microsoft/terminal/assets/18356694/0a0f4a0e-3ba5-4b61-8f80-1b988fbbb319)

closes microsoft#16577
closes microsoft#16578
  • Loading branch information
zadjii-msft committed May 14, 2024
1 parent bf55c44 commit 54cfb85
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ActionMap.h"
#include "Command.h"
#include "AllShortcutActions.h"
#include <LibraryResources.h>

#include "ActionMap.g.cpp"

Expand Down Expand Up @@ -964,17 +965,32 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
cmdImpl.copy_from(winrt::get_self<implementation::Command>(command));

const auto inArgs{ command.ActionAndArgs().Args().try_as<Model::SendInputArgs>() };

const auto inputString{ inArgs ? inArgs.Input() : L"" };
auto args = winrt::make_self<SendInputArgs>(
winrt::hstring{ fmt::format(FMT_COMPILE(L"{:\x7f^{}}{}"),
L"",
numBackspaces,
(std::wstring_view)(inArgs ? inArgs.Input() : L"")) });
inputString) });
Model::ActionAndArgs actionAndArgs{ ShortcutAction::SendInput, *args };

auto copy = cmdImpl->Copy();
copy->ActionAndArgs(actionAndArgs);

if (!copy->HasName())
{
// Here, we want to manually generate a send input name, but
// without visualizing space and backspace
//
// This is exactly the body of SendInputArgs::GenerateName, but
// with visualize_nonspace_control_codes instead of
// visualize_control_codes, to make filtering in the suggestions
// UI easier.

const auto escapedInput = til::visualize_nonspace_control_codes(std::wstring{ inputString });
const auto name = fmt::format(std::wstring_view(RS_(L"SendInputCommandKey")), escapedInput);
copy->Name(winrt::hstring{ name });
}

return *copy;
};

Expand Down
18 changes: 18 additions & 0 deletions src/inc/til/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
}
return str;
}
// The same as the above, but it doesn't visualize BS nor SPC.
_TIL_INLINEPREFIX std::wstring visualize_nonspace_control_codes(std::wstring str) noexcept
{
for (auto& ch : str)
{
// NOT backspace!
if (ch < 0x20 && ch != 0x08)
{
ch += 0x2400;
}
// NOT space
else if (ch == 0x7f)
{
ch = 0x2421; // replace del with ␡
}
}
return str;
}

_TIL_INLINEPREFIX std::wstring visualize_control_codes(std::wstring_view str)
{
Expand Down

0 comments on commit 54cfb85

Please sign in to comment.