Closed
Conversation
Cache maximum scroll range to prevent thumb resizing when items with different heights scroll in/out of view. This ensures the thumb maintains a consistent size throughout scrolling.
Cache maximum scroll range to prevent thumb resizing when items with different heights scroll in/out of view. This ensures the thumb maintains a consistent size throughout scrolling.
…7se7en72025/Anki-Android into fix/scrollbar-thumb-size-stable
Add logic to update cached maximum scroll range to maintain thumb size consistency.
Co-authored-by: Mike Hardy <github@mikehardy.net>
Fix the scrollbar thumb height calculation to prevent jittering during scroll. Changes: 1. Cache the maximum scroll range to prevent thumb size changes when items with different heights scroll in/out of view 2. Fix handle height calculation to use computeVerticalScrollExtent() instead of barHeight in the numerator. The correct formula is: (visibleExtent / totalRange) * trackHeight Previously used (barHeight / range) * barHeight which was mathematically incorrect and didn't properly represent the proportion of visible content. Fixes ankidroid#19224
…7se7en72025/Anki-Android into fix/scrollbar-thumb-size-stable
Fix the scrollbar thumb height calculation to prevent jittering during scroll. Changes: 1. Cache the maximum scroll range to prevent thumb size changes when items with different heights scroll in/out of view 2. Fix handle height calculation to use computeVerticalScrollExtent() instead of barHeight in the numerator. The correct formula is: (visibleExtent / totalRange) * trackHeight Previously used (barHeight / range) * barHeight which was mathematically incorrect and didn't properly represent the proportion of visible content. Fixes ankidroid#19224
Cache computeVerticalScrollExtent() and only update when RecyclerView is resized. The visible extent can vary during scroll, causing the thumb height to change and create jitter. Changes: - Add cachedVisibleExtent and lastRecyclerViewHeight variables - Only recalculate visible extent when RecyclerView height changes - Use cached visible extent for handle height calculation - Reset cache when adapter changes This prevents the thumb size from changing during scroll, eliminating the jitter issue.
Cache the calculated handle height and only update when there's a significant change (> 2px difference). This prevents small calculation fluctuations from causing jitter during scroll. Changes: - Add cachedHandleHeight and cachedBarHeight variables - Only update handle height if barHeight changed or difference > 2px - Use cached handle height to prevent jitter - Reset cache when adapter changes This provides additional stability on top of the visible extent caching.
- Wrap saveNoteType in undoableOp to track template edits in undo history - Make saveToDatabase a suspend function to support undoableOp - Remove TODO comment as the issue is now fixed This fixes the issue where after deleting a deck and editing a template, users couldn't undo the template editing operation. Now both operations are properly tracked in the undo history. Fixes: Template editing not being undoable after deck deletion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Description
This PR fixes an issue where editing card templates after deleting a deck would break the undo functionality. When users deleted a deck and then edited a template, they could no longer undo either operation. This happened because template editing operations were not wrapped in
undoableOp, so they weren't being tracked in the undo history.Fixes
Approach
The fix wraps the
saveNoteTypeoperation inundoableOpto ensure template editing changes are properly tracked in the undo history. Specifically:saveToDatabasea suspend function - This allows it to useundoableOpwhich is a suspend functionsaveNoteTypeinundoableOp- This ensures all template editing operations (adding/deleting templates, updating template content) are tracked in the undo historycolparameter - SinceundoableOpprovides the Collection context viawithCol, the parameter is no longer neededThe changes ensure that template editing operations are properly integrated with Anki's undo system, matching the behavior of other operations like deck deletion.
How Has This Been Tested?
Manual Testing Steps:
Test Configuration:
Expected Behavior:
Learning (optional, can help others)
undoableOpfunction is the standard way to wrap operations that should be undoable in AnkiDroidundoableOpinternally useswithColto provide Collection context, so operations don't need to manually pass the CollectionundoableOpto preserve undo historyundoableOpChecklist