@Nullable private Editor selectEditor(@NotNull Editor editor, @NotNull VirtualFile file) { return VimPlugin.getFile().selectEditor(editor.getProject(), file); }
@Nullable public static PsiFile getFile(@NotNull Editor editor) { VirtualFile vf = EditorData.getVirtualFile(editor); if (vf != null) { Project proj = editor.getProject(); if (proj != null) { PsiManager mgr = PsiManager.getInstance(proj); return mgr.findFile(vf); } } return null; } }
public void run() { deactivate(true); final Project project = myEditor.getProject(); if (project != null && e != null && e.getKeyChar() != '\n') { final KeyStroke key = KeyStroke.getKeyStrokeForEvent(e); final List<KeyStroke> keys = new ArrayList<KeyStroke>(1); keys.add(key); VimPlugin.getMacro().playbackKeys(myEditor, new EditorDataContext(myEditor), project, keys, 0, 0, 1); } } });
/** * Returns the object corresponding to the specified data identifier. Some of the supported data identifiers are * defined in the {@link PlatformDataKeys} class. * * @param dataId the data identifier for which the value is requested. * @return the value, or null if no value is available in the current context for this identifier. */ public Object getData(String dataId) { if (PlatformDataKeys.EDITOR.getName().equals(dataId)) { return editor; } else if (PlatformDataKeys.PROJECT.getName().equals(dataId)) { return editor.getProject(); } else if (PlatformDataKeys.VIRTUAL_FILE.getName().equals(dataId)) { return EditorData.getVirtualFile(editor); } return null; }
/** * Checks if the editor is a primary editor in the main editing area. */ private boolean isPrimaryEditor(@NotNull Editor editor) { final Project project = editor.getProject(); if (project == null) return false; final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project); return StreamEx.of(fileEditorManager.getAllEditors()) .anyMatch(fileEditor -> editor.equals(EditorUtil.getEditorEx(fileEditor))); }
private void handleEditorReset(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull final DataContext context) { if (state != State.COMMAND && count == 0 && currentArg == Argument.Type.NONE && currentCmd.size() == 0) { RegisterGroup register = VimPlugin.getRegister(); if (register.getCurrentRegister() == register.getDefaultRegister()) { if (key.getKeyCode() == KeyEvent.VK_ESCAPE) { CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { @Override public void run() { KeyHandler.executeAction("EditorEscape", context); } }, "", null); } VimPlugin.indicateError(); } } reset(editor); }
private static void resetCursor(@NotNull Editor editor, boolean insert) { Document doc = editor.getDocument(); VirtualFile vf = FileDocumentManager.getInstance().getFile(doc); if (vf != null) { resetCursor(vf, editor.getProject(), insert); } else { editor.getSettings().setBlockCursor(!insert); } }
Project project = editor.getProject(); if (project != null) { VirtualFile root = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(vf);
private void deinitLineNumbers(@NotNull Editor editor) { editor.getCaretModel().removeCaretListener(myLineNumbersCaretListener); EditorData.setEditorGroup(editor, false); editor.getGutter().closeAllAnnotations(); final Project project = editor.getProject(); if (project == null || project.isDisposed()) return; editor.getSettings().setLineNumbersShown(EditorData.isLineNumbersShown(editor)); }
/** * This processes all "regular" keystrokes entered while in insert/replace mode * * @param editor The editor the character was typed into * @param context The data context * @param key The user entered keystroke * @return true if this was a regular character, false if not */ public boolean processKey(@NotNull final Editor editor, @NotNull final DataContext context, @NotNull final KeyStroke key) { if (logger.isDebugEnabled()) { logger.debug("processKey(" + key + ")"); } if (key.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { final Document doc = editor.getDocument(); CommandProcessor.getInstance().executeCommand(editor.getProject(), () -> ApplicationManager.getApplication().runWriteAction( () -> KeyHandler.getInstance().getOriginalHandler().execute( editor, key.getKeyChar(), context)), "", doc, UndoConfirmationPolicy.DEFAULT, doc); return true; } return false; }
@Override public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { if (myOriginalHandler != null) myOriginalHandler.execute(editor, c, dataContext); if (c != 'e') return; Project project = editor.getProject(); if (project == null) return; int offset = editor.getCaretModel().getOffset(); if (offset < 4) return; TextRange from = TextRange.from(offset - 4, 4); String text = editor.getDocument().getText(from); if ("case".equals(text)) { PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); ApplicationManager.getApplication().runWriteAction(() -> { if (project.isDisposed()) return; PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) return; CodeStyleManager.getInstance(project).adjustLineIndent(file, from); }); } } }
@Override public void run() { if (editor.isDisposed()) { return; } final List<KeyStroke> toKeys = mappingInfo.getToKeys(); final VimExtensionHandler extensionHandler = mappingInfo.getExtensionHandler(); final EditorDataContext currentContext = new EditorDataContext(editor); if (toKeys != null) { final boolean fromIsPrefix = isPrefix(mappingInfo.getFromKeys(), toKeys); boolean first = true; for (KeyStroke keyStroke : toKeys) { final boolean recursive = mappingInfo.isRecursive() && !(first && fromIsPrefix); handleKey(editor, keyStroke, currentContext, recursive); first = false; } } else if (extensionHandler != null) { final CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(editor.getProject(), () -> extensionHandler.execute(editor, context), "Vim " + extensionHandler.getClass().getSimpleName(), null); } if (prevMappingInfo != null) { handleKey(editor, key, currentContext); } } };
Project project = editor.getProject(); final Command.Type type = cmd.getType(); if (type.isWrite() && !editor.getDocument().isWritable()) {
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, ";", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, " {}", false, 2); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, "()", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, "();", false, 1); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); char completionChar = context.getCompletionChar(); if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) { return; } Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { EditorModificationUtil.insertStringAtCaret(editor, ":", false, 1); if (myWithSpace) { EditorModificationUtil.insertStringAtCaret(editor, " ", false, 1); } PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } else { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + completionCharOffset + 1); } if (myTriggerAutoPopup) { AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); } } }
Project project = editor.getProject(); if (suggestAlias) { alias = Messages.showInputDialog(project, "Package '" + ((PsiDirectory) element).getName() +
return; Project project = editor.getProject(); if (project != null) { int completionCharOffset = getCompletionCharOffset(editor);