From 30c3ce9dc17f799aec59a177d82360becf6a664b Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 14 Jul 2018 16:44:58 -0400 Subject: [PATCH] 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. --- .../plugins/hiscore/NameAutocompleter.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/NameAutocompleter.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/NameAutocompleter.java index f5a4cba504..6dcaaecf83 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/NameAutocompleter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/NameAutocompleter.java @@ -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(); }