Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip repeated key events when the slash menu is opening #978

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions lib/src/editor/selection_menu/selection_menu_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@

_scrollController?.scrollToIndex(
_selectedIndex,
duration: const Duration(milliseconds: 200),
preferPosition: AutoScrollPosition.begin,
preferPosition: AutoScrollPosition.middle,
);
}

Expand Down Expand Up @@ -465,6 +464,10 @@
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
AppFlowyEditorLog.keyboard.debug('slash command, on key $event');

if (event is KeyRepeatEvent) {

Check warning on line 467 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L467

Added line #L467 was not covered by tests
return KeyEventResult.skipRemainingHandlers;
}

if (event is! KeyDownEvent) {
return KeyEventResult.ignored;
}
Expand Down Expand Up @@ -506,18 +509,46 @@

var newSelectedIndex = _selectedIndex;
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
// When going left, wrap to the end of the previous row
newSelectedIndex -= widget.maxItemInRow;
if (newSelectedIndex < 0) {

Check warning on line 514 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L514

Added line #L514 was not covered by tests
// Calculate the last row's starting position
final lastRowStart = (_showingItems.length - 1) -
((_showingItems.length - 1) % widget.maxItemInRow);

Check warning on line 517 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L516-L517

Added lines #L516 - L517 were not covered by tests
// Move to the same column in the last row
newSelectedIndex =
lastRowStart + (_selectedIndex % widget.maxItemInRow);
if (newSelectedIndex >= _showingItems.length) {
newSelectedIndex = _showingItems.length - 1;

Check warning on line 522 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L520-L522

Added lines #L520 - L522 were not covered by tests
}
}
} else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
// When going right, wrap to the start of the next row
newSelectedIndex += widget.maxItemInRow;
if (newSelectedIndex >= _showingItems.length) {
newSelectedIndex = _selectedIndex % widget.maxItemInRow;
if (newSelectedIndex >= _showingItems.length) {
newSelectedIndex = _showingItems.length - 1;

Check warning on line 531 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L528-L531

Added lines #L528 - L531 were not covered by tests
}
}
} else if (event.logicalKey == LogicalKeyboardKey.arrowUp) {
newSelectedIndex -= 1;
if (newSelectedIndex > 0) {
newSelectedIndex -= 1;

Check warning on line 536 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L535-L536

Added lines #L535 - L536 were not covered by tests
} else {
// Wrap to the last item
newSelectedIndex = _showingItems.length - 1;

Check warning on line 539 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L539

Added line #L539 was not covered by tests
}
} else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
newSelectedIndex += 1;
if (newSelectedIndex < _showingItems.length - 1) {
newSelectedIndex += 1;

Check warning on line 543 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L542-L543

Added lines #L542 - L543 were not covered by tests
} else {
// Wrap to the first item
newSelectedIndex = 0;
}
} else if (event.logicalKey == LogicalKeyboardKey.tab) {
newSelectedIndex += widget.maxItemInRow;
var currRow = (newSelectedIndex) % widget.maxItemInRow;
newSelectedIndex += 1;

Check warning on line 549 in lib/src/editor/selection_menu/selection_menu_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/selection_menu/selection_menu_widget.dart#L549

Added line #L549 was not covered by tests
if (newSelectedIndex >= _showingItems.length) {
newSelectedIndex = (currRow + 1) % widget.maxItemInRow;
newSelectedIndex = 0;
}
}

Expand Down
Loading