Exemplo n.º 1
0
 /**
  * @param container A block level element containing the start of the given range.
  * @param range A DOM range.
  * @return true if the start of the given range is at the beginning of its block level container.
  */
 protected boolean isAtStart(Node container, Range range) {
   if (!container.hasChildNodes()) {
     return true;
   }
   if (range.getStartOffset() > 0) {
     return false;
   }
   return domUtils.getFirstLeaf(container) == domUtils.getFirstLeaf(range.getStartContainer());
 }
Exemplo n.º 2
0
  /**
   * Tab key has been pressed inside a table cell.
   *
   * @param event the native event that was fired
   * @param cell The table cell in which the tab key has been pressed.
   */
  protected void onTabInTableCell(Event event, TableCellElement cell) {
    Node nextCell = event.getShiftKey() ? cell.getPreviousCell() : cell.getNextCell();
    if (nextCell == null) {
      if (event.getShiftKey()) {
        return;
      } else {
        getTextArea().getCommandManager().execute(new Command("insertrowafter"));
        nextCell = cell.getNextCell();
      }
    }

    Selection selection = getTextArea().getDocument().getSelection();
    Range range = selection.getRangeAt(0);

    // Place the caret at the beginning of the next cell.
    Node leaf = domUtils.getFirstLeaf(nextCell);
    if (leaf == nextCell || leaf.getNodeType() == Node.TEXT_NODE) {
      range.setStart(leaf, 0);
    } else {
      range.setStartBefore(leaf);
    }

    range.collapse(true);
    selection.removeAllRanges();
    selection.addRange(range);
  }