combineAll method
Future<bool>
combineAll({
- String text = "",
- List<
LogicalKeyboardKey> ? keysToCloseUp, - int cursorPosition = 0,
combineAll combines all the key events in the record that can be combined. Returns true if "this" event would combine previous one and thus the previous one can be deleted.
Implementation
Future<bool> combineAll(
{String text = "",
List<LogicalKeyboardKey>? keysToCloseUp,
int cursorPosition = 0}) async {
FlutsterTestEvent? next = (await getRecord())?.findNextEvent(this);
if (type != FlutsterTestEventType.key ||
isStopKey() ||
(LogicalKeyboardKey.isControlCharacter(keyEventKeyLabel ?? "") &&
keyEvent!.logicalKey != LogicalKeyboardKey.backspace)) {
next?.combineAll(
keysToCloseUp: keysToCloseUp,
);
return (false);
}
keysToCloseUp ??= [];
if (keyEvent?.logicalKey != null) {
if (keyEventDown ?? true) {
if (isCharacterAZ()) {
if (keysToCloseUp.contains(LogicalKeyboardKey.shift) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftLeft) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftLevel5) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftRight)) {
text = text.replaceRange(cursorPosition, cursorPosition,
characterCharacter().toUpperCase());
typedText = text;
} else {
text = text.replaceRange(
cursorPosition, cursorPosition, characterCharacter());
typedText = text;
}
cursorPosition++;
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.arrowLeft ||
keyLabel == "Arrow Left") {
cursorPosition--;
if (cursorPosition < 0) {
cursorPosition = 0;
}
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.arrowRight ||
keyLabel == "Arrow Right") {
cursorPosition++;
if (cursorPosition > text.length) {
cursorPosition = text.length;
}
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.end ||
keyLabel == "End") {
cursorPosition = text.length;
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.home ||
keyLabel == "Home") {
cursorPosition = 0;
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.backspace ||
keyLabel == "Backspace") {
if (cursorPosition > 0) {
text = text.replaceRange(cursorPosition - 1, cursorPosition, "");
cursorPosition--;
}
} else if (keyEvent!.logicalKey == LogicalKeyboardKey.delete ||
keyLabel == "Delete") {
if (cursorPosition < text.length) {
text = text.replaceRange(cursorPosition, cursorPosition + 1, "");
// typedText=text;
}
} else if (isAZ()) {
if (keysToCloseUp.contains(LogicalKeyboardKey.shift) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftLeft) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftLevel5) ||
keysToCloseUp.contains(LogicalKeyboardKey.shiftRight)) {
text = text.replaceRange(
cursorPosition, cursorPosition, character().toUpperCase());
} else {
text =
text.replaceRange(cursorPosition, cursorPosition, character());
}
cursorPosition++;
} else {
if (!keyToSwallow()) {
next?.combineAll(
keysToCloseUp: keysToCloseUp,
);
return (false);
}
}
if (keyEventDown != null) {
keysToCloseUp.add(keyEvent!.logicalKey);
}
} else {
if (keysToCloseUp.isNotEmpty) {
keysToCloseUp
.removeWhere((element) => element == keyEvent!.logicalKey);
}
}
}
next = (await getRecord())?.findNextEvent(this);
FlutsterTestEvent? previous = (await getRecord())?.findPreviousEvent(this);
if (previous?.type != FlutsterTestEventType.key ||
(previous?.isStopKey() ?? false)) {
previous = null;
} else {
waitDuration = Duration(
milliseconds: waitDuration!.inMilliseconds +
(previous?.waitDuration?.inMilliseconds ?? 0));
}
if (await next?.combineAll(
text: text,
keysToCloseUp: keysToCloseUp,
cursorPosition: cursorPosition,
) ??
false) {
(await getRecord())?.deleteEvent(this);
}
if (text.isNotEmpty && (typedText?.isEmpty ?? true)) {
typedText = text;
}
return (true);
}