fix bug from issue #16: input text not retracting in shell
This commit is contained in:
parent
00dc46be50
commit
7b37039fed
@ -41,98 +41,99 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
|
|||||||
|
|
||||||
void TextInputNode::update()
|
void TextInputNode::update()
|
||||||
{
|
{
|
||||||
if(!m_hasFocus) return;
|
if(m_hasFocus)
|
||||||
|
{
|
||||||
|
|
||||||
std::wstring text = getEngine().getInput()->getText();
|
std::wstring text = getEngine().getInput()->getText();
|
||||||
|
|
||||||
auto input = getEngine().getInput();
|
auto input = getEngine().getInput();
|
||||||
for(auto action : input->getActions()){
|
for(auto action : input->getActions()){
|
||||||
if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){
|
if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){
|
||||||
if (m_cursor_pos > 0){
|
if (m_cursor_pos > 0){
|
||||||
m_cursor_pos--;
|
m_cursor_pos--;
|
||||||
m_cursor_pos_updated=true;
|
m_cursor_pos_updated=true;
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){
|
|
||||||
if(m_cursor_pos < m_text.length()){
|
|
||||||
m_cursor_pos++;
|
|
||||||
m_cursor_pos_updated=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action.action == m_inputActions[HISTORY_PREVIOUS]){
|
|
||||||
if(m_history_pos > 0)
|
|
||||||
{
|
|
||||||
m_history_pos--;
|
|
||||||
m_text = m_history[m_history_pos];
|
|
||||||
m_cursor_pos = m_text.size();
|
|
||||||
m_text_updated = true;
|
|
||||||
m_cursor_pos_updated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action.action == m_inputActions[HISTORY_NEXT]){
|
|
||||||
if (m_history_pos < m_history.size())
|
|
||||||
{
|
|
||||||
m_history_pos++;
|
|
||||||
if (m_history_pos == m_history.size())
|
|
||||||
{
|
|
||||||
m_text.clear();
|
|
||||||
m_cursor_pos = 0;
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){
|
||||||
|
if(m_cursor_pos < m_text.length()){
|
||||||
|
m_cursor_pos++;
|
||||||
|
m_cursor_pos_updated=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action.action == m_inputActions[HISTORY_PREVIOUS]){
|
||||||
|
if(m_history_pos > 0)
|
||||||
{
|
{
|
||||||
|
m_history_pos--;
|
||||||
m_text = m_history[m_history_pos];
|
m_text = m_history[m_history_pos];
|
||||||
m_cursor_pos = m_text.size();
|
m_cursor_pos = m_text.size();
|
||||||
|
m_text_updated = true;
|
||||||
|
m_cursor_pos_updated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action.action == m_inputActions[HISTORY_NEXT]){
|
||||||
|
if (m_history_pos < m_history.size())
|
||||||
|
{
|
||||||
|
m_history_pos++;
|
||||||
|
if (m_history_pos == m_history.size())
|
||||||
|
{
|
||||||
|
m_text.clear();
|
||||||
|
m_cursor_pos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_text = m_history[m_history_pos];
|
||||||
|
m_cursor_pos = m_text.size();
|
||||||
|
}
|
||||||
|
m_text_updated = true;
|
||||||
|
m_cursor_pos_updated = true;
|
||||||
}
|
}
|
||||||
m_text_updated = true;
|
|
||||||
m_cursor_pos_updated = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for(unsigned int i = 0 ; i < text.length() ; i++){
|
for(unsigned int i = 0 ; i < text.length() ; i++){
|
||||||
char c = text[i];
|
char c = text[i];
|
||||||
switch(c){
|
switch(c){
|
||||||
case 8:
|
case 8:
|
||||||
if(m_cursor_pos > 0)
|
if(m_cursor_pos > 0)
|
||||||
m_text.erase(--m_cursor_pos,1);
|
m_text.erase(--m_cursor_pos,1);
|
||||||
m_text_updated = true;
|
|
||||||
m_cursor_pos_updated=true;
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
if (!m_text.empty())
|
|
||||||
{
|
|
||||||
if(m_callback)
|
|
||||||
m_callback->exec();
|
|
||||||
m_text_updated = true;
|
m_text_updated = true;
|
||||||
m_cursor_pos = 0;
|
|
||||||
m_cursor_pos_updated=true;
|
m_cursor_pos_updated=true;
|
||||||
}
|
break;
|
||||||
break;
|
case 13:
|
||||||
case 9:
|
if (!m_text.empty())
|
||||||
if (!m_text.empty())
|
{
|
||||||
{
|
if(m_callback)
|
||||||
if(m_tab_callback)
|
m_callback->exec();
|
||||||
m_tab_callback->exec();
|
m_text_updated = true;
|
||||||
|
m_cursor_pos = 0;
|
||||||
|
m_cursor_pos_updated=true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
if (!m_text.empty())
|
||||||
|
{
|
||||||
|
if(m_tab_callback)
|
||||||
|
m_tab_callback->exec();
|
||||||
|
m_text_updated = true;
|
||||||
|
m_cursor_pos_updated=true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 127:
|
||||||
|
m_text.erase(m_cursor_pos,1);
|
||||||
|
m_text_updated = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_text.insert(m_cursor_pos++,std::string(1,c));
|
||||||
m_text_updated = true;
|
m_text_updated = true;
|
||||||
m_cursor_pos_updated=true;
|
m_cursor_pos_updated=true;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 127:
|
|
||||||
m_text.erase(m_cursor_pos,1);
|
|
||||||
m_text_updated = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
m_text.insert(m_cursor_pos++,std::string(1,c));
|
|
||||||
m_text_updated = true;
|
|
||||||
m_cursor_pos_updated=true;
|
|
||||||
}
|
}
|
||||||
|
if(m_cursor_pos_updated)
|
||||||
|
updateCursorMesh();
|
||||||
|
|
||||||
|
if(m_text_updated)
|
||||||
|
updateTextMesh();
|
||||||
}
|
}
|
||||||
if(m_cursor_pos_updated)
|
|
||||||
updateCursorMesh();
|
|
||||||
|
|
||||||
if(m_text_updated)
|
|
||||||
updateTextMesh();
|
|
||||||
|
|
||||||
GUINode::update();
|
GUINode::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user