commitDocument in TypedHandler?
Hi all,
I've created a TypedHandlerDelegate, what I wanted to do was to reindent the line after a certain character was pressed at the start of a line (using CodeStyleManager.adjustLineIndent()). However I was getting errors that the text of the document didn't correspond with the PSI. I managed to fix this by committing the document beforehand - is this correct or is there a better way to do it?
Relevant code snippet:
if (shouldApplyTo(c, lineText))
{
try
{
PsiDocumentManager.getInstance(project).commitDocument(document);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
int newPos = codeStyleManager.adjustLineIndent(file, lineStart);
Cheers,
Colin
Please sign in to leave a comment.
Hello Colin,
Committing the document in this way is correct. The doPostponedOperations...
call is totally unneeded: it's only needed if you perform some modifications
through the PSI and then need to work with the document.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Great, thanks Dmitry.