@@ -1586,6 +1586,7 @@ til::point Terminal::GetViewportRelativeCursorPosition() const noexcept
15861586
15871587void Terminal::PreviewText (std::wstring_view input)
15881588{
1589+ // Our suggestion text is default-on-default, in italics.
15891590 static constexpr TextAttribute previewAttrs{ CharacterAttributes::Italics, TextColor{}, TextColor{}, 0u , TextColor{} };
15901591
15911592 auto lock = LockForWriting ();
@@ -1597,44 +1598,37 @@ void Terminal::PreviewText(std::wstring_view input)
15971598 return ;
15981599 }
15991600
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.
16011609 std::wstring_view view{ input };
1610+ // Where do the DELs end?
16021611 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)
16201613 {
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 ' ' );
16351628 }
1629+ snippetPreview.text = til::visualize_nonspace_control_codes (preview);
1630+ // Build our composition data
16361631 const auto len = snippetPreview.text .size ();
1637- // snippetPreview.attributes[0] = Microsoft::Console::Render::CompositionRange{ len, TextAttribute{} };
16381632 snippetPreview.attributes .clear ();
16391633 snippetPreview.attributes .emplace_back (len, previewAttrs);
16401634 snippetPreview.cursorPos = len;
0 commit comments