Java Code Examples for com.google.gwt.event.dom.client.KeyCodes#KEY_DELETE

The following examples show how to use com.google.gwt.event.dom.client.KeyCodes#KEY_DELETE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YoungAndroidPalettePanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  switch (event.getCharCode()) {
    case KeyCodes.KEY_END:
    case KeyCodes.KEY_DELETE:
    case KeyCodes.KEY_BACKSPACE:
      doSearch();
      break;
  }
}
 
Example 2
Source File: EditorEventHandler.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Parameterised to allow testing different browser/os permuations
 * @param event
 * @param isMac
 * @param quirksHasOldSchoolClipboardShortcuts
 */
@VisibleForTesting
static boolean isAcceleratorInner(SignalEvent event, boolean isMac,
    boolean quirksHasOldSchoolClipboardShortcuts) {
  switch (event.getKeySignalType()) {
    case INPUT:
      // Alt on its own is a simple modifier, like shift, on OSX
      boolean maybeAltKey = !isMac && event.getAltKey();

      // NOTE(user): Perhaps we should create a registry in
      // EditorEventSubHandler of non-metesque like command keys such as TAB.
      // For now TAB is our only special case, but we may need to allow
      // implementers to define arbitrary keys as accelerators.
      return event.getCtrlKey() || event.getMetaKey() || event.getKeyCode() == KeyCodes.KEY_TAB
          || maybeAltKey;
    case DELETE:
      if (quirksHasOldSchoolClipboardShortcuts &&
          event.getKeyCode() == KeyCodes.KEY_DELETE && KeyModifier.SHIFT.check(event)) {

        // shift+delete on windows/linux is cut
        // (shift+insert and ctrl+insert are other clipboard alternatives,
        // but that's handled below).

        return true;
      } else {
        return false;
      }
    case NAVIGATION:
      // All navigation does not count
      return false;
    case NOEFFECT:
      // Random special keys like ESC, F7, TAB, INS, etc count
      return true;
  }
  throw new RuntimeException("Unknown KeySignal type");
}
 
Example 3
Source File: EditorEventHandler.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Parameterised to allow testing different browser/os permuations
 * @param event
 * @param isMac
 * @param quirksHasOldSchoolClipboardShortcuts
 */
@VisibleForTesting
static boolean isAcceleratorInner(SignalEvent event, boolean isMac,
    boolean quirksHasOldSchoolClipboardShortcuts) {
  switch (event.getKeySignalType()) {
    case INPUT:
      // Alt on its own is a simple modifier, like shift, on OSX
      boolean maybeAltKey = !isMac && event.getAltKey();

      // NOTE(user): Perhaps we should create a registry in
      // EditorEventSubHandler of non-metesque like command keys such as TAB.
      // For now TAB is our only special case, but we may need to allow
      // implementers to define arbitrary keys as accelerators.
      return event.getCtrlKey() || event.getMetaKey() || event.getKeyCode() == KeyCodes.KEY_TAB
          || maybeAltKey;
    case DELETE:
      if (quirksHasOldSchoolClipboardShortcuts &&
          event.getKeyCode() == KeyCodes.KEY_DELETE && KeyModifier.SHIFT.check(event)) {

        // shift+delete on windows/linux is cut
        // (shift+insert and ctrl+insert are other clipboard alternatives,
        // but that's handled below).

        return true;
      } else {
        return false;
      }
    case NAVIGATION:
      // All navigation does not count
      return false;
    case NOEFFECT:
      // Random special keys like ESC, F7, TAB, INS, etc count
      return true;
  }
  throw new RuntimeException("Unknown KeySignal type");
}
 
Example 4
Source File: EditorEventHandler.java    From swellrt with Apache License 2.0 4 votes vote down vote up
private boolean handleInputOrDeleteKeyEvent(EditorEvent event, KeySignalType keySignalType)
    throws SelectionLostException {
  // !!!!!!!!!
  // TODO(danilatos): This caret is in the wrong (full) view, and can die when
  // applied to mutable doc!!!! Only OK right now out of sheer luck.
  // !!!!!!!!!
  Point<ContentNode> caret;

  boolean isCollapsed = editorInteractor.getHtmlSelection() != null &&
      editorInteractor.getHtmlSelection().isCollapsed();
  boolean isReplace = false;

  if (isCollapsed) {
    MoveUnit moveUnit = event.getMoveUnit();
    if (moveUnit != MoveUnit.CHARACTER) {
      if (event.getMoveUnit() == MoveUnit.WORD) {
        if (event.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
          refreshEditorWithCaret(event);
          caret = cachedSelection.getFocus();
          editorInteractor.deleteWordEndingAt(caret);
        } else if (event.getKeyCode() == KeyCodes.KEY_DELETE){
          refreshEditorWithCaret(event);
          caret = cachedSelection.getFocus();
          editorInteractor.deleteWordStartingAt(caret);
        }
      }
      // TODO(user): Manually handle line/other etc. deletes, because
      // they might contain formatting, etc. For now, cancelling for safety.
      return true;
    } else {
      // HACK(danilatos/patcoleman): We don't want the caret to get set here,
      // because it is not safe unless we continually flush the typing extractor
      // which is undesirable.
      // NOTE #XYZ (this comment referenced from elsewhere)
      // To fix this properly, we need to restructure the control flow, and
      // possibly change the types of caret we pass around.
      caret = null;
    }

  } else {
    refreshEditorWithCaret(event);

    // NOTE: at this point, should be either INPUT or DELETE
    boolean isDelete = (keySignalType == KeySignalType.DELETE);

    if (event.isImeKeyEvent()) {
      // Semi-HACK(danilatos): sometimes during composition, the selection will be reported
      // as a range. We want to leave this alone, not delete it. Since we're not handling
      // ranged deletions with non-FF ime input properly anyway, this will do.
      caret = cachedSelection.getFocus();
    } else {
      caret = deleteCachedSelectionRangeAndInvalidate(!isDelete); // keep annotations on insert
    }

    if (isDelete) {
      return true; // Did a range delete already. Do not go on to typing extractor.
    } else {
      isReplace = true;
    }
  }

  if (keySignalType == KeySignalType.DELETE) {
    refreshEditorWithCaret(event);
    caret = cachedSelection.getFocus();
    ContentNode node = caret.getContainer();

    editorInteractor.checkpoint(new FocusedContentRange(caret));

    switch (EventWrapper.getKeyCombo(event)) {
      case BACKSPACE:
      case SHIFT_BACKSPACE:
        editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
        return router.handleBackspace(node, event);
      case SHIFT_DELETE:
        if (!QuirksConstants.HAS_OLD_SCHOOL_CLIPBOARD_SHORTCUTS) {
          // On a mac, shift+delete is the same as regular delete.
          editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
          return router.handleDelete(node, event);
        } else {
          // On windows & linux, shift+delete is cut
          // It should have been caught earlier by the isAccelerator check
          throw new RuntimeException("Shift delete should have been caught"
              + "as an accelerator event!");
        }
      case DELETE:
        editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
        return router.handleDelete(node, event);
    }
  } else if (handleEventsManuallyOnNode(event, caret)){
    return true;
  }

  return handleNormalTyping(event, caret, isReplace);
}
 
Example 5
Source File: MaskValueBoxHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void onKeyDown(KeyDownEvent event) {
	this.keyDown = event.getNativeKeyCode();
	boolean preventDefault = false;
	switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_DELETE:
		case KeyCodes.KEY_BACKSPACE:
			if (this.token != null) {
				this.reset();
				this.maskHelper.refreshValueBox();
				event.preventDefault();
			}
			break;
		case KeyCodes.KEY_DOWN:
		case KeyCodes.KEY_UP:
			event.preventDefault();
			break;
		case KeyCodes.KEY_LEFT:
			preventDefault = this.maskHelper.focusPrevious();
			break;
		case KeyCodes.KEY_RIGHT:
			preventDefault = this.maskHelper.focusNext();

			break;
		case KeyCodes.KEY_TAB:
			if (event.isShiftKeyDown()) {
				preventDefault = this.maskHelper.focusPrevious();
			} else {
				preventDefault = this.maskHelper.focusNext();
			}
			break;
		default:
			break;
	}

	if (preventDefault) {
		event.preventDefault();
	}
	if (this.handleKeyDown(this.keyDown)) {
		this.maskHelper.refreshValueBox();
		this.schedule(this.maskHelper.initialDelayMilis);
	}
}
 
Example 6
Source File: EditorEventHandler.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
private boolean handleInputOrDeleteKeyEvent(EditorEvent event, KeySignalType keySignalType)
    throws SelectionLostException {
  // !!!!!!!!!
  // TODO(danilatos): This caret is in the wrong (full) view, and can die when
  // applied to mutable doc!!!! Only OK right now out of sheer luck.
  // !!!!!!!!!
  Point<ContentNode> caret;

  boolean isCollapsed = editorInteractor.getHtmlSelection() != null &&
      editorInteractor.getHtmlSelection().isCollapsed();
  boolean isReplace = false;

  if (isCollapsed) {
    MoveUnit moveUnit = event.getMoveUnit();
    if (moveUnit != MoveUnit.CHARACTER) {
      if (event.getMoveUnit() == MoveUnit.WORD) {
        if (event.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
          refreshEditorWithCaret(event);
          caret = cachedSelection.getFocus();
          editorInteractor.deleteWordEndingAt(caret);
        } else if (event.getKeyCode() == KeyCodes.KEY_DELETE){
          refreshEditorWithCaret(event);
          caret = cachedSelection.getFocus();
          editorInteractor.deleteWordStartingAt(caret);
        }
      }
      // TODO(user): Manually handle line/other etc. deletes, because
      // they might contain formatting, etc. For now, cancelling for safety.
      return true;
    } else {
      // HACK(danilatos/patcoleman): We don't want the caret to get set here,
      // because it is not safe unless we continually flush the typing extractor
      // which is undesirable.
      // NOTE #XYZ (this comment referenced from elsewhere)
      // To fix this properly, we need to restructure the control flow, and
      // possibly change the types of caret we pass around.
      caret = null;
    }

  } else {
    refreshEditorWithCaret(event);

    // NOTE: at this point, should be either INPUT or DELETE
    boolean isDelete = (keySignalType == KeySignalType.DELETE);

    if (event.isImeKeyEvent()) {
      // Semi-HACK(danilatos): sometimes during composition, the selection will be reported
      // as a range. We want to leave this alone, not delete it. Since we're not handling
      // ranged deletions with non-FF ime input properly anyway, this will do.
      caret = cachedSelection.getFocus();
    } else {
      caret = deleteCachedSelectionRangeAndInvalidate(!isDelete); // keep annotations on insert
    }

    if (isDelete) {
      return true; // Did a range delete already. Do not go on to typing extractor.
    } else {
      isReplace = true;
    }
  }

  if (keySignalType == KeySignalType.DELETE) {
    refreshEditorWithCaret(event);
    caret = cachedSelection.getFocus();
    ContentNode node = caret.getContainer();

    editorInteractor.checkpoint(new FocusedContentRange(caret));

    switch (EventWrapper.getKeyCombo(event)) {
      case BACKSPACE:
      case SHIFT_BACKSPACE:
        editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
        return router.handleBackspace(node, event);
      case SHIFT_DELETE:
        if (!QuirksConstants.HAS_OLD_SCHOOL_CLIPBOARD_SHORTCUTS) {
          // On a mac, shift+delete is the same as regular delete.
          editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
          return router.handleDelete(node, event);
        } else {
          // On windows & linux, shift+delete is cut
          // It should have been caught earlier by the isAccelerator check
          throw new RuntimeException("Shift delete should have been caught"
              + "as an accelerator event!");
        }
      case DELETE:
        editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
        return router.handleDelete(node, event);
    }
  } else if (handleEventsManuallyOnNode(event, caret)){
    return true;
  }

  return handleNormalTyping(event, caret, isReplace);
}