예제 #1
0
 @Override
 public void execute() {
   if (focus) {
     // Rich text area needs to be focused in order to have a proper selection or caret.
     rta.setFocus(true);
   }
   if (rta.getCommandManager().isEnabled(command)) {
     rta.getCommandManager().execute(command, parameter);
   }
 }
예제 #2
0
 /**
  * Moves the caret outside the passed anchor.
  *
  * @param rta the underlying rich text area
  * @param selectedAnchor the anchor to move the caret out of
  * @param atEnd {@code true} if the caret is at the end of the selected anchor, {@code false} if
  *     it's at the beginning.
  */
 private void moveCaretOuside(RichTextArea rta, Element selectedAnchor, boolean atEnd) {
   Range newRange = rta.getDocument().createRange();
   if (atEnd) {
     newRange.setStartAfter(selectedAnchor);
   } else {
     newRange.setStartBefore(selectedAnchor);
   }
   newRange.collapse(true);
   // now set it on the document
   rta.getDocument().getSelection().removeAllRanges();
   rta.getDocument().getSelection().addRange(newRange);
 }
예제 #3
0
 /**
  * Overwrites the default rich text area behavior when the user releases the mouse button.
  *
  * @param event the native event that was fired
  */
 protected void onBeforeMouseUp(Event event) {
   // The height of the body element is given by its content. When the height of the body element
   // is less than the
   // rich text area height the user can click outside of the body element, on the HTML element.
   // When this happens
   // the selection can be lost. To prevent this we give the focus back to the body element.
   if (Element.is(event.getEventTarget())
       && "html".equalsIgnoreCase(Element.as(event.getEventTarget()).getTagName())) {
     textArea.setFocus(true);
   }
 }