preserve highlights on enter

This commit is contained in:
Alexey Kudravtsev
2010-11-09 12:51:46 +03:00
parent 984bfb7485
commit 4f5f9f485a
5 changed files with 30 additions and 11 deletions
@@ -1 +1 @@
abcd
abcd<caret>
@@ -36,8 +36,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase {
int end = myEditor.getCaretModel().getOffset();
Collection<HighlightInfo> 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);
}
}
}
@@ -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() {
@@ -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;
@@ -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