Search in sources :

Example 1 with BaseQuoteHandler

use of com.jetbrains.python.editor.BaseQuoteHandler in project intellij-community by JetBrains.

the class PyTripleQuoteBackspaceDelegate method beforeCharDeleted.

@Override
public void beforeCharDeleted(char c, PsiFile file, Editor editor) {
    isTripleQuote = false;
    if (c == '"' || c == '\'' && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE) {
        final QuoteHandler quoteHandler = TypedHandler.getQuoteHandler(file, editor);
        if (quoteHandler == null || !(quoteHandler instanceof BaseQuoteHandler))
            return;
        final int offset = editor.getCaretModel().getCurrentCaret().getOffset();
        String text = editor.getDocument().getText();
        boolean mayBeTripleQuote = offset >= 3 && offset + 2 < text.length();
        if (mayBeTripleQuote) {
            HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
            boolean hasTripleQuoteAfter = offset + 2 < text.length() && text.charAt(offset) == c && text.charAt(offset + 1) == c && text.charAt(offset + 2) == c;
            isTripleQuote = quoteHandler.isOpeningQuote(iterator, offset - 1) && hasTripleQuoteAfter;
        }
    }
}
Also used : BaseQuoteHandler(com.jetbrains.python.editor.BaseQuoteHandler) QuoteHandler(com.intellij.codeInsight.editorActions.QuoteHandler) BaseQuoteHandler(com.jetbrains.python.editor.BaseQuoteHandler) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Aggregations

QuoteHandler (com.intellij.codeInsight.editorActions.QuoteHandler)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 BaseQuoteHandler (com.jetbrains.python.editor.BaseQuoteHandler)1