mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-02 09:59:07 +02:00
Refactored digraph handling in command line
This commit is contained in:
parent
c4927372ec
commit
7b6163c968
src/com/maddyhome/idea/vim/ui
@ -130,27 +130,32 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
new ExEditorKit.HistoryUpFilterAction(),
|
||||
new ExEditorKit.HistoryDownFilterAction(),
|
||||
new ExEditorKit.ToggleInsertReplaceAction(),
|
||||
new ExEditorKit.StartDigraphAction()
|
||||
new ExEditorKit.StartDigraphAction(),
|
||||
};
|
||||
|
||||
public static class DefaultExKeyHandler extends DefaultKeyTypedAction {
|
||||
public void actionPerformed(@NotNull ActionEvent e) {
|
||||
ExTextField target = (ExTextField)getTextComponent(e);
|
||||
KeyStroke key = convert(e);
|
||||
if (key != null) {
|
||||
char ch = target.checkKey(convert(e));
|
||||
if (ch > 0) {
|
||||
ActionEvent event = new ActionEvent(e.getSource(), e.getID(), "" + ch, e.getWhen(), e.getModifiers());
|
||||
super.actionPerformed(event);
|
||||
final Action currentAction = target.getCurrentAction();
|
||||
if (currentAction != null) {
|
||||
currentAction.actionPerformed(e);
|
||||
}
|
||||
else {
|
||||
KeyStroke key = convert(e);
|
||||
if (key != null) {
|
||||
final char c = key.getKeyChar();
|
||||
if (c > 0) {
|
||||
ActionEvent event = new ActionEvent(e.getSource(), e.getID(), "" + c, e.getWhen(), e.getModifiers());
|
||||
super.actionPerformed(event);
|
||||
target.saveLastEntry();
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.actionPerformed(e);
|
||||
|
||||
target.saveLastEntry();
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.actionPerformed(e);
|
||||
|
||||
target.saveLastEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,15 +396,36 @@ public class ExEditorKit extends DefaultEditorKit {
|
||||
}
|
||||
|
||||
public static class StartDigraphAction extends TextAction {
|
||||
@Nullable private DigraphSequence digraphSequence;
|
||||
|
||||
public StartDigraphAction() {
|
||||
super(StartDigraph);
|
||||
}
|
||||
|
||||
public void actionPerformed(@NotNull ActionEvent actionEvent) {
|
||||
ExTextField target = (ExTextField)getTextComponent(actionEvent);
|
||||
KeyStroke key = convert(actionEvent);
|
||||
if (key != null && DigraphSequence.isDigraphStart(key)) {
|
||||
target.startDigraph(convert(actionEvent));
|
||||
public void actionPerformed(@NotNull ActionEvent e) {
|
||||
final ExTextField target = (ExTextField)getTextComponent(e);
|
||||
final KeyStroke key = convert(e);
|
||||
if (key != null && digraphSequence != null) {
|
||||
DigraphSequence.DigraphResult res = digraphSequence.processKey(key, target.getEditor(), target.getContext());
|
||||
switch (res.getResult()) {
|
||||
case DigraphSequence.DigraphResult.RES_BAD:
|
||||
target.escape();
|
||||
target.handleKey(key);
|
||||
break;
|
||||
case DigraphSequence.DigraphResult.RES_DONE:
|
||||
final KeyStroke digraph = res.getStroke();
|
||||
digraphSequence = null;
|
||||
target.setCurrentAction(null);
|
||||
if (digraph != null) {
|
||||
target.handleKey(digraph);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (key != null && DigraphSequence.isDigraphStart(key)) {
|
||||
target.setCurrentAction(this);
|
||||
digraphSequence = new DigraphSequence();
|
||||
digraphSequence.processKey(key, target.getEditor(), target.getContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.group.CommandGroups;
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup;
|
||||
import com.maddyhome.idea.vim.helper.DigraphSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -233,41 +232,21 @@ public class ExTextField extends JTextField {
|
||||
}
|
||||
|
||||
public void escape() {
|
||||
if (digraph != null) {
|
||||
digraph = null;
|
||||
if (currentAction != null) {
|
||||
currentAction = null;
|
||||
}
|
||||
else {
|
||||
CommandGroups.getInstance().getProcess().cancelExEntry(editor, context);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDigraph(@NotNull KeyStroke key) {
|
||||
if (digraph == null) {
|
||||
digraph = new DigraphSequence();
|
||||
digraph.processKey(key, editor, context);
|
||||
}
|
||||
public void setCurrentAction(@Nullable Action action) {
|
||||
this.currentAction = action;
|
||||
}
|
||||
|
||||
public char checkKey(@NotNull KeyStroke key) {
|
||||
if (digraph != null) {
|
||||
DigraphSequence.DigraphResult res = digraph.processKey(key, editor, context);
|
||||
switch (res.getResult()) {
|
||||
case DigraphSequence.DigraphResult.RES_OK:
|
||||
return 0;
|
||||
case DigraphSequence.DigraphResult.RES_BAD:
|
||||
digraph = null;
|
||||
return 0;
|
||||
case DigraphSequence.DigraphResult.RES_DONE:
|
||||
key = res.getStroke();
|
||||
digraph = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
|
||||
return key.getKeyChar();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@Nullable
|
||||
public Action getCurrentAction() {
|
||||
return currentAction;
|
||||
}
|
||||
|
||||
public void toggleInsertReplace() {
|
||||
@ -411,7 +390,7 @@ public class ExTextField extends JTextField {
|
||||
private String lastEntry;
|
||||
private List<HistoryGroup.HistoryEntry> history;
|
||||
private int histIndex = 0;
|
||||
@Nullable private DigraphSequence digraph;
|
||||
@Nullable private Action currentAction;
|
||||
// TODO - support block cursor for overwrite mode
|
||||
//private Caret origCaret;
|
||||
//private Caret blockCaret;
|
||||
|
Loading…
Reference in New Issue
Block a user