can fill prompt with previous command fragment
This commit is contained in:
parent
470c01b7ea
commit
934bae9e3f
|
@ -570,40 +570,7 @@ void CommandLine::_deleteCommandHistory(CookedRead& cookedReadData) noexcept
|
|||
// - cookedReadData - The cooked read data to operate on
|
||||
void CommandLine::_fillPromptWithPreviousCommandFragment(CookedRead& cookedReadData) noexcept
|
||||
{
|
||||
/*
|
||||
if (cookedReadData.HasHistory())
|
||||
{
|
||||
size_t NumSpaces, cchCount;
|
||||
|
||||
const auto LastCommand = cookedReadData.History().GetLastCommand();
|
||||
if (!LastCommand.empty() && LastCommand.size() > cookedReadData.InsertionPoint())
|
||||
{
|
||||
cchCount = LastCommand.size() - cookedReadData.InsertionPoint();
|
||||
const auto bufferSpan = cookedReadData.SpanAtPointer();
|
||||
std::copy_n(LastCommand.cbegin() + cookedReadData.InsertionPoint(), cchCount, bufferSpan.begin());
|
||||
cookedReadData.InsertionPoint() += cchCount;
|
||||
cchCount *= sizeof(WCHAR);
|
||||
cookedReadData.BytesRead() = std::max(LastCommand.size() * sizeof(wchar_t), cookedReadData.BytesRead());
|
||||
if (cookedReadData.IsEchoInput())
|
||||
{
|
||||
short ScrollY = 0;
|
||||
FAIL_FAST_IF_NTSTATUS_FAILED(WriteCharsLegacy(cookedReadData.ScreenInfo(),
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.BufferCurrentPtr(),
|
||||
cookedReadData.BufferCurrentPtr(),
|
||||
&cchCount,
|
||||
&NumSpaces,
|
||||
cookedReadData.OriginalCursorPosition().X,
|
||||
WC_DESTRUCTIVE_BACKSPACE | WC_KEEP_CURSOR_VISIBLE | WC_ECHO,
|
||||
&ScrollY));
|
||||
cookedReadData.OriginalCursorPosition().Y += ScrollY;
|
||||
cookedReadData.VisibleCharCount() += NumSpaces;
|
||||
}
|
||||
cookedReadData.SetBufferCurrentPtr(cookedReadData.BufferCurrentPtr() + cchCount / sizeof(WCHAR));
|
||||
}
|
||||
}
|
||||
*/
|
||||
cookedReadData;
|
||||
cookedReadData.FillPromptWithPreviousCommandFragment();
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
|
|
@ -376,6 +376,34 @@ void CookedRead::SetPromptToMatchingHistoryCommand()
|
|||
}
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - fills prompt with characters from the last command in the history
|
||||
void CookedRead::FillPromptWithPreviousCommandFragment()
|
||||
{
|
||||
if (_pCommandHistory && _pCommandHistory->GetNumberOfCommands() > 0)
|
||||
{
|
||||
const size_t leftChars = _visibleCharCountOf({ _prompt.c_str(), _insertionIndex });
|
||||
const std::wstring_view lastCommand = _pCommandHistory->GetLastCommand();
|
||||
const size_t lastCommandChars = _visibleCharCountOf(lastCommand);
|
||||
if (lastCommandChars > leftChars)
|
||||
{
|
||||
// fill prompt with chars from last command
|
||||
const std::vector<std::vector<wchar_t>> parsedLastCommand = Utf16Parser::Parse(lastCommand);
|
||||
auto it = parsedLastCommand.cbegin() + leftChars;
|
||||
while (it != parsedLastCommand.cend())
|
||||
{
|
||||
const std::vector<wchar_t>& glyph = *it;
|
||||
for (const wchar_t wch : glyph)
|
||||
{
|
||||
_prompt.push_back(wch);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
_writeToScreen(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - deletes all text to the left of the insertion index
|
||||
// Return Value:
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
void SetPromptToCommand(const size_t index);
|
||||
void SetPromptToCommand(const CommandHistory::SearchDirection searchDirection);
|
||||
void SetPromptToMatchingHistoryCommand();
|
||||
void FillPromptWithPreviousCommandFragment();
|
||||
|
||||
size_t DeletePromptBeforeInsertionIndex();
|
||||
void DeletePromptAfterInsertionIndex();
|
||||
|
|
Loading…
Reference in a new issue