use of com.intellij.codeInsight.editorActions.QuoteHandler in project intellij-community by JetBrains.
the class EnterInStringLiteralHandler method isInStringLiteral.
private static boolean isInStringLiteral(@NotNull Editor editor, @NotNull DataContext dataContext, int offset) {
Language language = EnterHandler.getLanguage(dataContext);
if (offset > 0 && language != null) {
QuoteHandler quoteHandler = TypedHandler.getLanguageQuoteHandler(language);
if (quoteHandler == null) {
FileType fileType = language.getAssociatedFileType();
quoteHandler = fileType != null ? TypedHandler.getQuoteHandlerForType(fileType) : null;
}
if (quoteHandler != null) {
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
return StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()) || quoteHandler.isInsideLiteral(iterator);
}
}
return false;
}
use of com.intellij.codeInsight.editorActions.QuoteHandler 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;
}
}
}
Aggregations