handleShortcut method

Future<void> handleShortcut(
  1. InputShortcut? shortcut
)
inherited

Implementation

Future<void> handleShortcut(InputShortcut? shortcut) async {
  // final selection = widget.controller.selection;
  final plainText = textEditingValue.text;
  // assert(selection != null);
  if (shortcut == InputShortcut.copy) {
    clipboardController.copy(widget.controller, plainText);
    return;
  }
  if (shortcut == InputShortcut.cut && !widget.readOnly) {
    final updatedEditingValue =
        clipboardController.cut(widget.controller, plainText);
    if (updatedEditingValue != null) {
      textEditingValue = updatedEditingValue;
    }
    return;
  }
  if (shortcut == InputShortcut.paste && !widget.readOnly) {
    // Snapshot the input before using `await`.
    // See https://github.com/flutter/flutter/issues/11427
    clipboardController.paste(widget.controller, textEditingValue);
    return;
  }
  if (shortcut == InputShortcut.selectAll &&
      widget.enableInteractiveSelection) {
    final newSelection = widget.controller.selection.copyWith(
      baseOffset: 0,
      extentOffset: textEditingValue.text.length,
    );
    widget.controller.updateSelection(newSelection);
    return;
  }
}