-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Bugfix/18670 cursor position retention #18759
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
Bugfix/18670 cursor position retention #18759
Conversation
This commit refactors the `CardTemplateEditor` to remove the `cursorPosition` argument from `CardTemplateFragment.newInstance`. The `cursorPosition` is now directly retrieved from the `tabToCursorPosition` map within the `CardTemplateFragment` when setting the editor view. This simplifies the fragment's initialization and makes the cursor position handling more localized. Additionally, a check is added in `afterTextChanged` to ensure `tabToCursorPosition` is only updated if the selection start is not 0, preventing incorrect cursor position updates in certain scenarios.
This change modifies how cursor positions are stored in the Card Template Editor. Previously, only one cursor position was saved per card template. Now, the cursor position is saved independently for each editor window (front, style, back) within each card template. This ensures that when switching between editor windows or card templates, the cursor remains in its last known position for that specific window and template combination.
When a new card template tab is created in the CardTemplateEditor, ensure the `tabToCursorPosition` map, which stores cursor positions for each editor window within that tab, is initialized.
The variable `tabToCursorPosition` stores a map of tab indices to a map of editor view IDs to cursor positions. Renaming it to `tabToCursorPositions` (plural) better reflects that it holds multiple cursor positions for each tab, one for each editor window (front, style, back) within that tab.
The `setCurrentEditorView` method now requires a `cardId` parameter. This commit updates the test cases to pass a default `cardId` of 0 when calling this method.
The cursor position was not being saved correctly when switching between editor views (Front, Back, Styling). This commit ensures that the cursor position is saved before changing the editor view and restored when switching back. The previous logic that saved the cursor position whenever the text changed did not account for just the cursor position change and one had to change the text to trigger a save of cursor position.
Closed the last PR due to some missed updates. This one contains the complete and corrected changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, cheers!
* The inner HashMap's key is the editor window ID (e.g., R.id.front_edit). | ||
* The value is the cursor position within that editor window. | ||
*/ | ||
private var tabToCursorPositions: HashMap<Int, HashMap<Int, Int>> = HashMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more readable if you made private typealiases for the Ints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good to me, thanks!
noting squash merge intention for maintainers
This doesn't cherry-pick cleanly and I'd prefer not to hand-hack the diff for a non-crash fix |
Purpose / Description
Fixes
Approach
In the card template editor when switching from front to back to css. The cursor position was not retained, this was due to faulty cursor position updation. This issue was solved by saving the cursor position when the editor view was changed and not when the text was changed. Also only a single cursor position was stored per card, which is not enough for all the three views i.e. front, back and css. This was taken care of by storing a HashMap<Int, Int> for every card instead of a card.
How Has This Been Tested?
On an Android 15 phone
Checklist