deleteWordWithAltBksp function

ExecutionInstruction deleteWordWithAltBksp({
  1. required EditContext editContext,
  2. required KeyEvent keyEvent,
})

Implementation

ExecutionInstruction deleteWordWithAltBksp({
  required EditContext editContext,
  required KeyEvent keyEvent,
}) {
  if (keyEvent is! KeyDownEvent && keyEvent is! KeyRepeatEvent) {
    return ExecutionInstruction.continueExecution;
  }

  if (!HardwareKeyboard.instance.isAltPressed || keyEvent.logicalKey != LogicalKeyboardKey.backspace) {
    return ExecutionInstruction.continueExecution;
  }
  if (editContext.composer.selection == null) {
    return ExecutionInstruction.continueExecution;
  }

  bool didMove = false;

  didMove = editContext.commonOps.moveCaretUpstream(
    expand: true,
    movementModifier: MovementModifier.word,
  );

  if (didMove) {
    return editContext.commonOps.deleteSelection()
        ? ExecutionInstruction.haltExecution
        : ExecutionInstruction.continueExecution;
  }
  return ExecutionInstruction.continueExecution;
}