<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Thiago,</div><div><br></div><div>I’ve tested several modal dialogs on Mac, Windows, and Linux and in all but one ESC always dismisses the dialog. The only way for a user to back out an edit is to use Undo. The exception was the standard open file dialog on the Mac. In that dialog the Search field behaves the way you propose; the first ESC cancels editing and the second dismisses the dialog.</div><div><br></div><div>So I agree with Andy, you could just install a filter that catches ESC and unconditionally dismiss the dialog. That’s how most modal dialogs work.</div><div><br></div><div>With that said I think we should implement what you propose; if there’s nothing to cancel ESC should be allowed to bubble. Just attaching a formatter to a field shouldn’t entirely disable the cancel button. In JavaFX events have to bubble all the way up to the scene to ensure the cancel and default buttons work correctly (which is an unusual design). This isn’t really an issue with the presence of the ESC binding but the way TextFieldBehavior implements cancelEdit (TextFieldBehavior:170) which consumes the event even if the text doesn’t change.</div><div><br></div><div>Martin</div><div><div><br><blockquote type="cite"><div>On Nov 21, 2023, at 12:14 PM, Thiago Milczarek Sayão <thiago.sayao@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr">Andy,<div><br></div><div>I think you're right about the formatter.</div><div><br></div><div>The idea was to let the key propagate if there's nothing to cancel.</div><div><br></div><div>For example:</div><div>If I want to cancel the edit, one ESC. The second ESC would propagate because there's nothing to cancel.<br></div><div><br></div><div>Thank you for the reply.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em ter., 21 de nov. de 2023 às 14:36, Andy Goryachev <<a href="mailto:andy.goryachev@oracle.com">andy.goryachev@oracle.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-8599599663317374670">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-5626076307084115747WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">Dear Thiago:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">I don’t think it’s related to undo but to a TextField with a formatter.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">The question is - do you want to disable the standard behavior (updating the text using the formatter on ESCAPE) completely? Or perhaps you do want to let TextField invoke
cancelEdit() (see TextInputControlBehavior:178) and then close the stage?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">In the latter case you might consider adding an event filter on the Stage and calling hide() from there in a Platform.runLater()<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">What do you think?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16"">-andy<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Iosevka Fixed SS16""><u></u> <u></u></span></p>
<div id="m_-5626076307084115747mail-editor-reference-message-container">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in"><p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size: 12pt;">From:
</span></b><span style="font-size: 12pt;">openjfx-dev <<a href="mailto:openjfx-dev-retn@openjdk.org" target="_blank">openjfx-dev-retn@openjdk.org</a>> on behalf of Thiago Milczarek Sayão <<a href="mailto:thiago.sayao@gmail.com" target="_blank">thiago.sayao@gmail.com</a>><br>
<b>Date: </b>Tuesday, November 21, 2023 at 02:37<br>
<b>To: </b>openjfx-dev <<a href="mailto:openjfx-dev@openjdk.org" target="_blank">openjfx-dev@openjdk.org</a>><br>
<b>Subject: </b>ESC key binding on the Scene<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt">Hi,<u></u><u></u></span></p>
<div><p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt">I would like to use ESC to close Stages. The problem is that if the focus is on a TextField, it consumes the event.<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt">ESC is the key binding to Undo on the TextField, but it's always consumed, even if there's nothing to undo.<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt">Is this correct? Should it not propagate if there's nothing to undo?<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:11pt">-- Thiago.<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div></blockquote></div></div>
</div></blockquote></div><br></div></body></html>