mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-01-14 01:42:47 +01:00
Don't reset visual mode after some IntelliJ actions that operate on selections
These actions are: comment by block/line comment, surround with / surround with template, move statement up/down. The reason is simplification of action handling as a step towards keymap-less IdeaVim configuration.
This commit is contained in:
parent
4e84f056aa
commit
4a7557c5ba
resources/META-INF
src/com/maddyhome/idea/vim
@ -274,14 +274,8 @@
|
||||
<action id="VimFilterMotion" class="com.maddyhome.idea.vim.action.change.change.FilterMotionAction" text="Filter Lines"/>
|
||||
<action id="VimFilterCountLines" class="com.maddyhome.idea.vim.action.change.change.FilterCountLinesAction" text="Filter Lines"/>
|
||||
<action id="VimFilterVisualLines" class="com.maddyhome.idea.vim.action.change.change.FilterVisualLinesAction" text="Filter Visual Lines"/>
|
||||
<action id="VimAutoIndentVisual" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Auto Indent Selection"/>
|
||||
<action id="VimReformatVisual" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Reformat Selection"/>
|
||||
<action id="VimCommentByBlockComment" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Block Comment"/>
|
||||
<action id="VimCommentByLineComment" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Line Comment"/>
|
||||
<action id="VimSurroundWith" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Surround With"/>
|
||||
<action id="VimSurroundWithLiveTemplate" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Surround With Live Template"/>
|
||||
<action id="VimMoveStatementDown" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Move Statement Down"/>
|
||||
<action id="VimMoveStatementUp" class="com.maddyhome.idea.vim.action.visual.VisualOperatorDelegateAction" text="Move Statement Up"/>
|
||||
<action id="VimAutoIndentVisual" class="com.maddyhome.idea.vim.action.change.change.AutoIndentLinesVisualAction" text="Auto Indent Selection"/>
|
||||
<action id="VimReformatVisual" class="com.maddyhome.idea.vim.action.change.change.ReformatCodeVisualAction" text="Reformat Selection"/>
|
||||
|
||||
<!-- Shift -->
|
||||
<action id="VimAutoIndentLines" class="com.maddyhome.idea.vim.action.change.shift.AutoIndentLinesAction" text="Auto Indent Lines"/>
|
||||
|
@ -48,9 +48,6 @@ public class RegisterActions {
|
||||
* Update many of the built-in IDEA actions with our key handlers.
|
||||
*/
|
||||
private static void updatePlatformActionHandlers(@NotNull KeyParser parser) {
|
||||
parser.setupActionHandler("AutoIndentLines", "VimAutoIndentVisual");
|
||||
parser.setupActionHandler("ReformatCode", "VimReformatVisual");
|
||||
|
||||
// This group allows us to propagate the keystroke if action acts on something other than an editor
|
||||
parser.setupActionHandler("EditorBackSpace", "VimEditorBackSpace", KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0));
|
||||
parser.setupActionHandler("EditorDelete", "VimEditorDelete", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
|
||||
@ -114,26 +111,6 @@ public class RegisterActions {
|
||||
}
|
||||
|
||||
private static void registerVariousModesActions(@NotNull KeyParser parser) {
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_INSERT | KeyParser.MAPPING_VISUAL,
|
||||
"VimCommentByLineComment", Command.Type.CHANGE,
|
||||
Command.FLAG_MOT_LINEWISE | Command.FLAG_KEEP_VISUAL);
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimCommentByBlockComment",
|
||||
Command.Type.CHANGE, Command.FLAG_MOT_LINEWISE);
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimSurroundWith",
|
||||
Command.Type.CHANGE, Command.FLAG_DELEGATE |
|
||||
Command.FLAG_MOT_LINEWISE |
|
||||
Command.FLAG_FORCE_LINEWISE |
|
||||
Command.FLAG_FORCE_VISUAL);
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimSurroundWithLiveTemplate",
|
||||
Command.Type.CHANGE, Command.FLAG_DELEGATE |
|
||||
Command.FLAG_MOT_LINEWISE |
|
||||
Command.FLAG_FORCE_LINEWISE |
|
||||
Command.FLAG_FORCE_VISUAL);
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimMoveStatementDown",
|
||||
Command.Type.CHANGE, Command.FLAG_MOT_LINEWISE | Command.FLAG_FORCE_LINEWISE);
|
||||
parser.registerIdeaAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimMoveStatementUp",
|
||||
Command.Type.CHANGE, Command.FLAG_MOT_LINEWISE | Command.FLAG_FORCE_LINEWISE);
|
||||
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL | KeyParser.MAPPING_VISUAL, "VimVisualToggleCharacterMode",
|
||||
Command.Type.OTHER_READONLY,
|
||||
Command.FLAG_MOT_CHARACTERWISE,
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class AbstractDelegateAction extends AnAction implements DelegateAction {
|
||||
protected AbstractDelegateAction() {
|
||||
}
|
||||
|
||||
protected AbstractDelegateAction(@NotNull AnAction origAction) {
|
||||
setOrigAction(origAction);
|
||||
}
|
||||
|
||||
public void setOrigAction(@NotNull AnAction origAction) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("origAction=" + origAction);
|
||||
}
|
||||
this.origAction = origAction;
|
||||
copyFrom(origAction);
|
||||
}
|
||||
|
||||
public AnAction getOrigAction() {
|
||||
return origAction;
|
||||
}
|
||||
|
||||
private AnAction origAction;
|
||||
|
||||
private static Logger logger = Logger.getInstance(AbstractDelegateAction.class.getName());
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class AbstractDelegateEditorAction extends EditorAction implements DelegateAction {
|
||||
protected AbstractDelegateEditorAction(EditorActionHandler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
protected AbstractDelegateEditorAction(EditorActionHandler handler, @NotNull EditorAction origAction) {
|
||||
this(handler);
|
||||
setOrigAction(origAction);
|
||||
}
|
||||
|
||||
public void setOrigAction(@NotNull AnAction origAction) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("origAction=" + origAction);
|
||||
}
|
||||
this.origAction = origAction;
|
||||
copyFrom(origAction);
|
||||
}
|
||||
|
||||
public AnAction getOrigAction() {
|
||||
return origAction;
|
||||
}
|
||||
|
||||
private AnAction origAction;
|
||||
|
||||
private static Logger logger = Logger.getInstance(AbstractDelegateEditorAction.class.getName());
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
|
||||
public interface DelegateAction {
|
||||
void setOrigAction(AnAction origAction);
|
||||
|
||||
AnAction getOrigAction();
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class PassThruDelegateAction extends AbstractDelegateAction {
|
||||
public PassThruDelegateAction(KeyStroke stroke) {
|
||||
this.stroke = stroke;
|
||||
}
|
||||
|
||||
public void actionPerformed(@NotNull AnActionEvent event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("actionPerformed key=" + stroke);
|
||||
}
|
||||
final Editor editor = event.getData(PlatformDataKeys.EDITOR); // API change - don't merge
|
||||
if (editor == null || !VimPlugin.isEnabled()) {
|
||||
getOrigAction().actionPerformed(event);
|
||||
}
|
||||
else if (event.getInputEvent() instanceof KeyEvent) {
|
||||
KeyStroke key = KeyStroke.getKeyStrokeForEvent((KeyEvent)event.getInputEvent());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("event = KeyEvent: " + key);
|
||||
}
|
||||
KeyHandler.getInstance().handleKey(editor, key, event.getDataContext());
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("event is a " + event.getInputEvent().getClass().getName());
|
||||
}
|
||||
KeyHandler.getInstance().handleKey(editor, stroke, event.getDataContext());
|
||||
}
|
||||
}
|
||||
|
||||
private KeyStroke stroke;
|
||||
|
||||
private static Logger logger = Logger.getInstance(PassThruDelegateAction.class.getName());
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class PassThruDelegateEditorAction extends AbstractDelegateEditorAction {
|
||||
public PassThruDelegateEditorAction(KeyStroke stroke, EditorActionHandler origHandler) {
|
||||
super(new MyHandler(stroke, origHandler));
|
||||
}
|
||||
|
||||
private static Logger logger = Logger.getInstance(PassThruDelegateEditorAction.class.getName());
|
||||
|
||||
private static class MyHandler extends EditorActionHandler {
|
||||
public MyHandler(KeyStroke stroke, EditorActionHandler handler) {
|
||||
this.stroke = stroke;
|
||||
this.origHandler = handler;
|
||||
}
|
||||
|
||||
public void execute(@NotNull Editor editor, @NotNull DataContext dataContext) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("actionPerformed key=" + stroke);
|
||||
}
|
||||
if (!VimPlugin.isEnabled()) {
|
||||
origHandler.execute(editor, dataContext);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("event = KeyEvent: " + stroke);
|
||||
}
|
||||
KeyHandler.getInstance().handleKey(InjectedLanguageUtil.getTopLevelEditor(editor), stroke, dataContext);
|
||||
}
|
||||
}
|
||||
|
||||
private KeyStroke stroke;
|
||||
private EditorActionHandler origHandler;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.maddyhome.idea.vim.action.change.change;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.group.CommandGroups;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class AutoIndentLinesVisualAction extends EditorAction {
|
||||
public AutoIndentLinesVisualAction() {
|
||||
super(new VisualOperatorActionHandler() {
|
||||
@Override
|
||||
protected boolean execute(@NotNull Editor editor,
|
||||
@NotNull DataContext context,
|
||||
@NotNull Command cmd,
|
||||
@NotNull TextRange range) {
|
||||
CommandGroups.getInstance().getChange().autoIndentLines(context);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.maddyhome.idea.vim.action.change.change;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.group.CommandGroups;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class ReformatCodeVisualAction extends EditorAction {
|
||||
public ReformatCodeVisualAction() {
|
||||
super(new VisualOperatorActionHandler() {
|
||||
@Override
|
||||
protected boolean execute(@NotNull Editor editor,
|
||||
@NotNull DataContext context,
|
||||
@NotNull Command cmd,
|
||||
@NotNull TextRange range) {
|
||||
CommandGroups.getInstance().getChange().reformatCode(context);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@ public class AutoIndentLinesAction extends EditorAction {
|
||||
private static class Handler extends ChangeEditorActionHandler {
|
||||
public boolean execute(Editor editor, @NotNull DataContext context, int count, int rawCount, Argument argument) {
|
||||
CommandGroups.getInstance().getChange().autoIndentLines(context);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.action.visual;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.action.AbstractDelegateEditorAction;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.handler.AbstractEditorActionHandler;
|
||||
import com.maddyhome.idea.vim.handler.DelegateActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VisualOperatorDelegateAction extends AbstractDelegateEditorAction {
|
||||
public VisualOperatorDelegateAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
public void setOrigAction(@NotNull AnAction origAction) {
|
||||
super.setOrigAction(origAction);
|
||||
((Handler)getHandler()).setOrigAction(origAction);
|
||||
}
|
||||
|
||||
private static class Handler extends AbstractEditorActionHandler implements DelegateActionHandler {
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull Command cmd) {
|
||||
KeyHandler.executeAction(origAction, context);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setOrigAction(AnAction origAction) {
|
||||
if (logger.isDebugEnabled()) logger.debug("setOrigHander to " + origAction);
|
||||
this.origAction = origAction;
|
||||
}
|
||||
|
||||
public AnAction getOrigAction() {
|
||||
return origAction;
|
||||
}
|
||||
|
||||
private AnAction origAction;
|
||||
|
||||
private static Logger logger = Logger.getInstance(Handler.class.getName());
|
||||
}
|
||||
}
|
@ -1291,7 +1291,11 @@ public class ChangeGroup extends AbstractActionGroup {
|
||||
}
|
||||
|
||||
public void autoIndentLines(@NotNull DataContext context) {
|
||||
KeyHandler.executeAction("OrigAutoIndentLines", context);
|
||||
KeyHandler.executeAction("AutoIndentLines", context);
|
||||
}
|
||||
|
||||
public void reformatCode(@NotNull DataContext context) {
|
||||
KeyHandler.executeAction("ReformatCode", context);
|
||||
}
|
||||
|
||||
public void indentLines(@NotNull Editor editor, @NotNull DataContext context, int lines, int dir) {
|
||||
|
@ -22,7 +22,6 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.command.Argument;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.command.SelectionType;
|
||||
@ -371,7 +370,7 @@ public class CopyGroup extends AbstractActionGroup {
|
||||
int startOff = editor.getDocument().getLineStartOffset(slp.line);
|
||||
int endOff = editor.getDocument().getLineEndOffset(elp.line);
|
||||
editor.getSelectionModel().setSelection(startOff, endOff);
|
||||
KeyHandler.executeAction("OrigAutoIndentLines", context);
|
||||
CommandGroups.getInstance().getChange().autoIndentLines(context);
|
||||
}
|
||||
/*
|
||||
boolean indented = false;
|
||||
|
@ -23,7 +23,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
@ -35,9 +34,8 @@ public abstract class AbstractEditorActionHandler extends EditorActionHandler {
|
||||
public final void execute(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
|
||||
logger.debug("execute");
|
||||
if (!VimPlugin.isEnabled() && this instanceof DelegateActionHandler) {
|
||||
KeyHandler.executeAction(((DelegateActionHandler)this).getOrigAction(), context);
|
||||
|
||||
if (!VimPlugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.handler;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
|
||||
public interface DelegateActionHandler {
|
||||
void setOrigAction(AnAction origAction);
|
||||
|
||||
AnAction getOrigAction();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2013 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.handler.change.change;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AutoIndentVisualHandler extends VisualOperatorActionHandler {
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull Command cmd,
|
||||
@NotNull TextRange range) {
|
||||
KeyHandler.executeAction("OrigAutoIndentLines", context);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -20,15 +20,9 @@ package com.maddyhome.idea.vim.key;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.keymap.Keymap;
|
||||
import com.intellij.openapi.keymap.KeymapManager;
|
||||
import com.maddyhome.idea.vim.action.DelegateAction;
|
||||
import com.maddyhome.idea.vim.action.PassThruDelegateAction;
|
||||
import com.maddyhome.idea.vim.action.PassThruDelegateEditorAction;
|
||||
import com.maddyhome.idea.vim.command.Argument;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.handler.key.EditorKeyHandler;
|
||||
@ -36,7 +30,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -100,35 +93,6 @@ public class KeyParser {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setupActionHandler(@NotNull String ideaActName, @NotNull String vimActName) {
|
||||
if (logger.isDebugEnabled()) logger.debug("vimActName=" + vimActName);
|
||||
|
||||
ActionManager manager = ActionManager.getInstance();
|
||||
AnAction vimAction = manager.getAction(vimActName);
|
||||
if (vimAction instanceof DelegateAction) {
|
||||
manager.unregisterAction(vimActName);
|
||||
}
|
||||
setupActionHandler(ideaActName, vimAction);
|
||||
}
|
||||
|
||||
public void setupActionHandler(@NotNull String ideaActName, @NotNull AnAction vimAction) {
|
||||
if (logger.isDebugEnabled()) logger.debug("ideaActName=" + ideaActName);
|
||||
|
||||
ActionManager manager = ActionManager.getInstance();
|
||||
AnAction ideaAction = manager.getAction(ideaActName);
|
||||
if (ideaAction == null) return; // ignore actions which aren't available in RubyMine
|
||||
if (vimAction instanceof DelegateAction) {
|
||||
DelegateAction delegateAction = (DelegateAction)vimAction;
|
||||
delegateAction.setOrigAction(ideaAction);
|
||||
|
||||
manager.unregisterAction(ideaActName);
|
||||
|
||||
manager.registerAction(ideaActName, vimAction);
|
||||
}
|
||||
|
||||
manager.registerAction("Orig" + ideaActName, ideaAction);
|
||||
}
|
||||
|
||||
public void setupActionHandler(@NotNull String ideaActName, String vimActName, @NotNull KeyStroke stroke) {
|
||||
setupActionHandler(ideaActName, vimActName, stroke, false);
|
||||
}
|
||||
@ -177,51 +141,6 @@ public class KeyParser {
|
||||
return res;
|
||||
}
|
||||
|
||||
public void registerIdeaAction(int mapping, @NotNull String actName, @NotNull Command.Type cmdType, int cmdFlags) {
|
||||
String ideaName = actName.substring(3);
|
||||
ActionManager manager = ActionManager.getInstance();
|
||||
if (manager.getAction(ideaName) == null) {
|
||||
logger.info("No registered action " + ideaName);
|
||||
return;
|
||||
}
|
||||
|
||||
Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
|
||||
com.intellij.openapi.actionSystem.Shortcut[] cuts = keymap.getShortcuts(ideaName);
|
||||
ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
|
||||
for (com.intellij.openapi.actionSystem.Shortcut cut : cuts) {
|
||||
if (cut instanceof KeyboardShortcut) {
|
||||
KeyStroke keyStroke = ((KeyboardShortcut)cut).getFirstKeyStroke();
|
||||
Shortcut shortcut = new Shortcut(keyStroke);
|
||||
shortcuts.add(shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
registerAction(mapping, actName, cmdType, cmdFlags, shortcuts.toArray(new Shortcut[shortcuts.size()]));
|
||||
KeyStroke firstStroke = null;
|
||||
for (int i = 0; i < shortcuts.size(); i++) {
|
||||
Shortcut cut = shortcuts.get(i);
|
||||
//removePossibleConflict(cut.getKeys()[0]);
|
||||
if (i == 0) {
|
||||
firstStroke = cut.getKeys()[0];
|
||||
}
|
||||
}
|
||||
|
||||
AnAction ideaAction = manager.getAction(ideaName);
|
||||
AnAction vimAction = manager.getAction(actName);
|
||||
if (vimAction instanceof DelegateAction) {
|
||||
DelegateAction delegateAction = (DelegateAction)vimAction;
|
||||
delegateAction.setOrigAction(ideaAction);
|
||||
}
|
||||
|
||||
if (ideaAction instanceof EditorAction) {
|
||||
EditorAction ea = (EditorAction)ideaAction;
|
||||
setupActionHandler(ideaName, new PassThruDelegateEditorAction(firstStroke, ea.getHandler()));
|
||||
}
|
||||
else {
|
||||
setupActionHandler(ideaName, new PassThruDelegateAction(firstStroke));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the action
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user