/** * This is used to initialize each new editor that gets created. * * @param editor The editor to initialize */ public static void initializeEditor(Editor editor) { if (logger.isDebugEnabled()) logger.debug("editor created: " + editor); }
/** * Store which register the user wishes to work with. * * @param reg The register name * @return true if a valid register name, false if not */ public boolean selectRegister(char reg) { if (VALID_REGISTERS.indexOf(reg) != -1) { lastRegister = reg; if (logger.isDebugEnabled()) logger.debug("register selected: " + lastRegister); return true; } else { return false; } }
@NotNull private String processKey(String key, int start, int end) { if (logger.isDebugEnabled()) { logger.debug("process " + key + " " + start + "," + end); } StringBuilder res = new StringBuilder(); res.append(" # ").append(key).append(" ").append("history\n"); String spaces = " "; List<HistoryGroup.HistoryEntry> entries = VimPlugin.getHistory().getEntries(key, start, end); for (HistoryGroup.HistoryEntry entry : entries) { String num = Integer.toString(entry.getNumber()); res.append(spaces.substring(num.length())).append(num).append(" ").append(entry.getEntry()).append("\n"); } return res.toString(); }
@NotNull public String executeCommand(@NotNull String command, @Nullable CharSequence input) throws IOException { if (logger.isDebugEnabled()) { logger.debug("command=" + command); } final Process process = Runtime.getRuntime().exec(command); if (input != null) { final BufferedWriter outputWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); copy(new CharSequenceReader(input), outputWriter); outputWriter.close(); } final BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream())); final StringWriter writer = new StringWriter(); copy(inputReader, writer); writer.close(); lastCommand = command; return writer.toString(); }
public static void runWriteCommand(@Nullable Project project, @NotNull Runnable cmd, @Nullable String name, @Nullable Object groupId) { if (logger.isDebugEnabled()) { logger.debug("write command " + cmd); } CommandProcessor.getInstance().executeCommand(project, new WriteAction(cmd), name, groupId); }
public static void runReadCommand(@Nullable Project project, @NotNull Runnable cmd, @Nullable String name, @Nullable Object groupId) { if (logger.isDebugEnabled()) { logger.debug("read command " + cmd); } CommandProcessor.getInstance().executeCommand(project, new ReadAction(cmd), name, groupId); }
protected void processKeyEvent(KeyEvent e) { if (logger.isDebugEnabled()) logger.debug("key=" + e); super.processKeyEvent(e); }
public void addEntry(String key, @NotNull String text) { if (logger.isDebugEnabled()) { logger.debug("Add entry '" + text + "' to " + key); } HistoryBlock block = blocks(key); block.addEntry(text); }
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException { String arg = cmd.getArgument(); if (logger.isDebugEnabled()) { logger.debug("arg=" + arg); } return VimPlugin.getDigraph().parseCommandLine(editor, cmd.getArgument()); }
/** * Fetches the set of commands that can be used * on a text component that is using a model and * view produced by this kit. * * @return the set of actions */ public Action[] getActions() { Action[] res = TextAction.augmentList(super.getActions(), this.exActions); if (logger.isDebugEnabled()) logger.debug("res.length=" + res.length); return res; }
public void handleKey(@NotNull KeyStroke stroke) { if (logger.isDebugEnabled()) logger.debug("stroke=" + stroke); final char keyChar = stroke.getKeyChar(); char c = keyChar; final int modifiers = stroke.getModifiers(); final int keyCode = stroke.getKeyCode(); if ((modifiers & KeyEvent.CTRL_MASK) != 0) { final int codePoint = keyCode - KeyEvent.VK_A + 1; if (codePoint > 0) { c = Character.toChars(codePoint)[0]; } } KeyEvent event = new KeyEvent(this, keyChar != KeyEvent.CHAR_UNDEFINED ? KeyEvent.KEY_TYPED : (stroke.isOnKeyRelease() ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED), (new Date()).getTime(), modifiers, keyCode, c); super.processKeyEvent(event); }
/** * Each character in the supplied range gets replaced with the character ch * * @param editor The editor to change * @param range The range to change * @param ch The replacing character * @return true if able to change the range, false if not */ public boolean changeCharacterRange(@NotNull Editor editor, @NotNull TextRange range, char ch) { if (logger.isDebugEnabled()) { logger.debug("change range: " + range + " to " + ch); } CharSequence chars = editor.getDocument().getCharsSequence(); int[] starts = range.getStartOffsets(); int[] ends = range.getEndOffsets(); for (int j = ends.length - 1; j >= 0; j--) { for (int i = starts[j]; i < ends[j]; i++) { if (i < chars.length() && '\n' != chars.charAt(i)) { replaceText(editor, i, i + 1, Character.toString(ch)); } } } return true; }
public void postKey(@NotNull KeyStroke stroke, @NotNull Editor editor) { final Component component = SwingUtilities.getAncestorOfClass(Window.class, editor.getComponent()); final KeyEvent event = createKeyEvent(stroke, component); ApplicationManager.getApplication().invokeLater(() -> { if (logger.isDebugEnabled()) { logger.debug("posting " + event); } Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event); }); }
/** * This is used to clean up editors whenever they are closed. * * @param editor The editor to cleanup */ public static void unInitializeEditor(@NotNull Editor editor) { if (logger.isDebugEnabled()) logger.debug("editor closed: " + editor); editor.putUserData(COMMAND_STATE, null); editor.putUserData(LAST_HIGHLIGHTS, null); editor.putUserData(LAST_SELECTION_TYPE, null); editor.putUserData(LAST_VISUAL_RANGE, null); editor.putUserData(MORE_PANEL, null); editor.putUserData(EX_OUTPUT_MODEL, null); }
public void readData(@NotNull Element element) { logger.debug("readData"); Element search = element.getChild("search"); if (search == null) { return; } lastSearch = getSafeChildText(search, "last-search"); lastOffset = getSafeChildText(search, "last-offset"); lastPattern = getSafeChildText(search, "last-pattern"); lastReplace = getSafeChildText(search, "last-replace"); lastSubstitute = getSafeChildText(search, "last-substitute"); Element dir = search.getChild("last-dir"); lastDir = Integer.parseInt(dir.getText()); Element show = search.getChild("show-last"); final ListOption vimInfo = Options.getInstance().getListOption(Options.VIMINFO); final boolean disableHighlight = vimInfo != null && vimInfo.contains("h"); showSearchHighlight = !disableHighlight && Boolean.valueOf(show.getText()); if (logger.isDebugEnabled()) { logger.debug("show=" + show + "(" + show.getText() + ")"); logger.debug("showSearchHighlight=" + showSearchHighlight); } }
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException { LineRange range = cmd.getLineRange(editor, context); CharSequence chars = editor.getDocument().getCharsSequence(); for (int l = range.getStartLine(); l <= range.getEndLine(); l++) { int start = editor.getDocument().getLineStartOffset(l); int end = editor.getDocument().getLineEndOffset(l); if (logger.isDebugEnabled()) { logger.debug("Line " + l + ", start offset=" + start + ", end offset=" + end); for (int i = start; i <= end; i++) { logger.debug("Offset " + i + ", char=" + chars.charAt(i) + ", lp=" + editor.offsetToLogicalPosition(i) + ", vp=" + editor.offsetToVisualPosition(i)); } } } return true; }
private static void resetCursor(@NotNull VirtualFile virtualFile, Project proj, boolean insert) { logger.debug("resetCursor"); Document doc = FileDocumentManager.getInstance().getDocument(virtualFile); if (doc == null) return; // Must be no text editor (such as image) Editor[] editors = EditorFactory.getInstance().getEditors(doc, proj); if (logger.isDebugEnabled()) { logger.debug("There are " + editors.length + " editors for virtual file " + virtualFile.getName()); } for (Editor editor : editors) { editor.getSettings().setBlockCursor(!insert); } }
/** * This event indicates that a document was just changed. We use this event to update all the editor's * marks if text was just added. * * @param event The change event */ public void documentChanged(@NotNull DocumentEvent event) { if (!VimPlugin.isEnabled()) return; if (logger.isDebugEnabled()) logger.debug("MarkUpdater after, event = " + event); if (event.getNewLength() == 0 || (event.getNewLength() == 1 && event.getNewFragment().charAt(0) != '\n')) return; Document doc = event.getDocument(); updateMarkFromInsert(getAnEditor(doc), VimPlugin.getMark().getAllFileMarks(doc), event.getOffset(), event.getNewLength()); // TODO - update jumps }
/** * This event indicates that a document is about to be changed. We use this event to update all the * editor's marks if text is about to be deleted. * * @param event The change event */ public void beforeDocumentChange(@NotNull DocumentEvent event) { if (!VimPlugin.isEnabled()) return; if (logger.isDebugEnabled()) logger.debug("MarkUpdater before, event = " + event); if (event.getOldLength() == 0) return; Document doc = event.getDocument(); updateMarkFromDelete(getAnEditor(doc), VimPlugin.getMark().getAllFileMarks(doc), event.getOffset(), event.getOldLength()); // TODO - update jumps }
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); int offset = SearchHelper.findNextWord(target.getText(), caret.getDot(), target.getText().length(), -1, false, false); if (logger.isDebugEnabled()) logger.debug("offset=" + offset); try { int pos = caret.getDot(); doc.remove(offset, pos - offset); } catch (BadLocationException ex) { // ignore } } }