From 1f1d65726076679d58435205ff89a9a058f21d89 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 10 Nov 2022 19:07:38 +0000 Subject: [PATCH] TextInputTarget: Add underlining support for composing regions on macOS and iOS --- .../juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm | 5 +++++ .../juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index eb02a3be38..3d40104a7f 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -454,6 +454,8 @@ public: target->setHighlightedRegion (getMarkedTextRange()); target->insertTextAtCaret (text); + target->setTemporaryUnderlining ({ Range::withStartAndLength (startOfMarkedTextInTextInputTarget, + text.length()) }); stringBeingComposed = text; } @@ -1179,6 +1181,8 @@ static bool doKeysUp (UIViewComponentPeer* owner, NSSet* presses, UIPr redirectKeyPresses ('\t'); else owner->replaceMarkedRangeWithText (target, nsStringToJuce (text)); + + target->setTemporaryUnderlining ({}); } owner->stringBeingComposed.clear(); @@ -1260,6 +1264,7 @@ static bool doKeysUp (UIViewComponentPeer* owner, NSSet* presses, UIPr return; owner->replaceMarkedRangeWithText (target, owner->stringBeingComposed); + target->setTemporaryUnderlining ({}); owner->stringBeingComposed.clear(); owner->startOfMarkedTextInTextInputTarget = 0; } diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 7c256b969e..5d1c12788f 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -2121,6 +2121,7 @@ struct JuceNSViewClass : public NSViewComponentPeerWrapper> }()); target->insertTextAtCaret (newText); + target->setTemporaryUnderlining ({}); } } else @@ -2206,6 +2207,7 @@ struct JuceNSViewClass : public NSViewComponentPeerWrapper> target->setHighlightedRegion (initialHighlight); target->insertTextAtCaret (marked); + target->setTemporaryUnderlining ({ Range::withStartAndLength (initialHighlight.getStart(), marked.length()) }); target->setHighlightedRegion (finalHighlight + owner->startOfMarkedTextInTextInputTarget); } } @@ -2218,7 +2220,10 @@ struct JuceNSViewClass : public NSViewComponentPeerWrapper> if (owner->stringBeingComposed.isNotEmpty()) { if (auto* target = owner->findCurrentTextInputTarget()) + { target->insertTextAtCaret (owner->stringBeingComposed); + target->setTemporaryUnderlining ({}); + } owner->stringBeingComposed.clear(); }