Exemplo n.º 1
0
 /** 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));
   }
 }
Exemplo n.º 2
0
 @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()));
   }
 }
Exemplo n.º 3
0
 @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();
 }
Exemplo n.º 4
0
 @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();
 }
Exemplo n.º 5
0
 @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();
 }