Two way text binding for textField updates javax.swing.text.AbstractDocument#data model but not GUI

Answered

I use bindText function from

…/ideaIC-2024.1.2-sources.jar!/com/intellij/ui/dsl/builder/textField.kt:41

on textArea to bind PSI elements and GUI to allow some code edits from GUI.

GUI → PSI flow works perfectly

PSI → GUI results only in changes at javax.swing.text.AbstractDocument#data state, but GUI only blinks new data and proceeds to display initial state. I could not find why GUI gets reset, no code seems to actually reset it, moreover state of AbstractDocument#data is as I would expect it (so it looks like GUI and model state gets out of sync).

I use PsiManager.getInstance(project).addPsiTreeChangeListener(PsiTreeChangeAdapter) to listen for PSI changes and update textArea via bindText binding function mentioned above.

As I continue editing code, GUI only blinks changes and resets to very initial state or displays changes as expected, but once I click on the textArea field or other GUI element, value gets reset in GUI to its initial state.

I perform all changes inside EDT (by usingApplicationManager.getApplication().invokeAndWait or invokeLater and inside it WriteCommandAction.runWriteCommandAction)

 

Any ideas why that might happen? Any advices how to fix that or what I might be doing wrong

I use ideaIC-2024.1.2 and 17.0.10 AWS Corretto

 

update:
When I try to update textArea randomly, i.e. not from PsiTreeChangeAdapter on PSI change, it seems to work fine. I don't know how it might affect the behavior since in PSI listener I tried to capture plain String from event, schedule callback with that captured String on separate plain java thread, from that thread after (up to 10s) delay I scheduled update to EDT and after all that textArea still gets reset. I don't know how after all the attempts to detach textArea update from PSI listener it still managed to affect the behavior.

 

update2:
even when I attempt to replace JBAreaField element (remove → add → revalidate → repaint) the issue persists, GUI gets update on code change, but upon gaining focus GUI resets to initial value

0
2 comments

Hi,

I'm sorry, but I don't understand what you are trying to do. Could you please describe the use case more visually and share the code?

Please note, that Kotlin UI DSL is intended for implementing UI forms in dialogs, not for a “general” UI. Binding to the model class is done when the Apply button is clicked. I'm not sure if you are trying to implement a form or a “general” UI.

0

Figured it out while was preparing the sample project to share, it is not a bug/issue, but rather tricky coincidence which was hard to spot because of how things were rendered on GUI and in state (happened to be really misleading).

Karol Lewandowski  Thank you for your response

0

Please sign in to leave a comment.