diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lossyEncoding/Text.txt b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lossyEncoding/Text.txt index acbe86c7c895..8f7b7c24f052 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lossyEncoding/Text.txt +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lossyEncoding/Text.txt @@ -1 +1 @@ -abcd +abcd diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java index 1c96e84bf3fd..6f7f21d5cc36 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java @@ -36,8 +36,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase { int end = myEditor.getCaretModel().getOffset(); Collection infos = doHighlighting(); - assertEquals(1, infos.size()); - HighlightInfo info = infos.iterator().next(); + HighlightInfo info = assertOneElement(infos); assertEquals("Unsupported characters for the charset 'US-ASCII'", info.description); assertEquals(start, info.startOffset); assertEquals(end, info.endOffset); @@ -92,4 +91,4 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase { private void doTest(@NonNls String filePath) throws Exception { doTest(BASE_PATH + "/" + filePath, true, false); } -} \ No newline at end of file +} diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index e69bad860077..b2d25802d9d5 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -623,9 +623,18 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } protected void type(char c) { + type(c, getEditor()); + } + + protected static void type(char c, Editor editor) { EditorActionManager actionManager = EditorActionManager.getInstance(); + DataContext dataContext = DataManager.getInstance().getDataContext(); + if (c == '\n') { + actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext); + return; + } TypedAction action = actionManager.getTypedAction(); - action.actionPerformed(getEditor(), c, DataManager.getInstance().getDataContext()); + action.actionPerformed(editor, c, dataContext); } protected void caretRight() { @@ -633,6 +642,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase { EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT); action.execute(getEditor(), DataManager.getInstance().getDataContext()); } + protected void deleteLine() { + EditorActionManager actionManager = EditorActionManager.getInstance(); + EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_DELETE_LINE); + action.execute(getEditor(), DataManager.getInstance().getDataContext()); + } protected void type(@NonNls String s) { for (char c : s.toCharArray()) { @@ -647,15 +661,18 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } protected void backspace() { + backspace(getEditor()); + } + protected void backspace(final Editor editor) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE); - actionHandler.execute(getEditor(), DataManager.getInstance().getDataContext()); + actionHandler.execute(editor, DataManager.getInstance().getDataContext()); } - }, "backspace", getEditor().getDocument()); + }, "backspace", editor.getDocument()); } protected void ctrlShiftF7() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index 00a3dd6d9342..48f71b088b5f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -163,7 +163,7 @@ public class UpdateHighlightersUtil { int startOffset, int endOffset, @NotNull final HighlightInfo info, - @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used + @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used final int group) { ApplicationManager.getApplication().assertIsDispatchThread(); if (info.isFileLevelAnnotation || info.getGutterIconRenderer() != null) return; @@ -313,10 +313,10 @@ public class UpdateHighlightersUtil { public boolean process(HighlightInfo info) { if (info.group == group) { RangeHighlighter highlighter = info.highlighter; - int hiEnd = highlighter.getEndOffset(); int hiStart = highlighter.getStartOffset(); + int hiEnd = highlighter.getEndOffset(); boolean willBeRemoved = hiEnd == document.getTextLength() && range.getEndOffset() == document.getTextLength() - || range.intersects(hiStart, hiEnd); + || range.intersectsStrict(hiStart, hiEnd) || range.containsRange(hiStart, hiEnd) || hiStart <= range.getStartOffset() && hiEnd >= range.getEndOffset(); if (willBeRemoved) { infosToRemove.recycleHighlighter(highlighter); info.highlighter = null; diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java index 3fd084e3269a..83af33e86d94 100644 --- a/platform/util/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/src/com/intellij/openapi/util/TextRange.java @@ -112,7 +112,10 @@ public class TextRange { return Math.max(myStartOffset, startOffset) <= Math.min(myEndOffset, endOffset); } public boolean intersectsStrict(@NotNull TextRange textRange) { - return Math.max(myStartOffset, textRange.getStartOffset()) < Math.min(myEndOffset, textRange.getEndOffset()); + return intersectsStrict(textRange.getStartOffset(), textRange.getEndOffset()); + } + public boolean intersectsStrict(int startOffset, int endOffset) { + return Math.max(myStartOffset, startOffset) < Math.min(myEndOffset, endOffset); } @Nullable