How does one get an Editor instance for use in the plugin.
Answered
The following code was working , yes one of those :). The entire file is here: https://gist.github.com/digitalrinaldo/be9418b1769bb8b87d64e123a808e02f
@Override
public void update(@NotNull final com.intellij.openapi.actionSystem.AnActionEvent e) {
// Get required data keys
final Project project = e.getProject();
final Editor editor = e.getData(com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR);
System.out.println ( "editor:" + editor );
//Set visibility only in case of existing project and editor
e.getPresentation().setEnabledAndVisible(project != null && editor != null);
editorMouseListener = new LocalEditorMouseListener();
editor.addEditorMouseMotionListener(editorMouseMotionListener);
final CaretModel caretModel = editor.getCaretModel();
caretModel.addCaretListener(caretListener);
}
}
Is this the correct way to get the editor instance? I am getting a null.
final Editor editor = e.getData(com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR);
System.out.println ( "editor:" + editor );
The provided plugin code has a few deprecations.
This is the log for startup, Is this expected all the warnings.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method sun.java2d.SunGraphicsEnvironment.isUIScaleEnabled()
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-03-19 19:14:27,406 [ 1691] WARN - j.internal.DebugAttachDetector - Unable to start DebugAttachDetector, please add `--add-exports java.base/jdk.internal.vm=ALL-UNNAMED` to VM options
2020-03-19 19:14:34,911 [ 9196] WARN - j.ui.mac.MacMainFrameDecorator - no url bundle present.
To use platform protocol handler to open external links specify required protocols in the mac app layout section of the build file
Example: args.urlSchemes = ["your-protocol"] will handle following links: your-protocol://open?file=file&line=line
2020-03-19 19:14:37,288 [ 11573] WARN - com.intellij.util.xmlb.Binding - no accessors for class org.jetbrains.kotlin.idea.highlighter.KotlinDefaultHighlightingSettingsProvider
editor:null
2020-03-19 19:14:41,195 [ 15480] ERROR - ctionSystem.impl.ActionUpdater - update failed for AnAction(org.intellij.sdk.action.EditorEyeTrackingAction) with ID=org.intellij.sdk.action.EditorEyeTrackingAction
java.lang.NullPointerException
Also why is the above bold text missing "a"?
Please sign in to leave a comment.
Rinaldo,
Getting the Editor from the event using getData will work if you've invoked such an event in the proper context.
You can access the current Editor (s) with:
Regarding the missing "a" - warnings above are cut on the left as well - it's just a matter of the available space, presentation - don't worry about that.
What does it mean to invoke the event in the "proper context"?
When I look at https://plugins.jetbrains.com/docs/intellij/basic-action-system.html#determining-the-action-context it states that this sort of data should be available in `onUpdate`? I'm defining an `AnAction` in a custom editor and I need the instance of the editor back so that I don't need to keep state in the `AnAction`.