Java Code Examples for com.intellij.openapi.editor.Editor#isOneLineMode()

The following examples show how to use com.intellij.openapi.editor.Editor#isOneLineMode() . 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: CodeCompletionHandlerBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private LookupImpl obtainLookup(Editor editor, Project project) {
  CompletionAssertions.checkEditorValid(editor);
  LookupImpl existing = (LookupImpl)LookupManager.getActiveLookup(editor);
  if (existing != null && existing.isCompletion()) {
    existing.markReused();
    if (!autopopup) {
      existing.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
    }
    return existing;
  }

  LookupImpl lookup = (LookupImpl)LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
  if (editor.isOneLineMode()) {
    lookup.setCancelOnClickOutside(true);
    lookup.setCancelOnOtherWindowOpen(true);
  }
  lookup.setFocusDegree(autopopup ? LookupImpl.FocusDegree.UNFOCUSED : LookupImpl.FocusDegree.FOCUSED);
  return lookup;
}
 
Example 2
Source File: IdentifierHighlighterPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  if (editor.isOneLineMode()) return null;

  if (CodeInsightSettings.getInstance().HIGHLIGHT_IDENTIFIER_UNDER_CARET && (!ApplicationManager.getApplication().isHeadlessEnvironment() || ourTestingIdentifierHighlighting)) {
    return new IdentifierHighlighterPass(file.getProject(), file, editor);
  }
  return null;
}
 
Example 3
Source File: IncrementalFindAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  if (myReplace && ConsoleViewUtil.isConsoleViewEditor(editor) &&
      !ConsoleViewUtil.isReplaceActionEnabledForConsoleViewEditor(editor)) {
    return false;
  }
  if (SEARCH_DISABLED.get(editor, false)) {
    return false;
  }
  Project project = DataManager.getInstance().getDataContext(editor.getComponent()).getData(CommonDataKeys.PROJECT);
  return project != null && !editor.isOneLineMode();
}
 
Example 4
Source File: IncrementalFindAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final Editor editor, DataContext dataContext) {
  final Project project = DataManager.getInstance().getDataContext(editor.getComponent()).getData(CommonDataKeys.PROJECT);
  if (!editor.isOneLineMode()) {
    EditorSearchSession search = EditorSearchSession.get(editor);
    if (search != null) {
      search.getComponent().requestFocusInTheSearchFieldAndSelectContent(project);
      FindUtil.configureFindModel(myReplace, editor, search.getFindModel(), false);
    } else {
      FindManager findManager = FindManager.getInstance(project);
      FindModel model;
      if (myReplace) {
        model = findManager.createReplaceInFileModel();
      } else {
        model = new FindModel();
        model.copyFrom(findManager.getFindInFileModel());
      }
      boolean consoleViewEditor = ConsoleViewUtil.isConsoleViewEditor(editor);
      FindUtil.configureFindModel(myReplace, editor, model, consoleViewEditor);
      EditorSearchSession.start(editor, model, project).getComponent()
              .requestFocusInTheSearchFieldAndSelectContent(project);
      if (!consoleViewEditor && editor.getSelectionModel().hasSelection()) {
        // selection is used as string to find without search model modification so save the pattern explicitly
        FindUtil.updateFindInFileModel(project, model, true);
      }
    }
  }
}
 
Example 5
Source File: IntentionHintComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean canPlaceBulbOnTheSameLine(Editor editor) {
  if (ApplicationManager.getApplication().isUnitTestMode() || editor.isOneLineMode()) return false;
  if (Registry.is("always.show.intention.above.current.line", false)) return false;
  final int offset = editor.getCaretModel().getOffset();
  final VisualPosition pos = editor.offsetToVisualPosition(offset);
  int line = pos.line;

  final int firstNonSpaceColumnOnTheLine = EditorActionUtil.findFirstNonSpaceColumnOnTheLine(editor, line);
  if (firstNonSpaceColumnOnTheLine == -1) return false;
  final Point point = editor.visualPositionToXY(new VisualPosition(line, firstNonSpaceColumnOnTheLine));
  return point.x > AllIcons.Actions.RealIntentionBulb.getIconWidth() + (editor.isOneLineMode() ? SMALL_BORDER_SIZE : NORMAL_BORDER_SIZE) * 2;
}
 
Example 6
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent event) {
  Editor editor = event.getEditor();
  if (editor.isOneLineMode()) {
    return;
  }

  alarm.cancelAllRequests();
  Point point = event.getMouseEvent().getPoint();
  if (myElements == null && event.getMouseEvent().isShiftDown()) {
    alarm.addRequest(new PreviewRequest(point, editor, false), 100);
  }
  else {
    Collection<PsiElement> elements = myElements;
    if (!getPsiElementsAt(point, editor).equals(elements)) {
      myElements = null;
      for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) {
        try {
          if (elements != null) {
            for (PsiElement element : elements) {
              provider.hide(element, editor);
            }
          } else {
            provider.hide(null, editor);
          }
        }
        catch (Exception e) {
          LOG.error(e);
        }
      }
    }
  }
}
 
Example 7
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void registerListeners(final Editor editor) {
  if (editor.isOneLineMode()) {
    return;
  }

  Project project = editor.getProject();
  if (project == null || project.isDisposed()) {
    return;
  }

  PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
    return;
  }

  editor.addEditorMouseMotionListener(this);

  KeyListener keyListener = new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
        PointerInfo pointerInfo = MouseInfo.getPointerInfo();
        if (pointerInfo != null) {
          Point location = pointerInfo.getLocation();
          SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
          alarm.cancelAllRequests();
          alarm.addRequest(new PreviewRequest(location, editor, true), 100);
        }
      }
    }
  };
  editor.getContentComponent().addKeyListener(keyListener);

  EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
 
Example 8
Source File: BaseMoveHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabledForCaret(@Nonnull Editor editor, @Nonnull Caret caret, DataContext dataContext) {
  if (editor.isViewer() || editor.isOneLineMode()) return false;
  final Project project = editor.getProject();
  if (project == null || project.isDisposed()) return false;
  return true;
}
 
Example 9
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void updateScrollableHintPosition(VisibleAreaEvent e, LightweightHint hint, boolean hideIfOutOfEditor) {
  if (hint.getComponent() instanceof ScrollAwareHint) {
    ((ScrollAwareHint)hint.getComponent()).editorScrolled();
  }

  if (!hint.isVisible()) return;

  Editor editor = e.getEditor();
  if (!editor.getComponent().isShowing() || editor.isOneLineMode()) return;
  Rectangle newRectangle = e.getOldRectangle();
  Rectangle oldRectangle = e.getNewRectangle();

  Point location = hint.getLocationOn(editor.getContentComponent());
  Dimension size = hint.getSize();

  int xOffset = location.x - oldRectangle.x;
  int yOffset = location.y - oldRectangle.y;
  location = new Point(newRectangle.x + xOffset, newRectangle.y + yOffset);

  Rectangle newBounds = new Rectangle(location.x, location.y, size.width, size.height);
  //in some rare cases lookup can appear just on the edge with the editor, so don't hide it on every typing
  Rectangle newBoundsForIntersectionCheck = new Rectangle(location.x - 1, location.y - 1, size.width + 2, size.height + 2);

  final boolean okToUpdateBounds = hideIfOutOfEditor ? oldRectangle.contains(newBounds) : oldRectangle.intersects(newBoundsForIntersectionCheck);
  if (okToUpdateBounds || hint.vetoesHiding()) {
    hint.setLocation(new RelativePoint(editor.getContentComponent(), location));
  }
  else {
    hint.hide();
  }
}
 
Example 10
Source File: QuickDocOnMouseOverManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void processMouseMove(@Nonnull EditorMouseEvent e) {
  if (!myApplicationActive || !myEnabled || e.getArea() != EditorMouseEventArea.EDITING_AREA) {
    // Skip if the mouse is not at the editing area.
    closeQuickDocIfPossible();
    return;
  }

  if (e.getMouseEvent().getModifiers() != 0) {
    // Don't show the control when any modifier is active (e.g. Ctrl or Alt is hold). There is a common situation that a user
    // wants to navigate via Ctrl+click or perform quick evaluate by Alt+click.
    return;
  }

  Editor editor = e.getEditor();
  if (EditorMouseHoverPopupControl.arePopupsDisabled(editor)) {
    return;
  }

  if (editor.isOneLineMode()) {
    // Don't want auto quick doc to mess at, say, editor used for debugger condition.
    return;
  }

  Project project = editor.getProject();
  if (project == null) {
    return;
  }

  DocumentationManager documentationManager = DocumentationManager.getInstance(project);
  JBPopup hint = documentationManager.getDocInfoHint();
  if (hint != null) {

    // Skip the event if the control is shown because of explicit 'show quick doc' action call.
    DocumentationManager manager = getDocManager();
    if (manager == null || !manager.isCloseOnSneeze()) {
      return;
    }

    // Skip the event if the mouse is under the opened quick doc control.
    Point hintLocation = hint.getLocationOnScreen();
    Dimension hintSize = hint.getSize();
    int mouseX = e.getMouseEvent().getXOnScreen();
    int mouseY = e.getMouseEvent().getYOnScreen();
    int resizeZoneWidth = editor.getLineHeight();
    if (mouseX >= hintLocation.x - resizeZoneWidth && mouseX <= hintLocation.x + hintSize.width + resizeZoneWidth &&
        mouseY >= hintLocation.y - resizeZoneWidth && mouseY <= hintLocation.y + hintSize.height + resizeZoneWidth) {
      return;
    }
  }

  PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (psiFile == null) {
    closeQuickDocIfPossible();
    return;
  }

  Point point = e.getMouseEvent().getPoint();
  if (editor instanceof EditorEx && ((EditorEx)editor).getFoldingModel().getFoldingPlaceholderAt(point) != null) {
    closeQuickDocIfPossible();
    return;
  }

  VisualPosition visualPosition = editor.xyToVisualPosition(point);
  if (editor.getSoftWrapModel().isInsideOrBeforeSoftWrap(visualPosition)) {
    closeQuickDocIfPossible();
    return;
  }

  int mouseOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(visualPosition));
  PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset);
  if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace || elementUnderMouse instanceof PsiPlainText) {
    closeQuickDocIfPossible();
    return;
  }

  if (elementUnderMouse.equals(SoftReference.dereference(myActiveElements.get(editor))) && (!myAlarm.isEmpty() // Request to show documentation for the target component has been already queued.
                                                                                            || hint != null)) // Documentation for the target component is being shown.
  {
    return;
  }
  allowUpdateFromContext(project, false);
  closeQuickDocIfPossible();
  myActiveElements.put(editor, new WeakReference<>(elementUnderMouse));

  myAlarm.cancelAllRequests();
  if (myCurrentRequest != null) myCurrentRequest.cancel();
  myCurrentRequest = new MyShowQuickDocRequest(documentationManager, editor, mouseOffset, elementUnderMouse);
  myAlarm.addRequest(myCurrentRequest, EditorSettingsExternalizable.getInstance().getTooltipsDelay());
}
 
Example 11
Source File: SmartEnterAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null || editor.isOneLineMode()) {
    plainEnter(editor, caret, dataContext);
    return;
  }

  LookupManager.getInstance(project).hideActiveLookup();

  TemplateState state = TemplateManagerImpl.getTemplateState(editor);
  if (state != null) {
    state.gotoEnd();
  }

  final int caretOffset = editor.getCaretModel().getOffset();

  PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) {
    plainEnter(editor, caret, dataContext);
    return;
  }

  if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, caretOffset, psiFile.getFileType())) {
    EditorActionHandler enterHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
    enterHandler.execute(editor, caret, dataContext);
    return;
  }

  final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
  boolean processed = false;
  if (language != null) {
    final List<SmartEnterProcessor> processors = SmartEnterProcessors.INSTANCE.allForLanguage(language);
    if (!processors.isEmpty()) {
      for (SmartEnterProcessor processor : processors) {
        if (processor.process(project, editor, psiFile)) {
          processed = true;
          break;
        }
      }
    }
  }
  if (!processed) {
    plainEnter(editor, caret, dataContext);
  }
}
 
Example 12
Source File: ParameterHintsPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull Editor editor) {
  if (editor.isOneLineMode()) return null;
  return new ParameterHintsPass(file, editor);
}
 
Example 13
Source File: PageUpAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  return !editor.isOneLineMode();
}
 
Example 14
Source File: PageDownAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  return !editor.isOneLineMode();
}
 
Example 15
Source File: IntentionHintComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static Point getHintPosition(Editor editor) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return new Point();
  final int offset = editor.getCaretModel().getOffset();
  final VisualPosition pos = editor.offsetToVisualPosition(offset);
  int line = pos.line;

  final Point position = editor.visualPositionToXY(new VisualPosition(line, 0));
  LOG.assertTrue(editor.getComponent().isDisplayable());

  JComponent convertComponent = editor.getContentComponent();

  Point realPoint;
  final boolean oneLineEditor = editor.isOneLineMode();
  if (oneLineEditor) {
    // place bulb at the corner of the surrounding component
    final JComponent contentComponent = editor.getContentComponent();
    Container ancestorOfClass = SwingUtilities.getAncestorOfClass(JComboBox.class, contentComponent);

    if (ancestorOfClass != null) {
      convertComponent = (JComponent)ancestorOfClass;
    }
    else {
      ancestorOfClass = SwingUtilities.getAncestorOfClass(JTextField.class, contentComponent);
      if (ancestorOfClass != null) {
        convertComponent = (JComponent)ancestorOfClass;
      }
    }

    realPoint = new Point(-(AllIcons.Actions.RealIntentionBulb.getIconWidth() / 2) - 4, -(AllIcons.Actions.RealIntentionBulb.getIconHeight() / 2));
  }
  else {
    Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    if (position.y < visibleArea.y || position.y >= visibleArea.y + visibleArea.height) return null;

    // try to place bulb on the same line
    int yShift = -(NORMAL_BORDER_SIZE + AllIcons.Actions.RealIntentionBulb.getIconHeight());
    if (canPlaceBulbOnTheSameLine(editor)) {
      yShift = -(NORMAL_BORDER_SIZE + (AllIcons.Actions.RealIntentionBulb.getIconHeight() - editor.getLineHeight()) / 2 + 3);
    }
    else if (position.y < visibleArea.y + editor.getLineHeight()) {
      yShift = editor.getLineHeight() - NORMAL_BORDER_SIZE;
    }

    final int xShift = AllIcons.Actions.RealIntentionBulb.getIconWidth();

    realPoint = new Point(Math.max(0, visibleArea.x - xShift), position.y + yShift);
  }

  Point location = SwingUtilities.convertPoint(convertComponent, realPoint, editor.getComponent().getRootPane().getLayeredPane());
  return new Point(location.x, location.y);
}
 
Example 16
Source File: UnindentSelectionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  return !editor.isOneLineMode() && !((EditorEx)editor).isEmbeddedIntoDialogWrapper();
}
 
Example 17
Source File: MoveCaretUpAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  return !editor.isOneLineMode();
}
 
Example 18
Source File: MoveCaretDownAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  return !editor.isOneLineMode();
}