}
int linkIndex = hypertext.getContent().indexOf(linkToRemove);
// get prev. & succ. element
TextElement prevElement = null;
TextElement succElement = null;
if (linkIndex > 0) { // linkElement is not first
prevElement = hypertext.getContent().get(linkIndex - 1);
if (prevElement instanceof Link) {
prevElement = null;
}
} // else prevElement = null;
if (linkIndex < hypertext.getContent().size() - 1) {// linkElement is
// not last
succElement = hypertext.getContent().get(linkIndex + 1);
if (succElement instanceof Link) {
succElement = null;
}
} // else succElement = null;
if (prevElement == null && succElement == null) { // [Term] -> [Link]
Term newTerm = EMFfitModelFactory.eINSTANCE.createTerm();
newTerm.setVisibleContent(text);
hypertext.getContent().add(linkIndex, newTerm);
linkToRemove.delete();
} else if (prevElement == null) {// [Link,Term] -> [Term]
linkToRemove.delete();
succElement.setVisibleContent(text
+ succElement.getVisibleContent());
} else if (succElement == null) { // [Term, Link] -> [Term]
prevElement.setVisibleContent(prevElement.getVisibleContent()
+ text);
linkToRemove.delete();
} else { // [Term, Link, Term] -> [Term]
// [Term, Link, Term] -> [Term, Term]
prevElement.setVisibleContent(prevElement.getVisibleContent()
+ text);
linkToRemove.delete();
// [Term, Term] -> [Term]
prevElement.setVisibleContent(prevElement.getVisibleContent()
+ succElement.getVisibleContent());
succElement.delete();
}
}