use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class HighlightManagerImpl method addOccurrenceHighlights.
@Override
public void addOccurrenceHighlights(@NotNull Editor editor, @NotNull PsiElement[] elements, @NotNull TextAttributes attributes, boolean hideByTextChange, Collection<RangeHighlighter> outHighlighters) {
if (elements.length == 0)
return;
int flags = HIDE_BY_ESCAPE;
if (hideByTextChange) {
flags |= HIDE_BY_TEXT_CHANGE;
}
Color scrollmarkColor = getScrollMarkColor(attributes);
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
for (PsiElement element : elements) {
TextRange range = element.getTextRange();
range = InjectedLanguageManager.getInstance(myProject).injectedToHost(element, range);
addOccurrenceHighlight(editor, trimOffsetToDocumentSize(editor, range.getStartOffset()), trimOffsetToDocumentSize(editor, range.getEndOffset()), attributes, flags, outHighlighters, scrollmarkColor);
}
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class HighlightUsagesHandler method clearHighlights.
private static void clearHighlights(Editor editor, HighlightManager highlightManager, List<TextRange> rangesToHighlight, TextAttributes attributes) {
if (editor instanceof EditorWindow)
editor = ((EditorWindow) editor).getDelegate();
RangeHighlighter[] highlighters = ((HighlightManagerImpl) highlightManager).getHighlighters(editor);
Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
Collections.sort(rangesToHighlight, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
int i = 0;
int j = 0;
while (i < highlighters.length && j < rangesToHighlight.size()) {
RangeHighlighter highlighter = highlighters[i];
TextRange highlighterRange = TextRange.create(highlighter);
TextRange refRange = rangesToHighlight.get(j);
if (refRange.equals(highlighterRange) && attributes.equals(highlighter.getTextAttributes()) && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
highlightManager.removeSegmentHighlighter(editor, highlighter);
i++;
} else if (refRange.getStartOffset() > highlighterRange.getEndOffset()) {
i++;
} else if (refRange.getEndOffset() < highlighterRange.getStartOffset()) {
j++;
} else {
i++;
j++;
}
}
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class RenameTo method applyFix.
@SuppressWarnings({ "SSBasedInspection" })
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
DictionarySuggestionProvider provider = findProvider();
if (provider != null) {
provider.setActive(true);
}
Editor editor = getEditorFromFocus();
HashMap<String, Object> map = new HashMap<>();
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null)
return;
PsiFile containingFile = psiElement.getContainingFile();
if (editor == null) {
editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
}
if (editor == null)
return;
if (editor instanceof EditorWindow) {
map.put(CommonDataKeys.EDITOR.getName(), editor);
map.put(CommonDataKeys.PSI_ELEMENT.getName(), psiElement);
} else if (ApplicationManager.getApplication().isUnitTestMode()) {
// TextEditorComponent / FiledEditorManagerImpl give away the data in real life
map.put(CommonDataKeys.PSI_ELEMENT.getName(), new TextEditorPsiDataProvider().getData(CommonDataKeys.PSI_ELEMENT.getName(), editor, editor.getCaretModel().getCurrentCaret()));
}
final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL);
try {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true);
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
AnAction action = new RenameElementAction();
AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "", dataContext);
action.actionPerformed(event);
if (provider != null) {
provider.setActive(false);
}
} finally {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll);
}
}
use of com.intellij.injected.editor.EditorWindow in project intellij by bazelbuild.
the class ProjectViewEnterHandler method preprocessEnter.
@Override
public Result preprocessEnter(PsiFile file, Editor editor, Ref<Integer> caretOffset, Ref<Integer> caretAdvance, DataContext dataContext, EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!isApplicable(file, dataContext) || !insertIndent(file, offset)) {
return Result.Continue;
}
int indent = SectionParser.INDENT;
editor.getCaretModel().moveToOffset(offset);
Document doc = editor.getDocument();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
LogicalPosition position = editor.getCaretModel().getLogicalPosition();
if (position.column < indent) {
String spaces = StringUtil.repeatSymbol(' ', indent - position.column);
doc.insertString(editor.getCaretModel().getOffset(), spaces);
}
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent));
return Result.Stop;
}
Aggregations