Examples of RangeMarker


Examples of com.intellij.openapi.editor.RangeMarker

        }
    }

    public static void runTemplate(Editor editor, TextRange textRange, List<String> stringList, TemplateImpl template) {
        final Document document = editor.getDocument();
        final RangeMarker range = document.createRangeMarker(textRange.getStartOffset(), textRange.getEndOffset());
        setTemplateVariableValues(template, stringList);
        WriteCommandAction writeCommandAction = new WriteCommandAction(editor.getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.deleteString(range.getStartOffset(), range.getEndOffset());
            }
        };
        writeCommandAction.execute();
        TemplateManager.getInstance(editor.getProject()).startTemplate(editor, "", template);
    }
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        if (doc == null) {
            return;
        }

        final RangeMarker rangeMarker = doc.createRangeMarker(startElement.getTextRange());

        GoFile goFile = (GoFile) file;
        Template template;
        GoVarDeclarations[] globalVariables = goFile.getGlobalVariables();
        if (globalVariables.length == 0) {
            template = createNewStatementTemplate(editor, goFile, startElement);
        } else {
            GoVarDeclarations lastVar = globalVariables[globalVariables.length - 1];
            template = createAppendGlobalVariableTemplate(editor, lastVar, startElement);
        }

        if (template != null) {
            TemplateManager.getInstance(project).startTemplate(editor, template, new TemplateEditingAdapter() {
                @Override
                public void templateFinished(Template template, boolean brokenOff) {
                    editor.getCaretModel().moveToOffset(rangeMarker.getEndOffset());
                }
            });
        }
    }
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        }

        checkFallthrough(se);

        Document document = editor.getDocument();
        RangeMarker range = document.createRangeMarker(se.getTextRange());
        SwitchElements switchElements = SwitchElements.create(document, se);
        DocumentUtil.replaceElementWithText(document, se, switchElements.toIf());
        reformatPositions(se.getContainingFile(), range);
    }
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        if (doc == null) {
            return;
        }

        final RangeMarker rangeMarker;
        final int line = doc.getLineNumber(statement.getTextOffset());
        String variableName = startElement.getText();

        if (expressionIsTheWholeStatement(startElement, statement)) {
            doc.deleteString(doc.getLineStartOffset(line), doc.getLineEndOffset(line) + 1);
            rangeMarker = null;
        } else {
            rangeMarker = doc.createRangeMarker(startElement.getTextRange());
        }

        editor.getCaretModel().moveToOffset(doc.getLineStartOffset(line));

        TemplateImpl template = createTemplate(variableName);
        TemplateManager.getInstance(project).startTemplate(editor, template, new TemplateEditingAdapter() {
            @Override
            public void templateFinished(Template template, boolean brokenOff) {
                int offset;
                if (rangeMarker != null) {
                    offset = rangeMarker.getEndOffset();
                } else {
                    offset = doc.getLineEndOffset(line);
                }
                editor.getCaretModel().moveToOffset(offset);
            }
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        move(editor, seStmt, simpleStatement.getText(), start, end);
    }

    private static void move(Editor editor, final GoStatement statement, final String declaration, final int start, final int end) {
        final Document document = editor.getDocument();
        RangeMarker range = document.createRangeMarker(statement.getTextOffset(), end);
        WriteCommandAction writeCommandAction = new WriteCommandAction(editor.getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.deleteString(start, end);
                document.insertString(statement.getTextOffset(), declaration + "\n");
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        while (outermostIf instanceof GoIfStatement && outermostIf.getParent() instanceof GoIfStatement) {
            outermostIf = outermostIf.getParent();
        }

        final Document document = editor.getDocument();
        RangeMarker range = document.createRangeMarker(outermostIf.getTextOffset(), condition.getTextOffset());
        final PsiElement finalOutermostIf = outermostIf;
        WriteCommandAction writeCommandAction = new WriteCommandAction(ifStatement.getContainingFile().getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.deleteString(simpleStatement.getTextOffset(), condition.getTextOffset());
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        if (file == null) {
            return;
        }

        final Document document = editor.getDocument();
        RangeMarker stmtRange = document.createRangeMarker(stmt.getTextRange());

        GoExpr condition = stmt.getExpression();
        boolean parentIsFunctionDeclaration = isFunctionBlock(stmt.getParent());
        GoBlockStatement thenBlock = stmt.getThenBlock();
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

        }

        GoBlockStatement then = ifStmt.getThenBlock();
        TextRange thenRange = then.getTextRange();
        Document doc = editor.getDocument();
        RangeMarker thenRangeMarker = doc.createRangeMarker(thenRange);

        int lineStartOffset = doc.getLineStartOffset(doc.getLineNumber(thenRange.getEndOffset()));
        doc.insertString(lineStartOffset, "}\n");

        int lineEndOffset = doc.getLineEndOffset(doc.getLineNumber(thenRange.getStartOffset()));
        doc.insertString(lineEndOffset, String.format("\nif %s {", rightExpr.getText()));

        doc.deleteString(leftExpr.getTextRange().getEndOffset(), rightExpr.getTextRange().getEndOffset());

        PsiFile file = element.getContainingFile();
        if (file != null) {
            reformatPositions(file, thenRangeMarker.getStartOffset(), thenRangeMarker.getEndOffset());
        }
    }
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

    @Override
    protected void processIntention(@NotNull PsiElement element, Editor editor)
            throws IntentionExecutionException {
        final Document document = editor.getDocument();
        GoIfStatement outer = findParentOfType(element, GoIfStatement.class);
        RangeMarker reformatRange = document.createRangeMarker(outer.getTextRange());
        GoIfStatement inner = (GoIfStatement) outer.getThenBlock().getStatements()[0];
        if (outer.getSimpleStatement() != null && inner.getSimpleStatement() != null) {
            SmartPsiElementPointer<GoIfStatement> outerPointer = createSmartElementPointer(outer);
            MoveSimpleStatementOutIntention.moveSimpleStatementOut(editor, outer);
            outer = outerPointer.getElement();
            if (outer == null) {
                return;
            }
            inner = (GoIfStatement) outer.getThenBlock().getStatements()[0];
        }

        // outer if range is text range from "if" to "{", inclusive, and surrounding whitespaces are also included.
        final RangeMarker outerIfRange = getOuterIfRange(document, outer);
        final RangeMarker rightCurlyRange = getRightCurlyRange(document, outer);
        if (outerIfRange == null || rightCurlyRange == null) {
            return;
        }

        final int innerEnd = inner.getThenBlock().getTextOffset();
        final String simpleStatementAndExpression = getSimpleStatementAndExpression(outer, inner);

        final GoIfStatement finalInner = inner;
        WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.replaceString(finalInner.getTextOffset(), innerEnd, simpleStatementAndExpression);

                document.deleteString(outerIfRange.getStartOffset(), outerIfRange.getEndOffset());
                document.deleteString(rightCurlyRange.getStartOffset(), rightCurlyRange.getEndOffset());
            }
        };
        writeCommandAction.execute();

        PsiFile file = outer.getContainingFile();
View Full Code Here

Examples of com.intellij.openapi.editor.RangeMarker

  }

  public void selectInEditor() {
    if (!isValid()) return;
    Editor editor = openTextEditor(false);
    RangeMarker marker = getRangeMarker();
    editor.getSelectionModel().setSelection(marker.getStartOffset(), marker.getEndOffset());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.