@@ -1586,6 +1586,7 @@ til::point Terminal::GetViewportRelativeCursorPosition() const noexcept
1586
1586
1587
1587
void Terminal::PreviewText (std::wstring_view input)
1588
1588
{
1589
+ // Our suggestion text is default-on-default, in italics.
1589
1590
static constexpr TextAttribute previewAttrs{ CharacterAttributes::Italics, TextColor{}, TextColor{}, 0u , TextColor{} };
1590
1591
1591
1592
auto lock = LockForWriting ();
@@ -1597,44 +1598,37 @@ void Terminal::PreviewText(std::wstring_view input)
1597
1598
return ;
1598
1599
}
1599
1600
1600
- // HACK trim off leading DEL chars.
1601
+ // When we're previewing suggestions, they might be preceeded with DEL
1602
+ // characters to backspace off the old command.
1603
+ //
1604
+ // But also, in the case of something like pwsh, there might be MORE "ghost"
1605
+ // text in the buffer _after_ the commandline.
1606
+ //
1607
+ // We need to trim off the leading DELs, then pad out the rest of the line
1608
+ // to cover any other ghost text.
1601
1609
std::wstring_view view{ input };
1610
+ // Where do the DELs end?
1602
1611
const auto strBegin = view.find_first_not_of (L" \x7f " );
1603
-
1604
- // // What we actually want to display is the text that would remain after
1605
- // // accounting for the leading backspaces. So trim off the leading
1606
- // // backspaces, AND and equal number of "real" characters.
1607
- // if (strBegin != std::wstring::npos)
1608
- // {
1609
- // view = view.substr(strBegin * 2);
1610
- // }
1611
-
1612
- // snippetPreview.text = view;
1613
- // // // Hack, part the second: Pad the remaining text with spaces.
1614
- // // const auto originalLen = input.size();
1615
- // // const auto unpaddedLen = snippetPreview.text.size();
1616
- // // if (unpaddedLen < originalLen)
1617
- // // {
1618
- // // snippetPreview.text.insert(snippetPreview.text.size(), originalLen + unpaddedLen, L' ');
1619
- // // }
1612
+ if (strBegin != std::wstring::npos)
1620
1613
{
1621
- // Attempt 2
1622
- const auto bufferWidth = _GetMutableViewport (). Width ( );
1623
- const auto cursorX = _activeBuffer (). GetCursor (). GetPosition (). x ;
1624
- const auto expectedLenTillEnd = strBegin + (bufferWidth - cursorX);
1625
- if (strBegin != std::wstring::npos)
1626
- {
1627
- view = view. substr (strBegin) ;
1628
- }
1629
- snippetPreview. text = view;
1630
- const auto originalSize{ snippetPreview. text .size () };
1631
- if (expectedLenTillEnd > originalSize)
1632
- {
1633
- snippetPreview. text . insert (originalSize, expectedLenTillEnd - originalSize, L ' ' );
1634
- }
1614
+ // Trim them off.
1615
+ view = view. substr (strBegin );
1616
+ }
1617
+ // How many spaces do we need, so that the preview exactly covers the entire
1618
+ // prompt, all the way to the end of the viewport?
1619
+ const auto bufferWidth = _GetMutableViewport (). Width ();
1620
+ const auto cursorX = _activeBuffer (). GetCursor (). GetPosition (). x ;
1621
+ const auto expectedLenTillEnd = strBegin + (bufferWidth - cursorX);
1622
+ std::wstring preview{ view } ;
1623
+ const auto originalSize{ preview .size () };
1624
+ if (expectedLenTillEnd > originalSize)
1625
+ {
1626
+ // pad it out
1627
+ preview. insert (originalSize, expectedLenTillEnd - originalSize, L ' ' );
1635
1628
}
1629
+ snippetPreview.text = til::visualize_nonspace_control_codes (preview);
1630
+ // Build our composition data
1636
1631
const auto len = snippetPreview.text .size ();
1637
- // snippetPreview.attributes[0] = Microsoft::Console::Render::CompositionRange{ len, TextAttribute{} };
1638
1632
snippetPreview.attributes .clear ();
1639
1633
snippetPreview.attributes .emplace_back (len, previewAttrs);
1640
1634
snippetPreview.cursorPos = len;
0 commit comments