Java Code Examples for com.intellij.openapi.editor.event.EditorMouseEvent#getEditor()

The following examples show how to use com.intellij.openapi.editor.event.EditorMouseEvent#getEditor() . 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: EditorEventManager.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the mouse is clicked
 * At the moment, is used by CTRL+click to see references / goto definition
 *
 * @param e The mouse event
 */
public void mouseClicked(EditorMouseEvent e) {
    if (e.getEditor() != editor) {
        LOG.error("Wrong editor for EditorEventManager");
        return;
    }

    if (getIsCtrlDown()) {
        // If CTRL/CMD key is pressed, triggers goto definition/references and hover.
        try {
            trySourceNavigationAndHover(e);
        } catch (Exception err) {
            LOG.warn("Error occurred when trying source navigation", err);
        }
    }
}
 
Example 2
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void mouseMoved(EditorMouseEvent e){
	int offset = getEditorCharOffsetAndRemoveTokenHighlighters(e);
	if ( offset<0 ) return;

	Editor editor=e.getEditor();
	if ( inputPanel.previewState==null ) {
		return;
	}

	MouseEvent mouseEvent=e.getMouseEvent();
	InputPanel.clearTokenInfoHighlighters(e.getEditor());
	if ( mouseEvent.isControlDown() && inputPanel.previewState.parsingResult!=null ) {
		inputPanel.showTokenInfoUponCtrlKey(editor, inputPanel.previewState, offset);
	}
	else if ( mouseEvent.isAltDown() && inputPanel.previewState.parsingResult!=null ) {
		inputPanel.showParseRegion(e, editor, inputPanel.previewState, offset);
	}
	else { // just moving around, show any errors or hints
		InputPanel.showTooltips(e, editor, inputPanel.previewState, offset);
	}
}
 
Example 3
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int getEditorCharOffsetAndRemoveTokenHighlighters(EditorMouseEvent e) {
		if ( e.getArea()!=EditorMouseEventArea.EDITING_AREA ) {
			return -1;
		}

		MouseEvent mouseEvent=e.getMouseEvent();
		Editor editor=e.getEditor();
		int offset = MyActionUtils.getMouseOffset(mouseEvent, editor);
//		System.out.println("offset="+offset);

		if ( offset >= editor.getDocument().getTextLength() ) {
			return -1;
		}

		// Mouse has moved so make sure we don't show any token information tooltips
		InputPanel.clearTokenInfoHighlighters(e.getEditor());
		return offset;
	}
 
Example 4
Source File: FoldingPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent e) {
  myAlarm.cancelAllRequests();
  Editor editor = e.getEditor();
  if (editor.getUserData(DISABLED) != null) return;
  if (e.getArea() == EditorMouseEventArea.EDITING_AREA) {
    MouseEvent mouseEvent = e.getMouseEvent();
    Point point = mouseEvent.getPoint();
    FoldRegion fold = ((EditorEx)editor).getFoldingModel().getFoldingPlaceholderAt(point);
    TooltipController controller = TooltipController.getInstance();
    if (fold != null && !fold.shouldNeverExpand()) {
      myAlarm.addRequest(() -> {
        if (editor.getUserData(DISABLED) != null || !editor.getComponent().isShowing() || !fold.isValid() || fold.isExpanded()) return;
        DocumentFragment range = createDocumentFragment(fold);
        Point p = SwingUtilities.convertPoint((Component)mouseEvent.getSource(), point, editor.getComponent().getRootPane().getLayeredPane());
        controller.showTooltip(editor, p, new DocumentFragmentTooltipRenderer(range), false, FOLDING_TOOLTIP_GROUP);
      }, TOOLTIP_DELAY_MS);
    }
    else {
      controller.cancelTooltip(FOLDING_TOOLTIP_GROUP, mouseEvent, true);
    }
  }
}
 
Example 5
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseClicked(EditorMouseEvent e) {
	final int offset = getEditorCharOffsetAndRemoveTokenHighlighters(e);
	if ( offset<0 ) return;

	final Editor editor=e.getEditor();
	if ( inputPanel.previewState==null ) {
		return;
	}

	if ( e.getMouseEvent().getButton()==MouseEvent.BUTTON3 ) { // right click
		rightClick(e, inputPanel.previewState, editor, offset);
		return;
	}

	MouseEvent mouseEvent=e.getMouseEvent();
	if ( mouseEvent.isControlDown() ) {
		inputPanel.setCursorToGrammarElement(e.getEditor().getProject(), inputPanel.previewState, offset);
		inputPanel.setCursorToHierarchyViewElement(offset);
	}
	else if ( mouseEvent.isAltDown() ) {
		inputPanel.setCursorToGrammarRule(e.getEditor().getProject(), inputPanel.previewState, offset);
	}
	else {
		inputPanel.setCursorToHierarchyViewElement(offset);
	}
	InputPanel.clearDecisionEventHighlighters(editor);
}
 
Example 6
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void mouseMoved(EditorMouseEvent e) {
  Editor editor = e.getEditor();
  if (editor.getProject() != null && editor.getProject() != myProject && myProject != null/*???*/) return;
  if (!isInMyArea(e)) return;
  Cursor cursor = getOpenFileDescriptor(e) != null ? HAND__CURSOR : Cursor.getDefaultCursor();
  e.getMouseEvent().getComponent().setCursor(cursor);
  myEditor.getContentComponent().setCursor(cursor);
}
 
Example 7
Source File: MergeSearchHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Change findChangeAt(EditorMouseEvent e, MergePanel2 mergePanel, int index) {
  if (mergePanel.getMergeList() == null) return null;
  Editor editor = e.getEditor();
  LOG.assertTrue(editor == mergePanel.getEditor(index));
  LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
  int offset = editor.logicalPositionToOffset(logicalPosition);
  return forMergeList(mergePanel.getMergeList(), index).findChangeAt(offset);
}
 
Example 8
Source File: ValueLookupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void mouseMoved(EditorMouseEvent e) {
  if (e.isConsumed()) {
    return;
  }

  Editor editor = e.getEditor();
  if (editor.getProject() != null && editor.getProject() != myProject) {
    return;
  }

  ValueHintType type = AbstractValueHint.getHintType(e);
  if (e.getArea() != EditorMouseEventArea.EDITING_AREA ||
      DISABLE_VALUE_LOOKUP.get(editor) == Boolean.TRUE ||
      type == null) {
    myAlarm.cancelAllRequests();
    return;
  }

  Point point = e.getMouseEvent().getPoint();
  if (myRequest != null && !myRequest.isKeepHint(editor, point)) {
    hideHint();
  }

  for (DebuggerSupport support : mySupports) {
    QuickEvaluateHandler handler = support.getQuickEvaluateHandler();
    if (handler.isEnabled(myProject)) {
      requestHint(handler, editor, point, type);
      break;
    }
  }
}
 
Example 9
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 10
Source File: EditorEventManager.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Will show documentation if the mouse doesn't move for a given time (Hover)
 *
 * @param e the event
 */
public void mouseMoved(EditorMouseEvent e) {

    if (e.getEditor() != editor) {
        LOG.error("Wrong editor for EditorEventManager");
        return;
    }

    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile == null) {
        return;
    }
    Language language = psiFile.getLanguage();
    if ((!LanguageDocumentation.INSTANCE.allForLanguage(language).isEmpty() && !isSupportedLanguageFile(psiFile))
            || (!getIsCtrlDown() && !EditorSettingsExternalizable.getInstance().isShowQuickDocOnMouseOverElement())) {
        return;
    }

    long curTime = System.nanoTime();
    if (predTime == (-1L) || ctrlTime == (-1L)) {
        predTime = curTime;
        ctrlTime = curTime;
    } else {
        LogicalPosition lPos = getPos(e);
        if (lPos == null || getIsKeyPressed() && !getIsCtrlDown()) {
            return;
        }

        int offset = editor.logicalPositionToOffset(lPos);
        if (getIsCtrlDown() && curTime - ctrlTime > EditorEventManagerBase.CTRL_THRESH) {
            if (getCtrlRange() == null || !getCtrlRange().highlightContainsOffset(offset)) {
                if (currentHint != null) {
                    currentHint.hide();
                }
                currentHint = null;
                if (getCtrlRange() != null) {
                    getCtrlRange().dispose();
                }
                setCtrlRange(null);
                pool(() -> requestAndShowDoc(lPos, e.getMouseEvent().getPoint()));
            } else if (getCtrlRange().definitionContainsOffset(offset)) {
                createAndShowEditorHint(editor, "Click to show usages", editor.offsetToXY(offset));
            } else {
                editor.getContentComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            }
            ctrlTime = curTime;
        }
        predTime = curTime;
    }
}