import com.intellij.ui.HintListener; //导入依赖的package包/类
public static void showActiveHint(@NotNull Range range,
@NotNull Editor editor,
@Nullable Point mousePosition,
@NotNull LineStatusTracker tracker) {
final Disposable disposable = Disposer.newDisposable();
List wordDiff = computeWordDiff(range, tracker);
installEditorHighlighters(range, editor, tracker, wordDiff, disposable);
Pair editorComponent = createEditorComponent(range, editor, tracker, wordDiff);
ActionToolbar toolbar = buildToolbar(range, editor, tracker, disposable);
toolbar.updateActionsImmediately(); // we need valid ActionToolbar.getPreferredSize() to calc size of popup
PopupPanel popupPanel = new PopupPanel(editor, toolbar, editorComponent.first, editorComponent.second);
LightweightHint hint = new LightweightHint(popupPanel);
HintListener closeListener = new HintListener() {
public void hintHidden(final EventObject event) {
Disposer.dispose(disposable);
}
};
hint.addHintListener(closeListener);
int line = editor.getCaretModel().getLogicalPosition().line;
Point point = HintManagerImpl.getHintPosition(hint, editor, new LogicalPosition(line, 0), HintManager.UNDER);
if (mousePosition != null) { // show right after the nearest line
int lineHeight = editor.getLineHeight();
int delta = (point.y - mousePosition.y) % lineHeight;
if (delta < 0) delta += lineHeight;
point.y = mousePosition.y + delta;
}
point.x -= popupPanel.getEditorTextOffset(); // align main editor with the one in popup
int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, flags, -1, false, new HintHint(editor, point));
if (!hint.isVisible()) {
closeListener.hintHidden(null);
}
}