/** Makes sure that the prompt characters don't get erased when selected. */
 protected void clipSelection() {
   if (commandLineText.getSelectionCount() > 0) {
     Point sel = commandLineText.getSelection();
     int leftOffset = Math.min(sel.x, sel.y);
     int rightOffset = Math.max(sel.x, sel.y);
     if (leftOffset < contentsOffset) {
       leftOffset = contentsOffset;
     }
     if (rightOffset < contentsOffset) {
       rightOffset = contentsOffset;
     }
     commandLineText.setSelection(new Point(leftOffset, rightOffset));
   }
 }
 @Inject
 @Optional
 public void setStyle(
     @UIEventTopic(RelationsConstants.TOPIC_STYLE_CHANGE_FORM) final Styles.StyleEvent inEvent) {
   if (textWidget == null) {
     return;
   }
   if (!(isFormStyle ^ inEvent.isFormStyle) && inEvent.style.isToggle()) {
     final TextStyler lStyler = new TextStyler(textWidget);
     lStyler.format(inEvent.style, inEvent.isFormatNew);
     final int lOffset = textWidget.getCaretOffset();
     notifyPositionChange(Math.max(lOffset, lOffset - textWidget.getSelectionCount()));
   }
 }
 @Override
 public void delete() {
   clipSelection();
   if (commandLineText.getSelectionCount() > 0) {
     commandLineText.insert("");
   } else {
     int startOffset = commandLineText.getCaretOffset();
     if (startOffset < commandLineText.getCharCount()) {
       commandLineText.replaceTextRange(startOffset, 1, "");
     }
   }
   // caret doesn't move if character after caret is deleted and won't trigger caretMoved
   // update manually
   updateCaret();
 }
 @Override
 public void erase() {
   clipSelection();
   if (commandLineText.getSelectionCount() > 0) {
     commandLineText.insert("");
   } else {
     int startOffset = commandLineText.getCaretOffset();
     if (startOffset > contentsOffset) {
       commandLineText.replaceTextRange(startOffset - 1, 1, "");
       // Caret listener is called before content is updated, update manually
       updateCaret();
     }
   }
   updateUISize();
 }
 @Override
 public void type(String characters) {
   clipSelection();
   setMode(CommandLineMode.DEFAULT);
   int start = commandLineText.getCaretOffset();
   // Check caret position after replacing selection - caret might have been at end of selection
   if (commandLineText.getSelectionCount() > 0) {
     Point selection = commandLineText.getSelection();
     start = Math.min(selection.x, selection.y);
   }
   commandLineText.insert(characters);
   commandLineText.setCaretOffset(start + characters.length());
   // Mouse selection might cause caret to be at the same position as before, update manually
   updateCaret();
   updateUISize();
 }