Sdk/Console: Handle history

This commit is contained in:
Lynix 2017-08-30 17:06:15 +02:00
parent 1e5e1d5f6d
commit cd332c79ad
1 changed files with 24 additions and 1 deletions

View File

@ -58,6 +58,8 @@ namespace Ndk
m_input->OnTextAreaKeyReturn.Connect(this, &Console::ExecuteInput);
// Protect input prefix from erasure/selection
m_input->SetCursorPosition(s_inputPrefixSize);
m_input->OnTextAreaCursorMove.Connect([](const TextAreaWidget* textArea, std::size_t* newCursorPos)
{
*newCursorPos = std::max(*newCursorPos, s_inputPrefixSize);
@ -69,6 +71,27 @@ namespace Ndk
*ignoreDefaultAction = true;
});
// Handle history
m_input->OnTextAreaKeyUp.Connect([&] (const TextAreaWidget* textArea, bool* ignoreDefaultAction)
{
*ignoreDefaultAction = true;
if (m_historyPosition > 0)
m_historyPosition--;
m_input->SetText(s_inputPrefix + m_commandHistory[m_historyPosition]);
});
m_input->OnTextAreaKeyDown.Connect([&] (const TextAreaWidget* textArea, bool* ignoreDefaultAction)
{
*ignoreDefaultAction = true;
if (++m_historyPosition >= m_commandHistory.size())
m_historyPosition = 0;
m_input->SetText(s_inputPrefix + m_commandHistory[m_historyPosition]);
});
// General
SetPadding(0.f, 0.f, 0.f, 0.f);
}
@ -153,7 +176,7 @@ namespace Ndk
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
m_commandHistory.push_back(inputCmd);
m_historyPosition = 0;
m_historyPosition = m_commandHistory.size();
AddLine(input); //< With the input prefix