I don’t think a TextFormatter would work. The formatter would just see a caret 
arrive and then a space character. It would look just like the user typed those 
characters separately.

The unexpected sequence is:
- a PRESSED event arrives for the SPACE key
- a TYPED event arrives for the dead key character
- a TYPED event arrives for the space character
- a RELEASED event arrives for the SPACE key

You would have to register some filters that track state to detect this 
sequence and discard the second TYPED event.

I can’t think of another way of doing this. You can’t track the dead key state 
reliably or know for sure that a TYPED event occurred while a dead key sequence 
was ending.

I’ve submitted a PR (it’s a very small change to the code).

Martin

> On Sep 27, 2024, at 6:18 AM, Thiago Milczarek Sayão <thiago.sa...@gmail.com> 
> wrote:
> 
> Johan,
> 
> I guess you could use a TextFormatter<> to remove the extra space when 
> there's a dead key character before. It would work as
> 
> textField.setTextFormatter(new PasswordTextFilter())
> 
> public class PasswordTextFilter implements 
> UnaryOperator<TextFormatter.Change> {
> 
>     @Override
>     public TextFormatter.Change apply(final TextFormatter.Change aT) {
>        //logic to ignore the space if there's a dead key before
>     }
> }
> 
> 
> 
> 
> 
> Em sex., 27 de set. de 2024 às 09:42, Johan Corveleyn <jcor...@gmail.com 
> <mailto:jcor...@gmail.com>> escreveu:
>> On Thu, Sep 26, 2024 at 10:37 AM Johan Corveleyn <jcor...@gmail.com 
>> <mailto:jcor...@gmail.com>> wrote:
>> >
>> > Thanks, and thank you Martin for filing the issue 
>> > https://bugs.openjdk.org/browse/JDK-8340982. I'll try to create an account 
>> > on openjdk.org <http://openjdk.org/> to be able to watch the issue :-).
>> 
>> Seems it's not that easy to get an account on bugs.openjdk.org 
>> <http://bugs.openjdk.org/>, so
>> never mind that ... I'll check in on the issue from time to time (and
>> of course I keep an eye on this mailinglist anyway). I'm not expecting
>> this to be fixed immediately of course, I suppose everyone here has
>> lots of things on their plate, and lots of other priorities; and I
>> have little to offer as contribution myself at the moment.
>> 
>> In the meantime: does anybody have an idea for an elegant workaround
>> for this (to have a TextField and PasswordField where ^+<space> just
>> yields '^' on Windows + US International keyboard)? Injecting a Swing
>> component for this is an option, but I'd like to know if there are
>> others.
>> 
>> Thanks,
>> -- 
>> Johan

Reply via email to