Example #1
0
 private void record(Editor editor, @NotNull String text) {
   if (CommandState.getInstance(editor).isRecording()) {
     CommandGroups.getInstance().getRegister().recordText(text);
   }
 }
Example #2
0
  public boolean processExEntry(@NotNull final Editor editor, @NotNull final DataContext context) {
    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.deactivate();
    boolean res = true;
    int flags = 0;
    try {
      CommandState.getInstance(editor).popState();
      logger.debug("processing command");
      final String text = panel.getText();
      record(editor, text);
      if (logger.isDebugEnabled()) logger.debug("swing=" + SwingUtilities.isEventDispatchThread());
      if (panel.getLabel().equals(":")) {
        flags = CommandParser.getInstance().processCommand(editor, context, text, 1);
        if (logger.isDebugEnabled()) logger.debug("flags=" + flags);
        if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
          CommandGroups.getInstance().getMotion().exitVisual(editor, true);
        }
      } else {
        int pos =
            CommandGroups.getInstance()
                .getSearch()
                .search(
                    editor,
                    text,
                    panel.getCount(),
                    panel.getLabel().equals("/")
                        ? Command.FLAG_SEARCH_FWD
                        : Command.FLAG_SEARCH_REV,
                    true);
        if (pos == -1) {
          res = false;
        }
      }
    } catch (ExException ex) {
      // VimPlugin.showMessage(ex.getMessage());
      ProcessGroup.logger.info(ex.getMessage());
      VimPlugin.indicateError();
      res = false;
    } catch (Exception bad) {
      ProcessGroup.logger.error(bad);
      VimPlugin.indicateError();
      res = false;
    } finally {
      final int flg = flags;
      final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              // editor.getContentComponent().requestFocus();
              // Reopening the file was the only way I could solve the focus problem introduced in
              // IDEA at
              // version 1050.
              if (!ApplicationManager.getApplication().isUnitTestMode()
                  && (flg & CommandParser.RES_DONT_REOPEN) == 0) {
                VirtualFile vf = EditorData.getVirtualFile(editor);
                if (vf != null) {
                  FileEditorManager.getInstance(project)
                      .openFile(EditorData.getVirtualFile(editor), true);
                }
              }

              // If the result of the ex command is to display the "more" panel, show it here.
              if ((flg & CommandParser.RES_MORE_PANEL) != 0
                  && MorePanel.getInstance(editor).hasText()) {
                RunnableHelper.runReadCommand(
                    project,
                    new Runnable() {
                      public void run() {
                        MorePanel.getInstance(editor).activate();
                      }
                    },
                    "ShowMorePanel",
                    "ExCommand");
              }
            }
          });
    }

    return res;
  }