hiscore plugin: fix race with inserting next character with autocomplete

The key events are already on the awt thread, so it is unnecessary to defer it. When more than one is queued the order it completes them is undefined.
This commit is contained in:
Adam
2018-07-14 16:44:58 -04:00
parent 3499efd6c1
commit 30c3ce9dc1

View File

@@ -113,22 +113,20 @@ class NameAutocompleter implements KeyListener
{
if (isExpectedNext(input, charToInsert))
{
final int insertIndex = input.getSelectionStart();
SwingUtilities.invokeLater(() ->
try
{
try
{
// Insert the character and move the selection.
Document doc = input.getDocument();
doc.remove(insertIndex, 1);
doc.insertString(insertIndex, charToInsert, null);
input.select(insertIndex + 1, input.getSelectionEnd());
}
catch (BadLocationException ex)
{
log.warn("Could not insert character.", ex);
}
});
// Insert the character and move the selection.
final int insertIndex = input.getSelectionStart();
Document doc = input.getDocument();
doc.remove(insertIndex, 1);
doc.insertString(insertIndex, charToInsert, null);
input.select(insertIndex + 1, input.getSelectionEnd());
}
catch (BadLocationException ex)
{
log.warn("Could not insert character.", ex);
}
// Prevent default behavior.
e.consume();
}