Skip to content

Commit

Permalink
Fix spurious "?" from keys like backspace on Linux
Browse files Browse the repository at this point in the history
Input keys such as backspace, home, end, can insert spurious "?" characters on Linux. The fix is simply to stop processing input on this frame once these keys have already been handled.
This is an old bug that returned in 0.16.1 after IME refactor of TextBox control. This change restores the fix method.
  • Loading branch information
Interkarma committed Oct 12, 2023
1 parent 0da542d commit dcd327f
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions Assets/Scripts/Game/UserInterface/TextBox.cs
Expand Up @@ -211,8 +211,13 @@ public override void Update()
return;
}

// Process input
HandleControlInput();
// Process control input
// Exit if this input was handled by below call
// Otherwise keys like backspace can insert spurious "?" characters on some platforms
if (HandleControlInput())
return;

// Process all other input
HandleCharacterInput();
UpdateInlineComposition();

Expand Down Expand Up @@ -340,57 +345,67 @@ string GetResultText()
return Text;
}

// Handle control input such as for cursor movement, delete/backspace, home/end
void HandleControlInput()
// Handle control input such as cursor movement, delete/backspace, home/end
// Returns true when control input was handled by this method or false when input processing should continue
// The caller should stop processing input on this loop when this method returns true
// And continue processing input on this loop when this method returns false
bool HandleControlInput()
{
// During IME composition these kays are handed over to provider
// During IME composition these keys are always handed over to provider
if (IMECompositionInProgress)
return;
return false;

// Moving cursor left and right
if (DaggerfallUI.Instance.LastKeyCode == KeyCode.LeftArrow)
KeyCode lastKeyCode = DaggerfallUI.Instance.LastKeyCode;
if (lastKeyCode == KeyCode.LeftArrow)
{
MoveCursorLeft();
return;
return true;
}
else if (DaggerfallUI.Instance.LastKeyCode == KeyCode.RightArrow)
else if (lastKeyCode == KeyCode.RightArrow)
{
MoveCursorRight();
return;
return true;
}

// Delete and Backspace
if (DaggerfallUI.Instance.LastKeyCode == KeyCode.Delete)
if (lastKeyCode == KeyCode.Delete)
{
if (cursorPosition != text.Length)
{
text = text.Remove(cursorPosition, 1);
RaiseOnTypeHandler();
}
return;
return true;
}
else if (DaggerfallUI.Instance.LastKeyCode == KeyCode.Backspace)
else if (lastKeyCode == KeyCode.Backspace)
{
if (cursorPosition != 0)
{
text = text.Remove(cursorPosition - 1, 1);
MoveCursorLeft();
RaiseOnTypeHandler();
}
return;
return true;
}

// Home and End
if (DaggerfallUI.Instance.LastKeyCode == KeyCode.Home)
if (lastKeyCode == KeyCode.Home)
{
SetCursorPosition(0);
return;
return true;
}
else if (DaggerfallUI.Instance.LastKeyCode == KeyCode.End)
else if (lastKeyCode == KeyCode.End)
{
SetCursorPosition(text.Length);
return;
return true;
}

// Escape - just absorb this so escape does not send spurious input into textbox
if (lastKeyCode == KeyCode.Escape)
return true;

return false;
}

// Handling for basic character input or IME composition insert
Expand Down

0 comments on commit dcd327f

Please sign in to comment.