本文整理汇总了Java中com.intellij.openapi.editor.Editor类的典型用法代码示例。如果您正苦于以下问题:Java Editor类的具体用法?Java Editor怎么用?Java Editor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Editor类属于com.intellij.openapi.editor包,在下文中一共展示了Editor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawAllAnswerPlaceholders
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public static void drawAllAnswerPlaceholders(Editor editor, TaskFile taskFile) {
editor.getMarkupModel().removeAllHighlighters();
final Project project = editor.getProject();
if (project == null) return;
final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
final JBColor color = taskManager.getColor(answerPlaceholder);
EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, color);
}
final Document document = editor.getDocument();
EditorActionManager.getInstance()
.setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor));
EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
}
示例2: drawAnswerPlaceholder
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder,
@NotNull final JBColor color) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
EffectType.BOXED, Font.PLAIN);
textAttributes.setEffectColor(color);
int startOffset = placeholder.getOffset();
if (startOffset == -1) {
return;
}
final int length =
placeholder.isActive() ? placeholder.getRealLength() : placeholder.getVisibleLength(placeholder.getActiveSubtaskIndex());
Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
startOffset = offsets.first;
int endOffset = offsets.second;
if (placeholder.isActive()) {
drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, PLACEHOLDERS_LAYER);
}
else if (!placeholder.getUseLength() && length != 0) {
drawAnswerPlaceholderFromPrevStep(editor, startOffset, endOffset);
}
}
示例3: build
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
private void build(int type, PsiFile psiFile, Project project, Editor editor) {
switch (type){
case 1:
new ParamsStringBuilder().build(psiFile, project, editor);
break;
case 2:
new ParamsFileMapBuilder().build(psiFile, project, editor);
break;
case 3:
new ParamsFilePartBuilder().build(psiFile, project, editor);
break;
case 4:
new ParamsFileBodyBuilder().build(psiFile, project, editor);
break;
}
}
示例4: createRenameDialog
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
@Override
public RenameDialog createRenameDialog( Project project, PsiElement element, PsiElement nameSuggestionContext, Editor editor )
{
return new PsiFileRenameDialog( project, element, nameSuggestionContext, editor ) {
protected void createNewNameComponent() {
super.createNewNameComponent();
getNameSuggestionsField().selectNameWithoutExtension();
}
@Override
protected NameSuggestionsField getNameSuggestionsField()
{
return super.getNameSuggestionsField();
}
};
}
示例5: actionPerformed
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
final HighlightManager highlightManager = HighlightManager.getInstance(project);
final RangeHighlighter[] highlighters =
((HighlightManagerImpl) highlightManager).getHighlighters(editor);
for (RangeHighlighter highlighter : highlighters) {
final TextAttributes ta = highlighter.getTextAttributes();
if (ta != null && ta instanceof NamedTextAttr
&& highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
highlightManager.removeSegmentHighlighter(editor, highlighter);
}
}
}
示例6: getHeaderOfValueGroupUnderCaret
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public static PsiElement getHeaderOfValueGroupUnderCaret(@NotNull final Editor editor) {
Validate.notNull(editor);
final PsiElement psiElementUnderCaret = PsiUtilBase.getElementAtCaret(editor);
if (null == psiElementUnderCaret) {
return null;
}
final ImpexValueGroup valueGroup = ImpexPsiUtils.getClosestSelectedValueGroupFromTheSameLine(
psiElementUnderCaret);
if (null != valueGroup) {
final PsiElement header = ImpexPsiUtils.getHeaderForValueGroup(valueGroup);
if (null != header) {
return header;
}
}
return null;
}
示例7: actionPerformed
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public void actionPerformed( AnActionEvent e ) {
Editor editor = ( Editor ) e.getDataContext().getData( "editor" );
SelectionModel selectionModel = editor.getSelectionModel();
if ( selectionModel != null ) {
String selectedText = selectionModel.getSelectedText();
if ( selectedText != null && selectedText.trim().length() > 0 ) {
Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT );
String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID );
QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid );
if ( quickNotesPanel != null ) {
FileDocumentManager manager = FileDocumentManager.getInstance();
VirtualFile virtualFile = manager.getFile( editor.getDocument() );
quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText );
}
}
}
}
示例8: insertToEditor
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public void insertToEditor(Project project, SearchResultElement element) {
CommandProcessor.getInstance().executeCommand(project, () -> getApplication().runWriteAction(() -> {
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor != null) {
int offset = editor.getCaretModel().getOffset();
Document document = editor.getDocument();
String key = isXmlFile ?
"@" + element.getTag() + "/" + element.getName()
: "R." + element.getTag() + "." + element.getName();
if (key != null) {
document.insertString(offset, key);
editor.getCaretModel().moveToOffset(offset + key.length());
}
}
}), "InsertResultToEditor", "", UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
}
示例9: GCMStructureViewModel
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public GCMStructureViewModel(@NotNull PsiFile psiFile, @NotNull final GCMStructureViewRootElement root, Editor editor) {
super(psiFile, root);
withSorters(typeSorter, Sorter.ALPHA_SORTER);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
synchronized (needRefresh) {
needRefresh = true;
}
}
});
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
GCMStructureViewModel.this.refreshView();
}
}, 15, 5, TimeUnit.SECONDS);
}
示例10: processSubDec
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
private void processSubDec(GCMClassDeclaration o, GCMStructureViewClassElement classElement, Editor editor) {
/*
for (GCMClassElemDeclaration relDec : o.getClassElemDeclarationList()) {
if (relDec.getRelationDeclaration() != null) {
GCMStructureViewReferenceElement referenceElement = new GCMStructureViewReferenceElement(relDec.getRelationDeclaration(), editor);
classElement.references.add(referenceElement);
} else if (relDec.getAttributeDeclaration() != null) {
GCMStructureViewAttributeElement attributeElement = new GCMStructureViewAttributeElement(relDec.getAttributeDeclaration(), editor);
classElement.attributes.add(attributeElement);
} else {
System.err.println("Could not find appropriate ClassElem declaration type in processReference for Structure view");
}
}
*/
}
示例11: isAvailable
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (!element.isWritable()) return false;
boolean isTwigFile = GravFileTemplateUtil.isTwigTemplateFile(element.getContainingFile()) || element.getContainingFile() instanceof HtmlFileImpl;
boolean isXmlAttribute = false;
if (!isTwigFile) return false;
if (element.getParent() instanceof XmlAttributeValueImpl) {
XmlAttributeValueImpl parent0 = ((XmlAttributeValueImpl) element.getParent());
boolean hasTwigElement = PsiTreeUtil.findChildOfType(parent0, OuterLanguageElement.class) != null;
if (!hasTwigElement && parent0.getParent() instanceof XmlAttributeImpl) {
XmlAttributeImpl parent1 = (XmlAttributeImpl) parent0.getParent();
if (parent1.getName().equalsIgnoreCase("href") || parent1.getName().equalsIgnoreCase("src"))
isXmlAttribute = true;
}
}
return isXmlAttribute;
}
示例12: generateGherkinRunIcons
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
for (int i = 0; i < rootDocument.getLineCount(); i++) {
int startOffset = rootDocument.getLineStartOffset(i);
int endOffset = rootDocument.getLineEndOffset(i);
String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();
Icon icon;
if (lineText.matches(SCENARIO_REGEX)) {
icon = GherkinIconRenderer.SCENARIO_ICON;
} else if (lineText.matches(FEATURE_REGEX)) {
icon = GherkinIconRenderer.FEATURE_ICON;
} else {
// System.out.println();
continue;
}
GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
gherkinIconRenderer.setLine(i);
gherkinIconRenderer.setIcon(icon);
RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
}
}
示例13: actionPerformed
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
/**
* Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
*
* @param event the performed action
*/
@Override
public final void actionPerformed(final AnActionEvent event) {
final Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
final Project project = event.getData(CommonDataKeys.PROJECT);
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
final int start = caret.getSelectionStart();
final int end = caret.getSelectionEnd();
final String string = generateString();
final int newEnd = start + string.length();
document.replaceString(start, end, string);
caret.setSelection(start, newEnd);
});
WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}
示例14: preprocessEnter
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
@Override
public Result preprocessEnter(
@NotNull PsiFile psiFile,
@NotNull Editor editor,
@NotNull Ref<Integer> caretOffset,
@NotNull Ref<Integer> caretOffsetChange,
@NotNull DataContext dataContext,
@Nullable EditorActionHandler originalHandler) {
if (psiFile instanceof SoyFile && isBetweenSiblingTags(psiFile, caretOffset.get())) {
if (originalHandler != null) {
originalHandler.execute(editor, dataContext);
}
return Result.Default;
}
return Result.Continue;
}
示例15: isClearHighlights
import com.intellij.openapi.editor.Editor; //导入依赖的package包/类
private static boolean isClearHighlights(@NotNull Editor editor) {
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
final Project project = editor.getProject();
if (project == null) {
Log.error("isClearHighlights: editor.getProject() == null");
return false;
}
int caretOffset = editor.getCaretModel().getOffset();
final RangeHighlighter[] highlighters =
((HighlightManagerImpl) HighlightManager.getInstance(project)).getHighlighters(
editor);
for (RangeHighlighter highlighter : highlighters) {
if (TextRange.create(highlighter).grown(1).contains(caretOffset)) {
return true;
}
}
return false;
}