mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-07 12:32:52 +01:00
Ensure all shortcuts are seen by ex entry field
Fixes VIM-1550
This commit is contained in:
parent
e94eac77eb
commit
3a728df3b1
src/com/maddyhome/idea/vim
@ -242,15 +242,15 @@ public class KeyHandler {
|
||||
final CommandState commandState = CommandState.getInstance(editor);
|
||||
commandState.stopMappingTimer();
|
||||
|
||||
final List<KeyStroke> mappingKeys = commandState.getMappingKeys();
|
||||
final List<KeyStroke> fromKeys = new ArrayList<KeyStroke>(mappingKeys);
|
||||
fromKeys.add(key);
|
||||
|
||||
final MappingMode mappingMode = commandState.getMappingMode();
|
||||
if (MappingMode.NVO.contains(mappingMode) && (state != State.NEW_COMMAND || currentArg != Argument.Type.NONE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<KeyStroke> mappingKeys = commandState.getMappingKeys();
|
||||
final List<KeyStroke> fromKeys = new ArrayList<KeyStroke>(mappingKeys);
|
||||
fromKeys.add(key);
|
||||
|
||||
final KeyMapping mapping = VimPlugin.getKey().getKeyMapping(mappingMode);
|
||||
final MappingInfo currentMappingInfo = mapping.get(fromKeys);
|
||||
final MappingInfo prevMappingInfo = mapping.get(mappingKeys);
|
||||
|
@ -40,11 +40,9 @@ import java.awt.event.KeyEvent;
|
||||
public class VimTypedActionHandler implements TypedActionHandlerEx {
|
||||
private static final Logger logger = Logger.getInstance(VimTypedActionHandler.class.getName());
|
||||
|
||||
private final TypedActionHandler origHandler;
|
||||
@NotNull private final KeyHandler handler;
|
||||
|
||||
public VimTypedActionHandler(TypedActionHandler origHandler) {
|
||||
this.origHandler = origHandler;
|
||||
VimTypedActionHandler(TypedActionHandler origHandler) {
|
||||
handler = KeyHandler.getInstance();
|
||||
handler.setOriginalHandler(origHandler);
|
||||
}
|
||||
@ -55,7 +53,7 @@ public class VimTypedActionHandler implements TypedActionHandlerEx {
|
||||
handler.beforeHandleKey(editor, KeyStroke.getKeyStroke(charTyped), context, plan);
|
||||
}
|
||||
else {
|
||||
TypedActionHandler originalHandler = KeyHandler.getInstance().getOriginalHandler();
|
||||
TypedActionHandler originalHandler = handler.getOriginalHandler();
|
||||
if (originalHandler instanceof TypedActionHandlerEx) {
|
||||
((TypedActionHandlerEx)originalHandler).beforeExecute(editor, charTyped, context, plan);
|
||||
}
|
||||
@ -73,6 +71,7 @@ public class VimTypedActionHandler implements TypedActionHandlerEx {
|
||||
}
|
||||
}
|
||||
else {
|
||||
TypedActionHandler origHandler = handler.getOriginalHandler();
|
||||
origHandler.execute(editor, charTyped, context);
|
||||
}
|
||||
}
|
||||
|
@ -68,13 +68,12 @@ public class KeyGroup {
|
||||
@NotNull private final Map<MappingMode, KeyMapping> keyMappings = new HashMap<>();
|
||||
@Nullable private OperatorFunction operatorFunction = null;
|
||||
|
||||
public void registerRequiredShortcutKeys(@NotNull Editor editor) {
|
||||
final Set<KeyStroke> requiredKeys = VimPlugin.getKey().requiredShortcutKeys;
|
||||
void registerRequiredShortcutKeys(@NotNull Editor editor) {
|
||||
EventFacade.getInstance().registerCustomShortcutSet(VimShortcutKeyAction.getInstance(),
|
||||
toShortcutSet(requiredKeys), editor.getComponent());
|
||||
toShortcutSet(requiredShortcutKeys), editor.getComponent());
|
||||
}
|
||||
|
||||
public void unregisterShortcutKeys(@NotNull Editor editor) {
|
||||
void unregisterShortcutKeys(@NotNull Editor editor) {
|
||||
EventFacade.getInstance().unregisterCustomShortcutSet(VimShortcutKeyAction.getInstance(), editor.getComponent());
|
||||
}
|
||||
|
||||
|
49
src/com/maddyhome/idea/vim/ui/ExActions.kt
Normal file
49
src/com/maddyhome/idea/vim/ui/ExActions.kt
Normal file
@ -0,0 +1,49 @@
|
||||
package com.maddyhome.idea.vim.ui
|
||||
|
||||
import com.intellij.openapi.actionSystem.*
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
* An IntelliJ action to forward shortcuts to the ex entry component
|
||||
* <p>
|
||||
* Key events are processed by the IDE action system before they are dispatched to the actual component, which means
|
||||
* they take precedence over the keyboard shortcuts registered with the ex component as Swing actions. This can cause
|
||||
* clashes such as <C-R> invoking the Run action instead of the Paste Register ex action, or <BS> being handled by the
|
||||
* editor rather than allowing us to cancel the ex entry.
|
||||
* <p>
|
||||
* This class is an IDE action that is registered with the ex entry component, so is available only when the ex entry
|
||||
* component has focus. It registers all shortcuts used by the Swing actions and forwards them directly to the key
|
||||
* handler.
|
||||
*/
|
||||
class ExShortcutKeyAction(private val exEntryPanel: ExEntryPanel) : AnAction() {
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val keyStroke = getKeyStroke(e)
|
||||
if (keyStroke != null && exEntryPanel.isActive) {
|
||||
exEntryPanel.handleKey(keyStroke)
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
e.presentation.isEnabled = exEntryPanel.isActive
|
||||
}
|
||||
|
||||
private fun getKeyStroke(e: AnActionEvent): KeyStroke? {
|
||||
val inputEvent = e.inputEvent
|
||||
if (inputEvent is KeyEvent) {
|
||||
return KeyStroke.getKeyStrokeForEvent(inputEvent)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun registerCustomShortcutSet() {
|
||||
|
||||
val shortcuts = ExKeyBindings.bindings.map {
|
||||
KeyboardShortcut(it.key, null)
|
||||
}.toTypedArray()
|
||||
|
||||
registerCustomShortcutSet({ shortcuts }, exEntryPanel)
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KeyStroke convert(@NotNull ActionEvent event) {
|
||||
private static KeyStroke convert(@NotNull ActionEvent event) {
|
||||
String cmd = event.getActionCommand();
|
||||
int mods = event.getModifiers();
|
||||
if (cmd != null && cmd.length() > 0) {
|
||||
@ -99,25 +99,22 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final String DefaultExKey = "default-ex-key";
|
||||
public static final String CancelEntry = "cancel-entry";
|
||||
public static final String CompleteEntry = "complete-entry";
|
||||
public static final String EscapeChar = "escape";
|
||||
public static final String DeletePreviousChar = "delete-prev-char";
|
||||
public static final String DeletePreviousWord = "delete-prev-word";
|
||||
public static final String DeleteToCursor = "delete-to-cursor";
|
||||
public static final String DeleteFromCursor = "delete-from-cursor";
|
||||
public static final String ToggleInsertReplace = "toggle-insert";
|
||||
public static final String InsertRegister = "insert-register";
|
||||
public static final String InsertWord = "insert-word";
|
||||
public static final String InsertWORD = "insert-WORD";
|
||||
public static final String HistoryUp = "history-up";
|
||||
public static final String HistoryDown = "history-down";
|
||||
public static final String HistoryUpFilter = "history-up-filter";
|
||||
public static final String HistoryDownFilter = "history-down-filter";
|
||||
public static final String StartDigraph = "start-digraph";
|
||||
static final String CancelEntry = "cancel-entry";
|
||||
static final String CompleteEntry = "complete-entry";
|
||||
static final String EscapeChar = "escape";
|
||||
static final String DeletePreviousChar = "delete-prev-char";
|
||||
static final String DeletePreviousWord = "delete-prev-word";
|
||||
static final String DeleteToCursor = "delete-to-cursor";
|
||||
static final String DeleteFromCursor = "delete-from-cursor";
|
||||
static final String ToggleInsertReplace = "toggle-insert";
|
||||
static final String InsertRegister = "insert-register";
|
||||
static final String HistoryUp = "history-up";
|
||||
static final String HistoryDown = "history-down";
|
||||
static final String HistoryUpFilter = "history-up-filter";
|
||||
static final String HistoryDownFilter = "history-down-filter";
|
||||
static final String StartDigraph = "start-digraph";
|
||||
|
||||
@NotNull protected final Action[] exActions = new Action[]{
|
||||
@NotNull private final Action[] exActions = new Action[]{
|
||||
new ExEditorKit.CancelEntryAction(),
|
||||
new ExEditorKit.CompleteEntryAction(),
|
||||
new ExEditorKit.EscapeCharAction(),
|
||||
@ -161,7 +158,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class HistoryUpAction extends TextAction {
|
||||
public HistoryUpAction() {
|
||||
HistoryUpAction() {
|
||||
super(HistoryUp);
|
||||
}
|
||||
|
||||
@ -172,7 +169,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class HistoryDownAction extends TextAction {
|
||||
public HistoryDownAction() {
|
||||
HistoryDownAction() {
|
||||
super(HistoryDown);
|
||||
}
|
||||
|
||||
@ -183,7 +180,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class HistoryUpFilterAction extends TextAction {
|
||||
public HistoryUpFilterAction() {
|
||||
HistoryUpFilterAction() {
|
||||
super(HistoryUpFilter);
|
||||
}
|
||||
|
||||
@ -194,7 +191,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class HistoryDownFilterAction extends TextAction {
|
||||
public HistoryDownFilterAction() {
|
||||
HistoryDownFilterAction() {
|
||||
super(HistoryDownFilter);
|
||||
}
|
||||
|
||||
@ -205,14 +202,14 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class InsertRegisterAction extends TextAction {
|
||||
private static enum State {
|
||||
private enum State {
|
||||
SKIP_CTRL_R,
|
||||
WAIT_REGISTER,
|
||||
}
|
||||
|
||||
@NotNull private State state = State.SKIP_CTRL_R;
|
||||
|
||||
public InsertRegisterAction() {
|
||||
InsertRegisterAction() {
|
||||
super(InsertRegister);
|
||||
}
|
||||
|
||||
@ -248,7 +245,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class CompleteEntryAction extends TextAction {
|
||||
public CompleteEntryAction() {
|
||||
CompleteEntryAction() {
|
||||
super(CompleteEntry);
|
||||
}
|
||||
|
||||
@ -264,7 +261,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class CancelEntryAction extends TextAction {
|
||||
public CancelEntryAction() {
|
||||
CancelEntryAction() {
|
||||
super(CancelEntry);
|
||||
}
|
||||
|
||||
@ -276,7 +273,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class EscapeCharAction extends TextAction {
|
||||
public EscapeCharAction() {
|
||||
EscapeCharAction() {
|
||||
super(EscapeChar);
|
||||
}
|
||||
|
||||
@ -287,7 +284,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class DeletePreviousCharAction extends TextAction {
|
||||
public DeletePreviousCharAction() {
|
||||
DeletePreviousCharAction() {
|
||||
super(DeletePreviousChar);
|
||||
}
|
||||
|
||||
@ -335,7 +332,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class DeletePreviousWordAction extends TextAction {
|
||||
public DeletePreviousWordAction() {
|
||||
DeletePreviousWordAction() {
|
||||
super(DeletePreviousWord);
|
||||
}
|
||||
|
||||
@ -362,7 +359,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class DeleteToCursorAction extends TextAction {
|
||||
public DeleteToCursorAction() {
|
||||
DeleteToCursorAction() {
|
||||
super(DeleteToCursor);
|
||||
}
|
||||
|
||||
@ -385,7 +382,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class DeleteFromCursorAction extends TextAction {
|
||||
public DeleteFromCursorAction() {
|
||||
DeleteFromCursorAction() {
|
||||
super(DeleteFromCursor);
|
||||
}
|
||||
|
||||
@ -408,7 +405,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class ToggleInsertReplaceAction extends TextAction {
|
||||
public ToggleInsertReplaceAction() {
|
||||
ToggleInsertReplaceAction() {
|
||||
super(ToggleInsertReplace);
|
||||
|
||||
logger.debug("ToggleInsertReplaceAction()");
|
||||
@ -427,7 +424,7 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
public static class StartDigraphAction extends TextAction {
|
||||
@Nullable private DigraphSequence digraphSequence;
|
||||
|
||||
public StartDigraphAction() {
|
||||
StartDigraphAction() {
|
||||
super(StartDigraph);
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,8 @@ public class ExEntryPanel extends JPanel implements LafManagerListener {
|
||||
}
|
||||
};
|
||||
|
||||
new ExShortcutKeyAction(this).registerCustomShortcutSet();
|
||||
|
||||
LafManager.getInstance().addLafManagerListener(this);
|
||||
|
||||
updateUI();
|
||||
@ -280,7 +282,7 @@ public class ExEntryPanel extends JPanel implements LafManagerListener {
|
||||
|
||||
@NotNull private final DocumentListener documentListener = new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
protected void textChanged(@NotNull DocumentEvent e) {
|
||||
final Editor editor = entry.getEditor();
|
||||
final boolean forwards = !label.getText().equals("?");
|
||||
if (incHighlighter != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user