Skip to content

Commit

Permalink
AutopairWidgets: now restores defaultBindings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Oct 5, 2019
1 parent 20076f2 commit 4abce45
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions builtins/src/main/java/org/jline/builtins/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static class AutopairWidgets {
private static final Map<String,String> LBOUNDS;
private static final Map<String,String> RBOUNDS;
private final Map<String,String> pairs;
private final Map<String,Binding> defaultBindings = new HashMap<>();
private final LineReaderImpl reader;
private boolean autopair = false;
{
Expand Down Expand Up @@ -92,6 +93,15 @@ public AutopairWidgets(LineReader reader, boolean addCurlyBrackets) {
addWidget(reader.getWidgets(), "autopair-insert", this::autopairInsert);
addWidget(reader.getWidgets(), "autopair-close", this::autopairClose);
addWidget(reader.getWidgets(), "autopair-delete", this::autopairDelete);

KeyMap<Binding> map = reader.getKeyMaps().get(LineReader.MAIN);
for (Map.Entry<String, String> p: pairs.entrySet()) {
defaultBindings.put(p.getKey(), map.getBound(p.getKey()));
if (!p.getKey().equals(p.getValue())) {
defaultBindings.put(p.getValue(), map.getBound(p.getValue()));
}
}
defaultBindings.put(del(), map.getBound(del()));
}

/*
Expand Down Expand Up @@ -167,12 +177,12 @@ private void defaultBindings() {
}
KeyMap<Binding> map = reader.getKeyMaps().get(LineReader.MAIN);
for (Map.Entry<String, String> p: pairs.entrySet()) {
map.bind(new Reference(LineReader.SELF_INSERT), p.getKey());
if (p.getKey().equals(p.getValue())) {
map.bind(new Reference(LineReader.SELF_INSERT), p.getValue());
map.bind(defaultBindings.get(p.getKey()), p.getKey());
if (!p.getKey().equals(p.getValue())) {
map.bind(defaultBindings.get(p.getValue()), p.getValue());
}
}
map.bind(new Reference(LineReader.BACKWARD_DELETE_CHAR), del());
map.bind(defaultBindings.get(del()), del());
autopair = false;
}
/*
Expand Down

0 comments on commit 4abce45

Please sign in to comment.