mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 15:40:37 +02:00
get rid of reflection on ConsoleViewImpl#CONSOLE_VIEW_IN_EDITOR_VIEW after corresponding fix in IntellIJ IDEA codebase
This commit is contained in:
parent
7e32a2600b
commit
24f3b5ec46
@ -19,6 +19,7 @@ package com.maddyhome.idea.vim.helper;
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.intellij.execution.impl.ConsoleViewImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
@ -31,7 +32,6 @@ import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.command.VisualChange;
|
||||
import com.maddyhome.idea.vim.command.VisualRange;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@ -195,7 +195,7 @@ public class EditorData {
|
||||
|
||||
public static boolean isConsoleOutput(Editor editor) {
|
||||
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
|
||||
Object res = editor.getUserData(CONSOLE_VIEW_IN_EDITOR_VIEW);
|
||||
Object res = editor.getUserData(ConsoleViewImpl.CONSOLE_VIEW_IN_EDITOR_VIEW);
|
||||
logger.debug("isConsoleOutput for editor " + editor + " - " + res);
|
||||
return res != null;
|
||||
}
|
||||
@ -225,41 +225,9 @@ public class EditorData {
|
||||
private static final Key<CommandState> COMMAND_STATE = new Key<CommandState>("commandState");
|
||||
private static final Key<Boolean> CHANGE_GROUP = new Key<Boolean>("changeGroup");
|
||||
private static final Key<Boolean> MOTION_GROUP = new Key<Boolean>("motionGroup");
|
||||
private static Key CONSOLE_VIEW_IN_EDITOR_VIEW = Key.create("CONSOLE_VIEW_IN_EDITOR_VIEW");
|
||||
|
||||
private static Logger logger = Logger.getInstance(EditorData.class.getName());
|
||||
|
||||
static {
|
||||
try {
|
||||
// Yikes! The console output pane is really an editor. I need to be able to differentiate this editor
|
||||
// from other editors. After an email with Jetbrains I learned that the class to look at was ConsoleViewImpl
|
||||
// This class creates the editor and adds itself as user data to the editor. Unfortunately the Key used
|
||||
// for the user data is a private static in the class. And the name is obfuscated (why should this be easy).
|
||||
// This code looks at all the fields in ConsoleViewImpl and looks for a field of type Key. It is assumed
|
||||
// the first Key is the one I need. The key is created as:
|
||||
// private static final Key c = Key.create("CONSOLE_VIEW_IN_EDITOR_VIEW");
|
||||
// I tried to create a Key with the same name but it doesn't work. Most likely the Key implementation is
|
||||
// coded such that two keys with the same name are treated as different keys - oh well.
|
||||
// This code will work as long as the key I need is the first one in the ConsoleViewImpl.
|
||||
Class cvi = Class.forName("com.intellij.execution.impl.ConsoleViewImpl");
|
||||
Field[] flds = cvi.getDeclaredFields();
|
||||
for (Field f : flds) {
|
||||
if (f.getType().equals(Key.class)) {
|
||||
f.setAccessible(true);
|
||||
Key key = (Key)f.get(null);
|
||||
CONSOLE_VIEW_IN_EDITOR_VIEW = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
logger.error("ConsoleViewImpl not found");
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
logger.error("Can't access field 'c'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if editor is file editor, also it takes into account that editor can be placed in editors hierarhy
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user