Can I prevent user editing some PsiElement areas?
Answered
As the title says, I have got some PsiElement areas, and I want to prevent them from editing these areas(insert or move...)
Please sign in to leave a comment.
Hi,
You can block the possibility of editing document ranges with
Document.createGuardedBlock()
.Karol Lewandowski
Thanks, it surely prevents from editing target regions. But once I edit the region, a dialog(title: GuardedBlockModificationAttempt) will come up and I hope it won't.
How can I make it disappear or customize the content of the dialog?
See
com.intellij.openapi.editor.impl.EditorActionManagerImpl#setReadonlyFragmentModificationHandler(Document, ReadonlyFragmentModificationHandler)
.I wonder how to override the default EditorActionManagerImpl...
You should not override it but call the method I pointed out, passing the edited document and your custom handler implementation that does nothing or displays custom information.
Thanks
By the way, I found guard block will automatically add a background color, how can I remove it..
It is intentional, and it's not possible to remove it. Users can change this color in the editor color scheme options.
Fine... But in my plugin, I'll add a background for all uneditable region. So I think I have to find another to prevent someone else from editing