From e4b8569b12dd8bc6e4b2d51d3ff317b5f7e5f582 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 31 Jul 2023 19:25:18 +0100 Subject: [PATCH] TextEditor: Avoid giving away keyboard focus unconditionally in destructor While improving Android IME support (da38c1ed), text editor destructors were updated to explicitly pass keyboard focus elsewhere. As far as I remember, the change was intended to prevent the text input system from trying to send input events to components while they were being destroyed, in which case the TextInputTarget and Component bases may be 'valid', but the data members referenced by the TextInputTarget implementation may have been destroyed. The motivation for removing these lines is that giving away focus and sending a focus event can cause all components to become unfocused. This is problematic in the case of slider text editors - pressing 'enter' will cause the TextEditor to be destroyed, but the parent component will fail to gain focus, so pressing 'tab' will not have any effect. --- modules/juce_gui_basics/widgets/juce_TextEditor.cpp | 2 -- modules/juce_gui_basics/widgets/juce_TextEditor.h | 4 ++-- .../juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp | 2 -- .../juce_gui_extra/code_editor/juce_CodeEditorComponent.h | 6 +++--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 57ac184024..1cf648adda 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -948,8 +948,6 @@ TextEditor::TextEditor (const String& name, juce_wchar passwordChar) TextEditor::~TextEditor() { - giveAwayKeyboardFocus(); - if (auto* peer = getPeer()) peer->refreshTextInputTarget(); diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.h b/modules/juce_gui_basics/widgets/juce_TextEditor.h index 73ea3c42ba..c30decc618 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.h +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.h @@ -37,8 +37,8 @@ namespace juce @tags{GUI} */ -class JUCE_API TextEditor : public Component, - public TextInputTarget, +class JUCE_API TextEditor : public TextInputTarget, + public Component, public SettableTooltipClient { public: diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp index 33ab977d09..e0b3c7b6ad 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp @@ -476,8 +476,6 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* cons CodeEditorComponent::~CodeEditorComponent() { - giveAwayKeyboardFocus(); - if (auto* peer = getPeer()) peer->refreshTextInputTarget(); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h index d772e2f59e..f0a42b0b49 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h @@ -38,9 +38,9 @@ class CodeTokeniser; @tags{GUI} */ -class JUCE_API CodeEditorComponent : public Component, - public ApplicationCommandTarget, - public TextInputTarget +class JUCE_API CodeEditorComponent : public TextInputTarget, + public Component, + public ApplicationCommandTarget { public: //==============================================================================