Sdk/Console: Handle history
This commit is contained in:
parent
1e5e1d5f6d
commit
cd332c79ad
|
|
@ -58,6 +58,8 @@ namespace Ndk
|
||||||
m_input->OnTextAreaKeyReturn.Connect(this, &Console::ExecuteInput);
|
m_input->OnTextAreaKeyReturn.Connect(this, &Console::ExecuteInput);
|
||||||
|
|
||||||
// Protect input prefix from erasure/selection
|
// Protect input prefix from erasure/selection
|
||||||
|
m_input->SetCursorPosition(s_inputPrefixSize);
|
||||||
|
|
||||||
m_input->OnTextAreaCursorMove.Connect([](const TextAreaWidget* textArea, std::size_t* newCursorPos)
|
m_input->OnTextAreaCursorMove.Connect([](const TextAreaWidget* textArea, std::size_t* newCursorPos)
|
||||||
{
|
{
|
||||||
*newCursorPos = std::max(*newCursorPos, s_inputPrefixSize);
|
*newCursorPos = std::max(*newCursorPos, s_inputPrefixSize);
|
||||||
|
|
@ -69,6 +71,27 @@ namespace Ndk
|
||||||
*ignoreDefaultAction = true;
|
*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
|
// General
|
||||||
SetPadding(0.f, 0.f, 0.f, 0.f);
|
SetPadding(0.f, 0.f, 0.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +176,7 @@ namespace Ndk
|
||||||
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
|
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
|
||||||
m_commandHistory.push_back(inputCmd);
|
m_commandHistory.push_back(inputCmd);
|
||||||
|
|
||||||
m_historyPosition = 0;
|
m_historyPosition = m_commandHistory.size();
|
||||||
|
|
||||||
AddLine(input); //< With the input prefix
|
AddLine(input); //< With the input prefix
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue