@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    String key = 'Optimize this code:';
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (editor != null) {
        SelectionModel selectionModel = editor.getSelectionModel();
        String selectedText = selectionModel.getSelectedText();
        if (selectedText != null && !selectedText.isEmpty()) {
            HintManager.getInstance().showInformationHint(editor, key);
        }
    }
}

This code demonstrates how to create an IntelliJ IDEA plugin that displays a popup with a custom message 'Optimize this code:' next to the selected code in the editor. The plugin utilizes the actionPerformed method to handle the event and retrieve the selected text from the editor. If the selected text is not empty, the plugin uses HintManager to display the information hint with the custom message. This example provides a basic framework for adding similar functionality to your IntelliJ IDEA plugins.

IntelliJ IDEA Plugin: Display a Popup Next to Selected Code

原文地址: https://www.cveoy.top/t/topic/mUX3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录