From 214c1fba9ba5977dd6752058414f980f8bb8e947 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 7 Jul 2026 14:00:56 -0400 Subject: [PATCH] Fixed test focus issue when typing into text fields on FlatLaf --- .../docking/test/AbstractDockingTest.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java index d4c7d15e52..bc2b458797 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java @@ -1515,9 +1515,24 @@ public abstract class AbstractDockingTest extends AbstractGuiTest { */ private static void forceTextComponentFocus(JTextComponent tc) { - Object contextKey = getInstanceField("FOCUSED_COMPONENT", tc); - AppContext context = AppContext.getAppContext(); - context.put(contextKey, tc); + runSwing(() -> { + + // Update Swing's notion of the focused component + Object contextKey = getInstanceField("FOCUSED_COMPONENT", tc); + AppContext context = AppContext.getAppContext(); + context.put(contextKey, tc); + + /* + The FlatLaf will select all text in a text field when it gains focus. This will + break how we send key events to text fields. For text handling to work correctly, + we need to ensure that the given field has focus. If it gains focus in FlatLaf and + then selects the text, the next key event will overwrite the current text, which we + do not want. + + See FlatClientProperties.SELECT_ALL_ON_FOCUS_POLICY + */ + tc.putClientProperty("JTextField.selectAllOnFocusPolicy", "never"); + }); } /**