How to detect EnterHandlerDelegate line wrap during format
Answered
It appears that in com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate#postProcessEnter(PsiFile, Editor, DataContext), checking whether or not the user is currently applying reformatting has stopped working via DataManager.getInstance().loadFromDataContext(context, AutoHardWrapHandler.AUTO_WRAP_LINE_IN_PROGRESS_KEY)
However, DataManager.getInstance().loadFromDataContext(context, LineWrappingUtil.WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY) does work with the warning of internal api status.
What should we do about the internal status?
Please sign in to leave a comment.
I just want to clarify that AUTO_WRAP_LINE_IN_PROGRESS_KEY works fine for detecting if a line break occurs because the user was typing, we just want to also detect if the line break occurred because of the formatting action, so we don't run our enter handler in that case.
Maybe we can reuse our re-implementation of LineWrappingUtil#doWrapLongLinesIfNecessary used for our ParagraphFillHandler to perform line breaks manually, to avoid these kinds of side effects caused by simulating an enter press?
Would it make sense for you to have a dedicated method, for example CodeStyle.isAutoWrap(), which would return true in case of automatic wrapping? It could combine the two keys in the public API.
> Would it make sense for you to have a dedicated method, for example CodeStyle.isAutoWrap(), which would return true in case of automatic wrapping? It could combine the two keys in the public API.
Yes we could, but that doesn't answer the question of is it safe to use due to the internal api status? Is there something else we should use instead, etc.
@jojo2357 I think Rustam Vishniakov is suggesting that a dedicated method will be available in public api. I would say, yes, that would be very useful! It will both make it more safe for plugin authors as the internal implementation can change, and make it more usable as we don't have to go hunting for keys for various purposes.
In general using the internal API isn't safe so I have created the following ticket https://youtrack.jetbrains.com/issue/IDEA-324754/Introduce-a-public-API-method-to-check-if-autowrap-is-in-progress-vs-when-a-user-presses-Enter-explicitely. You can temporily use the internal key and switch to the new API method when it becomes available.
Thank you, sorry for the confusion