在 IntelliJ 插件中添加 focus/blur 监听器
Add focus/blur listener in IntelliJ plugin
如何监听 IntelliJ 插件中所有编辑器的 focus/blur 事件?
使用getEventMulticaster
method, and then use its addFocusChangeListener
方法得到EditorEventMulticasterEx
:
Disposable disposable = () -> {}; // or your custom disposable
EditorEventMulticasterEx editorEventMulticaster =
(EditorEventMulticasterEx) EditorFactory.getInstance().getEventMulticaster();
editorEventMulticaster.addFocusChangeListener(new FocusChangeListener() {
@Override
public void focusGained(@NotNull Editor editor) {
// handle focus event
}
@Override
public void focusLost(@NotNull Editor editor) {
// handle blur event
}
}, disposable);
如何监听 IntelliJ 插件中所有编辑器的 focus/blur 事件?
使用getEventMulticaster
method, and then use its addFocusChangeListener
方法得到EditorEventMulticasterEx
:
Disposable disposable = () -> {}; // or your custom disposable
EditorEventMulticasterEx editorEventMulticaster =
(EditorEventMulticasterEx) EditorFactory.getInstance().getEventMulticaster();
editorEventMulticaster.addFocusChangeListener(new FocusChangeListener() {
@Override
public void focusGained(@NotNull Editor editor) {
// handle focus event
}
@Override
public void focusLost(@NotNull Editor editor) {
// handle blur event
}
}, disposable);