Ejemplo n.º 1
0
    public void checkCursorKeys(KeyDownEvent e) {

      String text = autoCompleteTextField.getText(); // ?// (String)
      // delegate.getCellEditorValue();

      int keyCode = e.getNativeKeyCode();
      // Application.debug(e+"");
      switch (keyCode) {
        case KeyCodes.KEY_UP:
          if (isSuggesting()) {
            return;
          }
          if (isFormulaBarListener) return;

          // Application.debug("UP");
          stopCellEditing(0, -1, false);
          // ?//e.consume();
          tabReturnCol = -1;
          break;

        case KeyCodes.KEY_TAB:
          if (isFormulaBarListener) return;
          App.debug(" tab");
          // Application.debug("RIGHT");
          // shift-tab moves left
          // tab moves right
          if (tabReturnCol == -1) tabReturnCol = column;
          stopCellEditing(e.isShiftKeyDown() ? -1 : 1, 0, false);
          e.preventDefault();
          break;

        case KeyCodes.KEY_ENTER:
          if (isSuggesting()) {
            return;
          }

          // if incomplete command entered, want to move the cursor to
          // between []
          int bracketsIndex = text.indexOf("[]");
          if (bracketsIndex == -1) {

            if (tabReturnCol != -1) {
              int colOffset = tabReturnCol - column;
              stopCellEditing(colOffset, 1, true);
            } else {

              // TODO: in desktop this works with column, row + 1
              String cellBelowStr = GeoElementSpreadsheet.getSpreadsheetCellName(column, row + 1);
              GeoElement cellBelow = kernel.getConstruction().lookupLabel(cellBelowStr);

              boolean moveDown = cellBelow == null || !cellBelow.isFixed();

              // don't move down to cell below after <Enter> if it's
              // fixed
              stopCellEditing(0, moveDown ? 1 : 0, moveDown);
            }
          } else {
            autoCompleteTextField.setCaretPosition(bracketsIndex + 1);
            // ?//e.consume();
          }

          tabReturnCol = -1;
          break;

        case KeyCodes.KEY_DOWN:
          if (isSuggesting()) {
            return;
          }

          if (isFormulaBarListener) {
            // ?//e.consume();
            return;
          }
          // Application.debug("DOWN");
          stopCellEditing(0, 1, false);
          tabReturnCol = -1;
          break;

        case KeyCodes.KEY_LEFT:
          if (isFormulaBarListener) return;
          // Application.debug("LEFT");
          // Allow left/right keys to exit cell for easier data entry
          if (getCaretPosition() == 0) {
            stopCellEditing(-1, 0, false);
          }
          tabReturnCol = -1;
          break;

        case KeyCodes.KEY_RIGHT:
          if (isFormulaBarListener) return;
          // Application.debug("RIGHT");
          // Allow left/right keys to exit cell for easier data entry
          if (getCaretPosition() == text.length()) {
            stopCellEditing(1, 0, false);
          }

          tabReturnCol = -1;
          break;

        case KeyCodes.KEY_PAGEDOWN:
        case KeyCodes.KEY_PAGEUP:
          e.preventDefault();
          // ?//e.consume();
          tabReturnCol = -1;
          break;

          // An F1 keypress causes the focus to be lost, so we
          // need to set 'editing' to false to prevent the focusLost()
          // method from calling stopCellEditing()
          // ?//case KeyEvent.VK_F1:
          // ?// editing = false;
          // ?// break;

      }
    }