private boolean insertFromCharacter(Chord chord, KeyPress keyPress, char character, boolean addIntermediate) {
chord.setComplete(true);
boolean multiple = mathCollection.isRangeSelectionSet();
if (character=='"' && multiple) {
RangeSelection range = (RangeSelection) getSelection();
Vector<Argument> roots = range.getSubbranchRoots();
String string = "";
for (Argument a : roots) {
Purpose p = getCurrent().getPurpose();
if (p instanceof Value) {
string += ((Value) p).getValue(); // i.e. unquoted
} else {
string += p.toString();
}
}
Token replacement = new Token(new Text(string));
if (range.areMultipleEquationsSelected()) {
// Remove all but one equation and replace it.
Vector<Equation> selectedEquations = range.getSelectedEquations();
range.setOnly(selectedEquations.firstElement().getRoot());
for (int i=1; i<selectedEquations.size(); i++) {
selectedEquations.get(i).removeEquation();
}
} else {
// Remove all but one roots and replace it with:
Vector<Argument> subbranchRoots = range.getSubbranchRoots();
range.setOnly(subbranchRoots.firstElement());
for (int i=1; i<subbranchRoots.size(); i++) {
subbranchRoots.get(i).remove();
}
}
getSelection().replace(replacement); // Now a cursor selection.