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...)

0
8 comments

Hi,

You can block the possibility of editing document ranges with Document.createGuardedBlock().

0

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?

 

 

0

See com.intellij.openapi.editor.impl.EditorActionManagerImpl#setReadonlyFragmentModificationHandler(Document, ReadonlyFragmentModificationHandler).

0

I wonder how to override the default EditorActionManagerImpl...

0

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.

0

Thanks

By the way, I found guard block will automatically add a background color, how can I remove it..

0

It is intentional, and it's not possible to remove it. Users can change this color in the editor color scheme options.

0

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

0

Please sign in to leave a comment.