Search in sources :

Example 21 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.

the class ExtractIncludeFileBase method highlightInEditor.

private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) {
    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    final int startOffset = pair.getStart().getTextRange().getStartOffset();
    final int endOffset = pair.getEnd().getTextRange().getEndOffset();
    highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null);
    final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
    editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 22 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.

the class ExtractMethodHelper method highlightInEditor.

private static void highlightInEditor(@NotNull final Project project, @NotNull final SimpleMatch match, @NotNull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) {
    final List<RangeHighlighter> highlighters = new ArrayList<>();
    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    final int startOffset = match.getStartElement().getTextRange().getStartOffset();
    final int endOffset = match.getEndElement().getTextRange().getEndOffset();
    highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters);
    highlighterMap.put(match, highlighters.get(0));
    final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
    editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 23 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.

the class SliceTestUtil method message.

private static String message(int startOffset, SliceUsage usage) {
    PsiFile file = usage.getElement().getContainingFile();
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    Editor editor = FileEditorManager.getInstance(file.getProject()).getSelectedTextEditor();
    LogicalPosition position = editor.offsetToLogicalPosition(startOffset);
    return position + ": '" + StringUtil.first(file.getText().substring(startOffset), 100, true) + "'";
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor)

Example 24 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.

the class SmartIndentingBackspaceHandler method doBeforeCharDeleted.

@Override
protected void doBeforeCharDeleted(char c, PsiFile file, Editor editor) {
    Project project = file.getProject();
    Document document = editor.getDocument();
    CharSequence charSequence = document.getImmutableCharSequence();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    LogicalPosition pos = caretModel.getLogicalPosition();
    int lineStartOffset = document.getLineStartOffset(pos.line);
    int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(charSequence, caretOffset - 1, " \t") + 1;
    if (beforeWhitespaceOffset != lineStartOffset) {
        myReplacement = null;
        return;
    }
    PsiDocumentManager.getInstance(project).commitDocument(document);
    CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
    myReplacement = codeStyleFacade.getLineIndent(document, lineStartOffset);
    if (myReplacement == null) {
        return;
    }
    int tabSize = codeStyleFacade.getTabSize(file.getFileType());
    int targetColumn = getWidth(myReplacement, tabSize);
    int endOffset = CharArrayUtil.shiftForward(charSequence, caretOffset, " \t");
    LogicalPosition logicalPosition = caretOffset < endOffset ? editor.offsetToLogicalPosition(endOffset) : pos;
    int currentColumn = logicalPosition.column;
    if (currentColumn > targetColumn) {
        myStartOffset = lineStartOffset;
    } else if (logicalPosition.line == 0) {
        myStartOffset = 0;
        myReplacement = "";
    } else {
        int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1);
        myStartOffset = CharArrayUtil.shiftBackward(charSequence, prevLineEndOffset - 1, " \t") + 1;
        if (myStartOffset != document.getLineStartOffset(logicalPosition.line - 1)) {
            int spacing = CodeStyleManager.getInstance(project).getSpacing(file, endOffset);
            myReplacement = StringUtil.repeatSymbol(' ', Math.max(0, spacing));
        }
    }
}
Also used : CodeStyleFacade(com.intellij.codeStyle.CodeStyleFacade) Project(com.intellij.openapi.project.Project) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) CaretModel(com.intellij.openapi.editor.CaretModel) Document(com.intellij.openapi.editor.Document)

Example 25 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.

the class BackspaceHandler method deleteToTargetPosition.

public static void deleteToTargetPosition(@NotNull Editor editor, @NotNull LogicalPosition pos) {
    LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition();
    if (logicalPosition.line != pos.line) {
        LOGGER.error("Unexpected caret position: " + logicalPosition + ", target indent position: " + pos);
        return;
    }
    if (pos.column < logicalPosition.column) {
        int targetOffset = editor.logicalPositionToOffset(pos);
        int offset = editor.getCaretModel().getOffset();
        editor.getSelectionModel().setSelection(targetOffset, offset);
        EditorModificationUtil.deleteSelectedText(editor);
        editor.getCaretModel().moveToLogicalPosition(pos);
    } else if (pos.column > logicalPosition.column) {
        EditorModificationUtil.insertStringAtCaret(editor, StringUtil.repeatSymbol(' ', pos.column - logicalPosition.column));
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)106 Document (com.intellij.openapi.editor.Document)16 PsiElement (com.intellij.psi.PsiElement)14 Editor (com.intellij.openapi.editor.Editor)12 TextRange (com.intellij.openapi.util.TextRange)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 CaretModel (com.intellij.openapi.editor.CaretModel)6 NotNull (org.jetbrains.annotations.NotNull)6 RelativePoint (com.intellij.ui.awt.RelativePoint)5 JSFile (com.intellij.lang.javascript.psi.JSFile)4 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 Mark (com.maddyhome.idea.vim.common.Mark)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 EditorWindow (com.intellij.injected.editor.EditorWindow)3