use of com.intellij.openapi.editor.ex.EditorEx 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.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class TemplateEditorUtil method createEditor.
private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) {
EditorFactory editorFactory = EditorFactory.getInstance();
Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project));
editor.getContentComponent().setFocusable(!isReadOnly);
EditorSettings editorSettings = editor.getSettings();
editorSettings.setVirtualSpace(false);
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setIndentGuidesShown(false);
editorSettings.setLineNumbersShown(false);
editorSettings.setFoldingOutlineShown(false);
editorSettings.setCaretRowShown(false);
EditorColorsScheme scheme = editor.getColorsScheme();
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
((EditorEx) editor).setHighlighter(highlighter);
}
return editor;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class LanguageConsoleImpl method prepareExecuteAction.
@NotNull
public String prepareExecuteAction(boolean addToHistory, boolean preserveMarkup, boolean clearInput) {
EditorEx editor = getCurrentEditor();
Document document = editor.getDocument();
String text = document.getText();
TextRange range = new TextRange(0, document.getTextLength());
if (!clearInput) {
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
}
if (addToHistory) {
addToHistoryInner(range, editor, clearInput, preserveMarkup);
} else if (clearInput) {
setInputText("");
}
return text;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class ConsoleExecuteAction method update.
@Override
public final void update(@NotNull AnActionEvent e) {
EditorEx editor = myConsoleView.getConsoleEditor();
boolean enabled = !editor.isRendererMode() && isEnabled() && (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence()));
if (enabled) {
Lookup lookup = LookupManager.getActiveLookup(editor);
// we should check getCurrentItem() also - fast typing could produce outdated lookup, such lookup reports isCompletion() true
enabled = lookup == null || !lookup.isCompletion() || lookup.getCurrentItem() == null || (lookup instanceof LookupImpl && ((LookupImpl) lookup).getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED);
}
e.getPresentation().setEnabled(enabled);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class FileTemplateConfigurable method createEditor.
private Editor createEditor() {
EditorFactory editorFactory = EditorFactory.getInstance();
Document doc = myFile == null ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText()) : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile);
assert doc != null;
Editor editor = editorFactory.createEditor(doc, myProject);
EditorSettings editorSettings = editor.getSettings();
editorSettings.setVirtualSpace(false);
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setIndentGuidesShown(false);
editorSettings.setLineNumbersShown(false);
editorSettings.setFoldingOutlineShown(false);
editorSettings.setAdditionalColumnsCount(3);
editorSettings.setAdditionalLinesCount(3);
editorSettings.setCaretRowShown(false);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
onTextChanged();
}
});
((EditorEx) editor).setHighlighter(createHighlighter());
JPanel topPanel = new JPanel(new BorderLayout());
JPanel southPanel = new JPanel(new HorizontalLayout(40));
southPanel.add(myAdjustBox);
southPanel.add(myLiveTemplateBox);
topPanel.add(southPanel, BorderLayout.SOUTH);
topPanel.add(editor.getComponent(), BorderLayout.CENTER);
mySplitter.setFirstComponent(topPanel);
return editor;
}
Aggregations