// Replace current?
private void moveRelative(KeyPress keyPress) {
char character = keyPress.getChar();
Ket.out.println(" --- move relative ("+character+") --- ");
Argument current = getSelection().getCurrent();
Selection s = getSelection();
Cursor c = s.getCursor();
Argument replacement = document.parseArgument(getLine());
boolean ok;
switch (character) {
case 'i': // TODO: Merge with appendNewSibling().
ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
if (!ok) return;
if (replacement!=null) {
s.replace(replacement);
}
if (relative==RELATIVE_EDIT) {
s.prependNewChild();
} else {
c.selectInOrOutLeft();
setMessage(current.toString());
}
break;
case 'o': // TODO: Merge with prependNewSibling().
ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
if (!ok) return;
if (replacement!=null) {
s.replace(replacement);
}
if (relative==RELATIVE_EDIT) {
s.appendNewChild();
} else {
c.selectInOrOutRight();
setMessage(current.toString());
}
break;
case 'h':
if (replacement!=null) {
s.replace(replacement);
}
if (relative==RELATIVE_EDIT) {
s.prependNewSibling();
} else {
c.selectLeft();
setMessage(current.toString());
}
break;
case 'l':
if (replacement!=null) {
s.replace(replacement);
}
if (relative==RELATIVE_EDIT) {
s.appendNewSibling();
} else {
c.selectRight();
setMessage(current.toString());
}
break;
case 'e':
case 'j':
case 'k':
boolean prepend = (character=='k');
insertEquation(prepend);
break;
case ' ':
if (replacement!=null) {
s.replace(replacement);
}
if (relative==RELATIVE_EDIT) {
document.getModes().setDocumentState(DocumentState.APPEND_PURPOSE);
s.addNewIntermediaryParent();
} else {
document.getModes().setDocumentState(DocumentState.APPEND_PURPOSE);
c.selectParent();
setMessage(getSelection().getCurrent().getPurpose().getName());
}
softReset();
// Note: Don't clear the message!
return;
default:
// TODO: If you are only moving then approach this command as 'f*' or 'F+'.
Function knownFunction = knownArguments.getFunctionByChar(character);
if (replacement!=null) {
s.replace(replacement);
}
s.addIntermediaryParent(knownFunction);
s.appendNewChild();
}
clear();
softReset();
}