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: off-by-one error in tree view caching logic #1330

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions lib/src/widgets/pgn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,15 @@ class _PgnTreeViewState extends State<_PgnTreeView> {
}

final mainlinePartOfCurrentPath = _mainlinePartOfCurrentPath();
final currentMoveIsOnMainline =
mainlinePartOfCurrentPath == widget.params.pathToCurrentMove;

final containsCurrentMove =
mainlinePartOfCurrentPath.size > mainlineInitialPath.size &&
mainlinePartOfCurrentPath.size <= path.size;
currentMoveIsOnMainline
? mainlinePartOfCurrentPath.size > mainlineInitialPath.size &&
mainlinePartOfCurrentPath.size <= path.size
: mainlinePartOfCurrentPath.size >= mainlineInitialPath.size &&
mainlinePartOfCurrentPath.size < path.size;

if (fullRebuild || subtrees[i].containsCurrentMove || containsCurrentMove) {
// Skip the first node which is the continuation of the mainline
Expand Down
28 changes: 28 additions & 0 deletions test/view/analysis/analysis_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ void main() {
// second mainline part has not changed since the current move is not part of it
expect(identical(secondMainlinePartOnMoveE5, secondMainlinePartOnMoveE4), isTrue);
});

testWidgets(
'Select first move of sideline if mainline part has only one move (regression test)',
(tester) async {
/// Will be rendered as:
/// -------------------
/// 1. e4
/// |- 1. d4
/// |- 1. c4
/// -------------------
await buildTree(tester, '1. e4 (1. d4) (1. c4)');

await tester.tap(find.text('1. d4'));
// need to wait for current move change debounce delay
await tester.pumpAndSettle(const Duration(milliseconds: 200));

final e4NodeBeforeTap = parentText(tester, '1. e4');

await tester.tap(find.text('1. c4'));
// need to wait for current move change debounce delay
await tester.pumpAndSettle(const Duration(milliseconds: 200));

final e4NodeAfterTap = parentText(tester, '1. e4');

// There was a bug where the subtree would not be rebuilt here
expect(e4NodeBeforeTap, isNot(e4NodeAfterTap));
},
);
});
}

Expand Down
Loading