Skip to content

Commit aa4fdda

Browse files
committed
Clean up Remove function
1 parent fa16a96 commit aa4fdda

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

src/host/history.cpp

+7-37
Original file line numberDiff line numberDiff line change
@@ -433,54 +433,24 @@ void CommandHistory::_Inc(Index& ind) const
433433

434434
std::wstring CommandHistory::Remove(const Index iDel)
435435
{
436-
Index iFirst = 0;
437-
auto iLast = gsl::narrow<Index>(_commands.size() - 1);
438-
auto iDisp = LastDisplayed;
439-
440-
if (_commands.size() == 0)
436+
if (iDel < 0 || iDel >= GetNumberOfCommands())
441437
{
442438
return {};
443439
}
444440

445-
if ((iDel < iFirst) || (iDel > iLast))
446-
{
447-
return {};
448-
}
441+
const auto str = std::move(_commands.at(iDel));
442+
_commands.erase(_commands.begin() + iDel);
449443

450-
if (iDisp == iDel)
444+
if (LastDisplayed == iDel)
451445
{
452446
LastDisplayed = -1;
453447
}
454-
455-
try
448+
else if (LastDisplayed > iDel)
456449
{
457-
const auto str = _commands.at(iDel);
458-
459-
if (iDel < iLast)
460-
{
461-
_commands.erase(_commands.cbegin() + iDel);
462-
if ((iDisp > iDel) && (iDisp <= iLast))
463-
{
464-
_Dec(iDisp);
465-
}
466-
_Dec(iLast);
467-
}
468-
else if (iDel >= iFirst)
469-
{
470-
_commands.erase(_commands.cbegin() + iDel);
471-
if ((iDisp >= iFirst) && (iDisp < iDel))
472-
{
473-
_Inc(iDisp);
474-
}
475-
_Inc(iFirst);
476-
}
477-
478-
LastDisplayed = iDisp;
479-
return str;
450+
_Dec(LastDisplayed);
480451
}
481-
CATCH_LOG();
482452

483-
return {};
453+
return str;
484454
}
485455

486456
// Routine Description:

0 commit comments

Comments
 (0)