1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-27 02:20:05 +00:00

TextEditor: Fix bug where text could be pasted twice from the popup menu

This bug was introduced in 140f8fedb1
This commit is contained in:
reuk 2022-09-28 17:45:18 +01:00
parent 00b1bf3f5b
commit dc8bc918d2
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 17 additions and 23 deletions

View file

@ -944,14 +944,10 @@ TextEditor::TextEditor (const String& name, juce_wchar passwordChar)
setWantsKeyboardFocus (true);
recreateCaret();
juce::Desktop::getInstance().addGlobalMouseListener (this);
}
TextEditor::~TextEditor()
{
juce::Desktop::getInstance().removeGlobalMouseListener (this);
textValue.removeListener (textHolder);
textValue.referTo (Value());
@ -1046,7 +1042,7 @@ bool TextEditor::isReadOnly() const noexcept
bool TextEditor::isTextInputActive() const
{
return ! isReadOnly() && (! clicksOutsideDismissVirtualKeyboard || mouseDownInEditor);
return ! isReadOnly() && (! clicksOutsideDismissVirtualKeyboard || globalMouseListener.lastMouseDownInEditor());
}
void TextEditor::setReturnKeyStartsNewLine (bool shouldStartNewLine)
@ -1851,11 +1847,6 @@ void TextEditor::performPopupMenuAction (const int menuItemID)
//==============================================================================
void TextEditor::mouseDown (const MouseEvent& e)
{
mouseDownInEditor = e.originalComponent == this;
if (! mouseDownInEditor)
return;
beginDragAutoRepeat (100);
newTransaction();
@ -1893,9 +1884,6 @@ void TextEditor::mouseDown (const MouseEvent& e)
void TextEditor::mouseDrag (const MouseEvent& e)
{
if (! mouseDownInEditor)
return;
if (wasFocused || ! selectAllTextWhenFocused)
if (! (popupMenuEnabled && e.mods.isPopupMenu()))
moveCaretTo (getTextIndexAt (e.getPosition()), true);
@ -1903,9 +1891,6 @@ void TextEditor::mouseDrag (const MouseEvent& e)
void TextEditor::mouseUp (const MouseEvent& e)
{
if (! mouseDownInEditor)
return;
newTransaction();
textHolder->restartTimer();
@ -1918,9 +1903,6 @@ void TextEditor::mouseUp (const MouseEvent& e)
void TextEditor::mouseDoubleClick (const MouseEvent& e)
{
if (! mouseDownInEditor)
return;
int tokenEnd = getTextIndexAt (e.getPosition());
int tokenStart = 0;
@ -1987,9 +1969,6 @@ void TextEditor::mouseDoubleClick (const MouseEvent& e)
void TextEditor::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
if (! mouseDownInEditor)
return;
if (! viewport->useMouseWheelMoveIfNeeded (e, wheel))
Component::mouseWheelMove (e, wheel);
}

View file

@ -771,10 +771,26 @@ private:
struct RemoveAction;
class EditorAccessibilityHandler;
class GlobalMouseListener : private MouseListener
{
public:
explicit GlobalMouseListener (Component& e) : editor (e) { Desktop::getInstance().addGlobalMouseListener (this); }
~GlobalMouseListener() override { Desktop::getInstance().removeGlobalMouseListener (this); }
bool lastMouseDownInEditor() const { return mouseDownInEditor; }
private:
void mouseDown (const MouseEvent& event) override { mouseDownInEditor = event.originalComponent == &editor; }
Component& editor;
bool mouseDownInEditor = false;
};
std::unique_ptr<Viewport> viewport;
TextHolderComponent* textHolder;
BorderSize<int> borderSize { 1, 1, 1, 3 };
Justification justification { Justification::topLeft };
const GlobalMouseListener globalMouseListener { *this };
bool readOnly = false;
bool caretVisible = true;
@ -791,7 +807,6 @@ private:
bool valueTextNeedsUpdating = false;
bool consumeEscAndReturnKeys = true;
bool underlineWhitespace = true;
bool mouseDownInEditor = false;
bool clicksOutsideDismissVirtualKeyboard = false;
UndoManager undoManager;