diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java index 439f73c52a98..913552134ae5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; @@ -40,7 +41,14 @@ public abstract class ExtendWordSelectionHandlerBase implements ExtendWordSelect @Override public List select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) { final TextRange originalRange = e.getTextRange(); - LOG.assertTrue(originalRange.getEndOffset() <= editorText.length(), getClass() + "; " + e); + if (originalRange.getEndOffset() > editorText.length()) { + throw new AssertionError("Invalid element range in " + getClass() + + "; element=" + e + + "; range=" + originalRange + + "; length=" + editorText + + "; editor=" + editor + + "; committed=" + PsiDocumentManager.getInstance(e.getProject()).isCommitted(editor.getDocument())); + } List ranges = expandToWholeLine(editorText, originalRange, true); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java index 7d0fa65e4ef4..8edbb3f5f11d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java @@ -149,6 +149,10 @@ public class SelectWordHandler extends EditorActionHandler { } } + if (element != null && element.getTextRange().getEndOffset() > editor.getDocument().getTextLength()) { + throw new AssertionError("Wrong element range " + element + "; committed=" + PsiDocumentManager.getInstance(project).isCommitted(document)); + } + final TextRange selectionRange = new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()); final Ref minimumRange = new Ref(new TextRange(0, editor.getDocument().getTextLength())); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java index 8253873421fe..94d59648de61 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java @@ -218,8 +218,12 @@ public class SelectWordUtil { availableSelectioners.add(selectioner); } } + long stamp = editor.getDocument().getModificationStamp(); for (ExtendWordSelectionHandler selectioner : availableSelectioners) { List ranges = selectioner.select(element, text, cursorOffset, editor); + if (stamp != editor.getDocument().getModificationStamp()) { + throw new AssertionError("Selectioner " + selectioner + " has changed the document"); + } if (ranges == null) continue; for (TextRange range : ranges) {