Search in sources :

Example 46 with LogicalPosition

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

the class ConsoleHighlighter method appendToDocument.

private void appendToDocument() {
    Document document = myEditor.getDocument();
    if (document != null) {
        String pendingString = StringUtil.convertLineSeparators(getPendingString());
        document.insertString(document.getTextLength(), pendingString);
        if (myEditor instanceof Editor) {
            Editor editor = (Editor) myEditor;
            int lineCount = document.getLineCount();
            editor.getScrollingModel().scrollTo(new LogicalPosition(lineCount - 1, 0), ScrollType.MAKE_VISIBLE);
        }
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor)

Example 47 with LogicalPosition

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

the class FileGroup method displayFileInfo.

public void displayFileInfo(@NotNull Editor editor, boolean fullPath) {
    StringBuilder msg = new StringBuilder();
    VirtualFile vf = EditorData.getVirtualFile(editor);
    if (vf != null) {
        msg.append('"');
        if (fullPath) {
            msg.append(vf.getPath());
        } else {
            Project project = editor.getProject();
            if (project != null) {
                VirtualFile root = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(vf);
                if (root != null) {
                    msg.append(vf.getPath().substring(root.getPath().length() + 1));
                } else {
                    msg.append(vf.getPath());
                }
            }
        }
        msg.append("\" ");
    } else {
        msg.append("\"[No File]\" ");
    }
    Document doc = editor.getDocument();
    if (!doc.isWritable()) {
        msg.append("[RO] ");
    } else if (FileDocumentManager.getInstance().isDocumentUnsaved(doc)) {
        msg.append("[+] ");
    }
    int lline = editor.getCaretModel().getLogicalPosition().line;
    int total = EditorHelper.getLineCount(editor);
    int pct = (int) ((float) lline / (float) total * 100f + 0.5);
    msg.append("line ").append(lline + 1).append(" of ").append(total);
    msg.append(" --").append(pct).append("%-- ");
    LogicalPosition lp = editor.getCaretModel().getLogicalPosition();
    int col = editor.getCaretModel().getOffset() - doc.getLineStartOffset(lline);
    msg.append("col ").append(col + 1);
    if (col != lp.column) {
        msg.append("-").append(lp.column + 1);
    }
    VimPlugin.showMessage(msg.toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Document(com.intellij.openapi.editor.Document)

Example 48 with LogicalPosition

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

the class MarkGroup method setMark.

/**
   * Sets the specified mark to the specified location.
   *
   * @param editor  The editor the mark is associated with
   * @param ch      The mark to set
   * @param offset  The offset to set the mark to
   * @return true if able to set the mark, false if not
   */
public boolean setMark(@NotNull Editor editor, char ch, int offset) {
    if (ch == '`')
        ch = '\'';
    LogicalPosition lp = editor.offsetToLogicalPosition(offset);
    final VirtualFile vf = EditorData.getVirtualFile(editor);
    if (vf == null) {
        return false;
    }
    Mark mark = new Mark(ch, lp.line, lp.column, vf.getPath());
    // File specific marks get added to the file
    if (FILE_MARKS.indexOf(ch) >= 0) {
        HashMap<Character, Mark> fmarks = getFileMarks(editor.getDocument());
        if (fmarks == null) {
            return false;
        }
        fmarks.put(ch, mark);
    } else // Global marks get set to both the file and the global list of marks
    if (GLOBAL_MARKS.indexOf(ch) >= 0) {
        HashMap<Character, Mark> fmarks = getFileMarks(editor.getDocument());
        if (fmarks == null) {
            return false;
        }
        fmarks.put(ch, mark);
        Mark oldMark = globalMarks.put(ch, mark);
        if (oldMark != null) {
            oldMark.clear();
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Mark(com.maddyhome.idea.vim.common.Mark)

Example 49 with LogicalPosition

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

the class MarkGroup method getMark.

/**
   * Gets the requested mark for the editor
   *
   * @param editor The editor to get the mark for
   * @param ch     The desired mark
   * @return The requested mark if set, null if not set
   */
@Nullable
public Mark getMark(@NotNull Editor editor, char ch) {
    Mark mark = null;
    if (ch == '`')
        ch = '\'';
    // Make sure this is a valid mark
    if (VALID_GET_MARKS.indexOf(ch) < 0)
        return null;
    VirtualFile vf = EditorData.getVirtualFile(editor);
    if ("{}".indexOf(ch) >= 0 && vf != null) {
        int offset = SearchHelper.findNextParagraph(editor, ch == '{' ? -1 : 1, false);
        offset = EditorHelper.normalizeOffset(editor, offset, false);
        LogicalPosition lp = editor.offsetToLogicalPosition(offset);
        mark = new Mark(ch, lp.line, lp.column, vf.getPath());
    } else if ("()".indexOf(ch) >= 0 && vf != null) {
        int offset = SearchHelper.findNextSentenceStart(editor, ch == '(' ? -1 : 1, false, true);
        offset = EditorHelper.normalizeOffset(editor, offset, false);
        LogicalPosition lp = editor.offsetToLogicalPosition(offset);
        mark = new Mark(ch, lp.line, lp.column, vf.getPath());
    } else // If this is a file mark, get the mark from this file
    if (FILE_MARKS.indexOf(ch) >= 0) {
        final HashMap fmarks = getFileMarks(editor.getDocument());
        if (fmarks != null) {
            mark = (Mark) fmarks.get(new Character(ch));
            if (mark != null && mark.isClear()) {
                fmarks.remove(new Character(ch));
                mark = null;
            }
        }
    } else // This is a mark from another file
    if (GLOBAL_MARKS.indexOf(ch) >= 0) {
        mark = globalMarks.get(new Character(ch));
        if (mark != null && mark.isClear()) {
            globalMarks.remove(new Character(ch));
            mark = null;
        }
    }
    return mark;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Mark(com.maddyhome.idea.vim.common.Mark) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionPathWithDotTest method testFileOnRootProjectDir.

public void testFileOnRootProjectDir() {
    Settings.getInstance(getProject()).publicPath = "";
    myFixture.configureByFile("parentWebPathFile.js");
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 36));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertCompletionList(Arrays.asList("./parentWebPathFile", "./public/blocks/block", "./public/blocks/childWebPathFile", "./public/blocks/fileWithDotPath", "./public/blocks/fileWithTwoDotPath", "./public/blocks/childBlocks/childBlock", "./public/main", "./public/rootWebPathFile"), strings);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)97 Document (com.intellij.openapi.editor.Document)12 PsiElement (com.intellij.psi.PsiElement)12 Editor (com.intellij.openapi.editor.Editor)11 TextRange (com.intellij.openapi.util.TextRange)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 NotNull (org.jetbrains.annotations.NotNull)6 CaretModel (com.intellij.openapi.editor.CaretModel)5 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 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3