mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-07 03:32:51 +01:00
Initialize IdeaVim components on non-EDT
This commit is contained in:
parent
66b7019da9
commit
6fd6765bee
src/com/maddyhome/idea/vim
@ -148,6 +148,8 @@ public class KeyHandler {
|
||||
@NotNull KeyStroke key,
|
||||
@NotNull DataContext context,
|
||||
boolean allowKeyMappings) {
|
||||
if (VimPlugin.Initialization.notInitialized()) return;
|
||||
|
||||
VimPlugin.clearError();
|
||||
// All the editor actions should be performed with top level editor!!!
|
||||
// Be careful: all the EditorActionHandler implementation should correctly process InjectedEditors
|
||||
|
@ -19,6 +19,7 @@ package com.maddyhome.idea.vim;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.maddyhome.idea.vim.action.VimCommandActionBase;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandFlags;
|
||||
@ -35,8 +36,17 @@ class RegisterActions {
|
||||
* Register all the key/action mappings for the plugin.
|
||||
*/
|
||||
static void registerActions() {
|
||||
registerVimCommandActions();
|
||||
registerSystemMappings();
|
||||
Runnable setup = () -> {
|
||||
registerVimCommandActions();
|
||||
registerSystemMappings();
|
||||
VimPlugin.Initialization.actionsInitialized();
|
||||
};
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
setup.run();
|
||||
} else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(setup);
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerVimCommandActions() {
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.configurationStore.APP_CONFIG
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.State
|
||||
@ -48,9 +49,17 @@ class VimLocalConfig : PersistentStateComponent<Element> {
|
||||
}
|
||||
|
||||
override fun loadState(state: Element) {
|
||||
VimPlugin.getMark().readData(state)
|
||||
VimPlugin.getRegister().readData(state)
|
||||
VimPlugin.getSearch().readData(state)
|
||||
VimPlugin.getHistory().readData(state)
|
||||
val setup = {
|
||||
VimPlugin.getMark().readData(state)
|
||||
VimPlugin.getRegister().readData(state)
|
||||
VimPlugin.getSearch().readData(state)
|
||||
VimPlugin.getHistory().readData(state)
|
||||
}
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
setup()
|
||||
} else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(setup)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* This plugin attempts to emulate the key binding and general functionality of Vim and gVim. See the supplied
|
||||
@ -444,6 +445,24 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
}
|
||||
}
|
||||
|
||||
public static class Initialization {
|
||||
private static final AtomicBoolean initializedActions = new AtomicBoolean(false);
|
||||
private static final AtomicBoolean initializedCommands = new AtomicBoolean(false);
|
||||
|
||||
public static boolean notInitialized() {
|
||||
return !(initializedActions.get() &&
|
||||
initializedCommands.get());
|
||||
}
|
||||
|
||||
public static void actionsInitialized() {
|
||||
initializedActions.set(true);
|
||||
}
|
||||
|
||||
public static void commandsInitialized() {
|
||||
initializedCommands.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static VimPlugin getInstance() {
|
||||
return (VimPlugin)ApplicationManager.getApplication().getComponent(IDEAVIM_COMPONENT_NAME);
|
||||
@ -514,27 +533,35 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
public void loadState(@NotNull final Element element) {
|
||||
LOG.debug("Loading state");
|
||||
|
||||
// Restore whether the plugin is enabled or not
|
||||
Element state = element.getChild("state");
|
||||
if (state != null) {
|
||||
try {
|
||||
previousStateVersion = Integer.parseInt(state.getAttributeValue("version"));
|
||||
Runnable setup = () -> {
|
||||
// Restore whether the plugin is enabled or not
|
||||
Element state = element.getChild("state");
|
||||
if (state != null) {
|
||||
try {
|
||||
previousStateVersion = Integer.parseInt(state.getAttributeValue("version"));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
enabled = Boolean.parseBoolean(state.getAttributeValue("enabled"));
|
||||
previousKeyMap = state.getAttributeValue("keymap");
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
enabled = Boolean.parseBoolean(state.getAttributeValue("enabled"));
|
||||
previousKeyMap = state.getAttributeValue("keymap");
|
||||
}
|
||||
|
||||
if (previousStateVersion > 0 && previousStateVersion < 5) {
|
||||
// Migrate settings from 4 to 5 version
|
||||
mark.readData(element);
|
||||
register.readData(element);
|
||||
search.readData(element);
|
||||
history.readData(element);
|
||||
if (previousStateVersion > 0 && previousStateVersion < 5) {
|
||||
// Migrate settings from 4 to 5 version
|
||||
mark.readData(element);
|
||||
register.readData(element);
|
||||
search.readData(element);
|
||||
history.readData(element);
|
||||
}
|
||||
key.readData(element);
|
||||
editor.readData(element);
|
||||
this.state.readData(element);
|
||||
};
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
setup.run();
|
||||
} else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(setup);
|
||||
}
|
||||
key.readData(element);
|
||||
editor.readData(element);
|
||||
this.state.readData(element);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import com.maddyhome.idea.vim.helper.Msg;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -130,14 +131,21 @@ public class CommandParser {
|
||||
* Registers all the supported Ex commands
|
||||
*/
|
||||
public void registerHandlers() {
|
||||
if (registered) return;
|
||||
if (registered.getAndSet(true)) return;
|
||||
|
||||
for (CommandHandler handler : myHandlers) {
|
||||
handler.register();
|
||||
Runnable setup = () -> {
|
||||
for (CommandHandler handler : myHandlers) {
|
||||
handler.register();
|
||||
}
|
||||
|
||||
VimPlugin.Initialization.commandsInitialized();
|
||||
};
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
setup.run();
|
||||
} else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(setup);
|
||||
}
|
||||
|
||||
registered = true;
|
||||
//logger.debug("root=" + root);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -649,7 +657,7 @@ public class CommandParser {
|
||||
}
|
||||
|
||||
@NotNull private final CommandNode root = new CommandNode();
|
||||
private boolean registered = false;
|
||||
private AtomicBoolean registered = new AtomicBoolean(false);
|
||||
|
||||
private static CommandParser ourInstance;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user