Java Code Examples for com.intellij.openapi.editor.Editor#getUserData()
The following examples show how to use
com.intellij.openapi.editor.Editor#getUserData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSGraphQLExecuteEditorAction.java From js-graphql-intellij-plugin with MIT License | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); final Project project = e.getData(CommonDataKeys.PROJECT); if(isQueryableFile(project, virtualFile)) { Editor editor = e.getData(CommonDataKeys.EDITOR); if(project != null && editor instanceof EditorEx) { final Boolean querying = Boolean.TRUE.equals(editor.getUserData(JSGraphQLLanguageUIProjectService.JS_GRAPH_QL_EDITOR_QUERYING)); if(querying) { // already doing a query return; } final Editor queryEditor = editor.getUserData(JSGraphQLLanguageUIProjectService.GRAPH_QL_QUERY_EDITOR); if(queryEditor != null) { // this action comes from the variables editor, so we need to resolve the query editor which contains the GraphQL editor = queryEditor; virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(((EditorEx)editor).getDataContext()); } JSGraphQLLanguageUIProjectService.getService(project).executeGraphQL(editor, virtualFile); } } }
Example 2
Source File: PopupFactoryImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static Point getVisibleBestPopupLocation(@Nonnull Editor editor) { VisualPosition visualPosition = editor.getUserData(ANCHOR_POPUP_POSITION); if (visualPosition == null) { CaretModel caretModel = editor.getCaretModel(); if (caretModel.isUpToDate()) { visualPosition = caretModel.getVisualPosition(); } else { visualPosition = editor.offsetToVisualPosition(caretModel.getOffset()); } } final int lineHeight = editor.getLineHeight(); Point p = editor.visualPositionToXY(visualPosition); p.y += lineHeight; final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); return !visibleArea.contains(p) && !visibleArea.contains(p.x, p.y - lineHeight) ? null : p; }
Example 3
Source File: FoldingUpdate.java From consulo with Apache License 2.0 | 6 votes |
@Nullable static Runnable updateFoldRegions(@Nonnull final Editor editor, @Nonnull PsiFile file, final boolean applyDefaultState, final boolean quick) { ApplicationManager.getApplication().assertReadAccessAllowed(); final Project project = file.getProject(); final Document document = editor.getDocument(); LOG.assertTrue(!PsiDocumentManager.getInstance(project).isUncommited(document)); CachedValue<Runnable> value = editor.getUserData(CODE_FOLDING_KEY); if (value != null && !applyDefaultState) { Getter<Runnable> cached = value.getUpToDateOrNull(); if (cached != null) { return cached.get(); } } if (quick || applyDefaultState) return getUpdateResult(file, document, quick, project, editor, applyDefaultState).getValue(); return CachedValuesManager.getManager(project).getCachedValue(editor, CODE_FOLDING_KEY, () -> { PsiFile file1 = PsiDocumentManager.getInstance(project).getPsiFile(document); return getUpdateResult(file1, document, false, project, editor, false); }, false); }
Example 4
Source File: DesktopAsyncEditorLoader.java From consulo with Apache License 2.0 | 5 votes |
public static void performWhenLoaded(@Nonnull Editor editor, @Nonnull Runnable runnable) { ApplicationManager.getApplication().assertIsDispatchThread(); DesktopAsyncEditorLoader loader = editor.getUserData(ASYNC_LOADER); if (loader == null) { runnable.run(); } else { loader.myDelayedActions.add(runnable); } }
Example 5
Source File: HighlightManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Map<RangeHighlighter, HighlightInfo> getHighlightInfoMap(@Nonnull Editor editor, boolean toCreate) { if (editor instanceof EditorWindow) return getHighlightInfoMap(((EditorWindow)editor).getDelegate(), toCreate); Map<RangeHighlighter, HighlightInfo> map = editor.getUserData(HIGHLIGHT_INFO_MAP_KEY); if (map == null && toCreate) { map = ((UserDataHolderEx)editor).putUserDataIfAbsent(HIGHLIGHT_INFO_MAP_KEY, new HashMap<RangeHighlighter, HighlightInfo>()); } return map; }
Example 6
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<RangeHighlighter> getHighlightersList() { // braces are highlighted across the whole editor, not in each injected editor separately Editor editor = myEditor instanceof EditorWindow ? ((EditorWindow)myEditor).getDelegate() : myEditor; List<RangeHighlighter> highlighters = editor.getUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY); if (highlighters == null) { highlighters = new ArrayList<>(); editor.putUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY, highlighters); } return highlighters; }
Example 7
Source File: CompletionContributorForInplaceRename.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void fillCompletionVariants(@Nonnull CompletionParameters parameters, @Nonnull CompletionResultSet result) { final Editor editor = parameters.getEditor(); final TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null) { if (editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null && parameters.getInvocationCount() == 0) { result.stopHere(); } } }
Example 8
Source File: DebuggerCopyPastePreprocessor.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) { if (editor.getUserData(REMOVE_NEWLINES_ON_PASTE) != null) { return StringUtil.convertLineSeparators(text, " "); } return text; }
Example 9
Source File: FileEditorRule.java From consulo with Apache License 2.0 | 5 votes |
@Override public FileEditor getData(@Nonnull DataProvider dataProvider) { final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR); if (editor == null) { return null; } final Boolean aBoolean = editor.getUserData(EditorTextField.SUPPLEMENTARY_KEY); if (aBoolean != null && aBoolean.booleanValue()) { return null; } return TextEditorProvider.getInstance().getTextEditor(editor); }
Example 10
Source File: SelectOccurrencesActionHandler.java From consulo with Apache License 2.0 | 5 votes |
protected static boolean isWholeWordSearch(Editor editor) { if (!isRepeatedActionInvocation()) { editor.putUserData(WHOLE_WORDS, null); } Boolean value = editor.getUserData(WHOLE_WORDS); return value != null; }
Example 11
Source File: JSGraphQLToggleVariablesAction.java From js-graphql-intellij-plugin with MIT License | 5 votes |
private Editor getVariablesEditor(AnActionEvent e) { final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE); if (editor != null) { final Editor variablesEditor = editor.getUserData(JSGraphQLLanguageUIProjectService.GRAPH_QL_VARIABLES_EDITOR); return variablesEditor != null ? variablesEditor : editor; } return null; }
Example 12
Source File: QuickEditAction.java From consulo with Apache License 2.0 | 5 votes |
public static QuickEditHandler getExistingHandler(@Nonnull PsiFile injectedFile) { Place shreds = InjectedLanguageUtil.getShreds(injectedFile); DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile); if (shreds == null || documentWindow == null) return null; TextRange hostRange = TextRange.create(shreds.get(0).getHostRangeMarker().getStartOffset(), shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset()); for (Editor editor : EditorFactory.getInstance().getAllEditors()) { if (editor.getDocument() != documentWindow.getDelegate()) continue; QuickEditHandler handler = editor.getUserData(QUICK_EDIT_HANDLER); if (handler != null && handler.changesRange(hostRange)) return handler; } return null; }
Example 13
Source File: JSGraphQLExecuteEditorAction.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public void update(AnActionEvent e) { final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE); if(editor != null) { final JSGraphQLEndpointsModel endpointsModel = editor.getUserData(JSGraphQLLanguageUIProjectService.JS_GRAPH_QL_ENDPOINTS_MODEL); if(endpointsModel == null || endpointsModel.getSelectedItem() == null) { e.getPresentation().setEnabled(false); return; } final Boolean querying = Boolean.TRUE.equals(editor.getUserData(JSGraphQLLanguageUIProjectService.JS_GRAPH_QL_EDITOR_QUERYING)); e.getPresentation().setEnabled(!querying); } }
Example 14
Source File: EditorFoldingInfo.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static EditorFoldingInfo get(@Nonnull Editor editor) { EditorFoldingInfo info = editor.getUserData(KEY); if (info == null){ info = new EditorFoldingInfo(); editor.putUserData(KEY, info); } return info; }
Example 15
Source File: LSPDiagnosticsToMarkers.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
@NotNull private Map<String, RangeHighlighter[]> getAllMarkers(Editor editor) { Map<String, RangeHighlighter[]> allMarkers = editor.getUserData(LSP_MARKER_KEY_PREFIX); if (allMarkers == null) { allMarkers = new HashMap<>(); editor.putUserData(LSP_MARKER_KEY_PREFIX, allMarkers); } return allMarkers; }
Example 16
Source File: DesktopAsyncEditorLoader.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isEditorLoaded(@Nonnull Editor editor) { return editor.getUserData(ASYNC_LOADER) == null; }
Example 17
Source File: DiffUtil.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isDiffEditor(@Nonnull Editor editor) { return editor.getUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY) != null; }
Example 18
Source File: IncrementalSearchHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean isEnabled(Editor editor, DataContext dataContext) { PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY); return data != null && data.hint != null || myOriginalHandler.isEnabled(editor, dataContext); }
Example 19
Source File: HighlightCommand.java From CppTools with Apache License 2.0 | 4 votes |
private void doAddHighlighters(Editor editor, List<String> highlighterStringList, boolean overriden) { if (stamp != communicator.getModificationCount() || failed) return; final long started = System.currentTimeMillis(); Key<THashSet<RangeHighlighter>> highlightersKey = overriden ? myOverridenHighlightersKey : myHighlightersKey; THashSet<RangeHighlighter> currentHighlighters = editor.getUserData(highlightersKey); final THashSet<RangeHighlighter> invalidMarkers; if (currentHighlighters == null) { invalidMarkers = new THashSet<RangeHighlighter>(10000); } else { invalidMarkers = currentHighlighters; } currentHighlighters = new THashSet<RangeHighlighter>(); editor.putUserData(highlightersKey, currentHighlighters); final TIntObjectHashMap<RangeHighlighter> lastOffsetToHighlightersMap = new TIntObjectHashMap<RangeHighlighter>(); final TIntObjectHashMap<RangeHighlighter> overridenMap = new TIntObjectHashMap<RangeHighlighter>(); final TIntObjectHashMap<RangeHighlighter> overriddingMap = new TIntObjectHashMap<RangeHighlighter>(); for(RangeHighlighter h:invalidMarkers) { if (!h.isValid()) continue; final GutterIconRenderer gutterIconRenderer = h.getGutterIconRenderer(); final int offset = h.getStartOffset(); if ((!overriden && gutterIconRenderer == null)) { lastOffsetToHighlightersMap.put(offset, h); } else if (overriden && gutterIconRenderer != null) { final HighlightUtils.MyGutterIconRenderer myGutterIconRenderer = (HighlightUtils.MyGutterIconRenderer) gutterIconRenderer; final boolean overrides = myGutterIconRenderer.isOverrides(); ((HighlightUtils.MyGutterIconRenderer) gutterIconRenderer).clearData(); ((overrides)?overriddingMap:overridenMap).put(offset, h); } } final EditorColorsScheme colorsScheme = editor.getColorsScheme(); for(String s: highlighterStringList) { processHighlighterString(editor, colorsScheme, s, overriddingMap, overridenMap, lastOffsetToHighlightersMap, currentHighlighters, invalidMarkers); } //System.out.println("Updated highlighters 2/5 for "+ (System.currentTimeMillis() - started)); for(RangeHighlighter rangeHighlighter:invalidMarkers) { editor.getMarkupModel().removeHighlighter(rangeHighlighter); currentHighlighters.remove(rangeHighlighter); } long doneFor = System.currentTimeMillis() - started; //System.out.println("Updated highlighters 2 for "+ doneFor); Communicator.debug("Updated highlighters 2 for "+ doneFor); }
Example 20
Source File: IncrementalSearchHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean isEnabled(Editor editor, DataContext dataContext) { PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY); return data != null && data.hint != null || myOriginalHandler.isEnabled(editor, dataContext); }