Skip to content

Feature: Undo function#18834

Closed
GuilhermeD9 wants to merge 6 commits intoankidroid:mainfrom
GuilhermeD9:feature-undo-function
Closed

Feature: Undo function#18834
GuilhermeD9 wants to merge 6 commits intoankidroid:mainfrom
GuilhermeD9:feature-undo-function

Conversation

@GuilhermeD9
Copy link

Purpose / Description

Adding an undo feature is a standard quality-of-life improvement for any text editor. While it particularly helps on devices where handwriting recognition or pen input might lead to accidental changes, it universally benefits users who make typing mistakes, paste incorrectly, or wish to revert formatting.

This change aims to enhance the text editing experience within the Note Editor by providing an easy way to undo recent modifications to fields.

Approach

This feature is implemented by introducing a new "Undo" button to the Note Editor toolbar. The technical approach involves:

  • Implementing a multi-level undo stack for each individual text field (Front, Back, and custom fields).
  • Utilizing a TextWatcher with a debounce mechanism to consolidate rapid typing or multiple small changes into a single, undoable action, providing a smoother undo experience similar to desktop text editors.
  • Ensuring the undo operation is field-specific, meaning an undo in the "Back" field will not affect the "Front" field.

How Has This Been Tested?

I performed extensive manual testing on two physical Android devices:

  • A Xiaomi Poco F3 (Android 13)
  • A Samsung tablet (Android 12)

Testing Steps:

  1. Opened the Note Editor (both for adding new notes and editing existing ones).
  2. Typed text incrementally in both "Front" and "Back" fields.
  3. Copied and pasted large blocks of text.
  4. Applied various text formatting (e.g., bold, italics) using the toolbar buttons.
  5. Switched focus between "Front" and "Back" fields multiple times.
  6. Repeatedly used the "Undo" button on both fields, verifying that:
    • It correctly reverted the last consolidated action (e.g., an entire typed word/sentence, not just a single character).
    • It allowed multiple levels of undo for each field independently.
    • It correctly reverted formatting actions.
    • No crashes occurred during the process.

The undo functionality worked satisfactorily on both devices and for all tested scenarios.

Automated Tests:
Automated tests were run (connectedPlayDebugAndroidTest). The report at file:///home/guilherme/coding/mobile/Anki-Android/AnkiDroid/build/reports/androidTests/connected/debug/flavors/play/index.html shows 15 failing tests. I am aware of these failures and will analyze them further, but I believe they are outside the scope of this feature's direct implementation and are likely regressions that need to be addressed separately.

Screenshots

Screenshot of the Note Editor toolbar with the new Undo button:


Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@welcome
Copy link

welcome bot commented Jul 10, 2025

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

@github-actions
Copy link
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

@david-allison
Copy link
Member

Thanks so much for the enthusiasm/PR! In future, could you chat in Discord before taking on a new feature which doesn't have an accepted issue

  • We're going to be retiring this screen soon, additional features will make this more difficult
  • Undo on the text level is hard to get right. In the current implementation
    • Sometimes, only a character is undone
    • Sometimes, nothing is undone
  • Anki already has an undo mechanism, and we need to be sure this doesn't conflict

Given this is going to be a fair amount of work (both from an implementer and reviewer) on a screen which will be removed, I'm going to preemptively close this pull request.

I TRULY appreciate the effort, please do get in touch on Discord/make an issue/forum thread and we'll do our best to find a feature/PR to get into the codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants