Example usage for com.intellij.openapi.editor EditorModificationUtil insertStringAtCaret

List of usage examples for com.intellij.openapi.editor EditorModificationUtil insertStringAtCaret

Introduction

In this page you can find the example usage for com.intellij.openapi.editor EditorModificationUtil insertStringAtCaret.

Prototype

public static int insertStringAtCaret(Editor editor, @NotNull String s, boolean toProcessOverwriteMode) 

Source Link

Usage

From source file:org.intellij.xquery.braces.FunctionDeclarationBracesBodyHandler.java

License:Apache License

@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile editedFile) {
    if ((editedFile.getLanguage() instanceof XQueryLanguage) && (c == '{' || c == '}')) {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file == null)
            return Result.CONTINUE;
        FileViewProvider provider = file.getViewProvider();
        final int offset = editor.getCaretModel().getOffset();
        PsiElement element = provider.findElementAt(offset - 1, XQueryLanguage.class);
        if (element == null)
            return Result.CONTINUE;
        if (!(element.getLanguage() instanceof XQueryLanguage))
            return Result.CONTINUE;
        ASTNode prevLeaf = element.getNode();
        if (prevLeaf == null)
            return Result.CONTINUE;
        final String prevLeafText = prevLeaf.getText();

        if (isInFunctionBodyAfterInsertionOfMatchingRightBrace(element, prevLeafText)) {
            if (c == '{') {
                editor.getDocument().insertString(offset + 1, ";");
            } else {
                EditorModificationUtil.insertStringAtCaret(editor, ";", false);
            }//from   w  w  w. jav a2  s . co  m
        }

    }

    return Result.CONTINUE;
}

From source file:org.intellij.xquery.completion.xml.XQueryXmlSlashTypedHandler.java

License:Apache License

private void closeEmptyTag(@NotNull Editor editor) {
    EditorModificationUtil.insertStringAtCaret(editor, ">", false);
}

From source file:org.intellij.xquery.completion.xml.XQueryXmlSlashTypedHandler.java

License:Apache License

private void finishClosingTag(@NotNull Editor editor, XQueryXmlTagName tagName) {
    String prefix = tagName.getXmlTagNamespace() != null ? tagName.getXmlTagNamespace().getName() + ":" : "";
    String name = prefix + tagName.getXmlTagLocalName().getText();
    EditorModificationUtil.insertStringAtCaret(editor, name + ">", false);
}