mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-08 18:40:37 +02:00
Unify ':map' and ':noremap' handlers
This commit is contained in:
parent
c77812d2a8
commit
c93daf78f6
src/com/maddyhome/idea/vim
@ -89,7 +89,6 @@ public class CommandParser {
|
||||
new MoveTextHandler();
|
||||
new NextFileHandler();
|
||||
new NoHLSearchHandler();
|
||||
new NonRecursiveMapHandler();
|
||||
new OnlyHandler();
|
||||
new PreviousFileHandler();
|
||||
new PromptFindHandler();
|
||||
|
@ -49,6 +49,13 @@ public class MapHandler extends CommandHandler implements VimrcCommandHandler {
|
||||
new CommandInfo("om", "ap", MappingMode.O, true),
|
||||
new CommandInfo("im", "ap", MappingMode.I, true),
|
||||
new CommandInfo("cm", "ap", MappingMode.C, true),
|
||||
// TODO: Support xnoremap, snoremap, noremap!, lnoremap
|
||||
new CommandInfo("no", "remap", MappingMode.NVO, false),
|
||||
new CommandInfo("nn", "oremap", MappingMode.N, false),
|
||||
new CommandInfo("vn", "oremap", MappingMode.V, false),
|
||||
new CommandInfo("ono", "remap", MappingMode.O, false),
|
||||
new CommandInfo("ino", "remap", MappingMode.I, false),
|
||||
new CommandInfo("cno", "remap", MappingMode.C, false),
|
||||
};
|
||||
public static final CommandName[] COMMAND_NAMES = createCommandNames();
|
||||
|
||||
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2014 The IdeaVim authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.handler;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.CommandName;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.VimrcCommandHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class NonRecursiveMapHandler extends CommandHandler implements VimrcCommandHandler {
|
||||
public static final Pattern RE_NOREMAP_ARGUMENTS = Pattern.compile("([^ ]+) +(.+)");
|
||||
|
||||
public NonRecursiveMapHandler() {
|
||||
super(new CommandName[]{
|
||||
// TODO: Support xnoremap, snoremap, noremap!, lnoremap
|
||||
new CommandName("no", "remap"),
|
||||
new CommandName("nn", "oremap"),
|
||||
new CommandName("vn", "oremap"),
|
||||
new CommandName("ono", "remap"),
|
||||
new CommandName("ino", "remap"),
|
||||
new CommandName("cno", "remap")
|
||||
}, RANGE_FORBIDDEN | ARGUMENT_OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) {
|
||||
return executeCommand(cmd, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull ExCommand cmd) {
|
||||
executeCommand(cmd, null);
|
||||
}
|
||||
|
||||
private boolean executeCommand(@NotNull ExCommand cmd, @Nullable Editor editor) {
|
||||
final Set<MappingMode> modes = getMappingModes(cmd.getCommand());
|
||||
if (modes != null) {
|
||||
final String argument = cmd.getArgument();
|
||||
if (argument.isEmpty()) {
|
||||
return editor != null && VimPlugin.getKey().showKeyMappings(modes, editor);
|
||||
}
|
||||
else {
|
||||
final Matcher matcher = RE_NOREMAP_ARGUMENTS.matcher(argument);
|
||||
if (matcher.matches()) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, parseKeys(matcher.group(1)), parseKeys(matcher.group(2)), false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Set<MappingMode> getMappingModes(@NotNull String command) {
|
||||
if (command.equals("no")) {
|
||||
return MappingMode.NVO;
|
||||
}
|
||||
else if (command.startsWith("nn")) {
|
||||
return MappingMode.N;
|
||||
}
|
||||
else if (command.startsWith("vn")) {
|
||||
return MappingMode.V;
|
||||
}
|
||||
else if (command.startsWith("ono")) {
|
||||
return MappingMode.O;
|
||||
}
|
||||
else if (command.startsWith("ino")) {
|
||||
return MappingMode.I;
|
||||
}
|
||||
else if (command.startsWith("cno")) {
|
||||
return MappingMode.C;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
* |:omap|
|
||||
* |:imap|
|
||||
* |:cmap|
|
||||
* |:noremap| {@link com.maddyhome.idea.vim.ex.handler.NonRecursiveMapHandler}
|
||||
* |:noremap|
|
||||
* |:nnoremap|
|
||||
* |:vnoremap|
|
||||
* |:onoremap|
|
||||
|
Loading…
Reference in New Issue
Block a user