Removing text selection for commit message

Answered

My plugin uses CommitMessageProvider to prepopulate the commit message. However, when the window is opened and my message is shown, the text is always preselected/highlighted (see screenshot). 
The plugin generates the first part of the commit message while the user inputs the second, however because the text is preselected there can be a mistake where the user removes the first part completely if the user didn't deselect the text first.

I do have a few questions:
1. Is it possible to configure CommitMessageProvider to not preselect the text?
2. I've tried this extension point as well and I was able to get a reference to the commit message text field, but this doesn't work for Commit tool window
3. I couldn't find any documentation on how to get a reference to a UI component from anywhere within the plugin? In other words, is there a way for me to directly access that text field from CommitMessageProvider handler and disable the selection

Here is the source code of my plugin https://github.com/nemwiz/jira-commit-message-intellij-plugin

Thanks

0
1 comment

There is no good API to solve it.

Below are some hacks that might help, but these are not universal (main difference being "Use non-modal commit interface" option).
The general approach is to find `com.intellij.openapi.vcs.ui.CommitMessage` and operate with its EditorTextField directly.
The main problem would be to trigger commit message re-generation when needed (ex: on a branch change or rename).

1) `com.intellij.vcs.commit.DelayedCommitMessageProvider` gets `CommitMessageUi` that  can be casted to CommitMessage.
It is used in non-modal interface and can be used to re-set the value whenever plugin wants.

2) `com.intellij.openapi.vcs.VcsDataKeys#COMMIT_MESSAGE_CONTROL` can be used by “Generate Commit Message” AnAction.
One can also try ‘com.intellij.ide.DataManager#getDataContext(java.awt.Component)’, but this is a bad thing to rely to. And one needs to find a relevant “Component” first.

3) 'com.intellij.openapi.vcs.checkin.BaseCheckinHandlerFactory#createHandler' gets a 'CheckinProjectPanel' into arguments, one might walk Swing hierarchy from 'CheckinProjectPanel#getComponent' using 'com.intellij.util.ui.UIUtil#findComponentsOfType' for CommitMessage.
This one is used in all commit modes, but might not be called often enough (will be called on init and after commit for non-modal, called before showing a commit dialog).
 

0

Please sign in to leave a comment.