⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

fix(change-note-types): don't discard undo queue#20249

Draft
david-allison wants to merge 5 commits intoankidroid:mainfrom
david-allison:fix-note-types
Draft

fix(change-note-types): don't discard undo queue#20249
david-allison wants to merge 5 commits intoankidroid:mainfrom
david-allison:fix-note-types

Conversation

@david-allison
Copy link
Member


Purpose / Description

The backend method changeNotetypeOfNotes internally updates the schema does not not discard the undo queue.

https://github.com/ankitects/anki/blob/83c615cc7f9aef3c336936fa797671965538f89c/rslib/src/notetype/notetypechange.rs#L216-L222

Before this PR, we called modSchema(), which updated the schema and discarded the undo/study queues

Fixes

Approach

Upstream Anki relies on implicit knowledge to handle backend methods which update the schema: they show a dialog if a schema change is needed, then call the backend method

I attempted to introduce a 'guard context' (my terminology), using Kotlin's experimental context parameters so this check was enforced by code, but there was a dex issue:

So I continued using Anki's approach: call launchCatchingRequiringOneWaySync before a backend method which modifies the collection

I then removed the modSchema(check = true) call

How Has This Been Tested?

Screenshot 2026-01-28 at 17 12 04

Learning (optional, can help others)

Loads of stuff in the stacked PR

Checklist

  • 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

**launchCatchingRequiringOneWaySync**
- This didn't belong in the DeckPicker

**userAcceptsSchemaChange()**
- extract to a more centralized location

**userAcceptsSchemaChange(col)**
- delete; unused
Removed dead code
Documented undo behaviour
Since we are no longer in Java, `ConfirmModSchemaException` is no longer
 a checked exception, so we can add in Anki's 'check' parameter

Also improves documentation of the method

Fixes 20246
… queue

Renamed to launchCatchingRequiringOneWaySyncDiscardUndo

For issue 20172
The backend method `changeNotetypeOfNotes` internally updates
 the schema does not not discard the undo queue.

https://github.com/ankitects/anki/blob/83c615cc7f9aef3c336936fa797671965538f89c/rslib/src/notetype/notetypechange.rs#L216-L222

Before this PR, we called `modSchema()`, which updated the schema
 and discarded the undo/study queues

Upstream Anki relies on implicit knowledge to handle
 backend methods which update the schema: they show a dialog
 if a schema change is needed, then call the backend method

I attempted to introduce a 'guard context' (my terminology),
 using Kotlin's experimental context parameters so this check
 was enforced by code, but there was a dex issue: 20247

So I continued using Anki's approach: call
 `launchCatchingRequiringOneWaySync` before a backend method
 which modifies the collection

I then removed the `modSchema(check = true)` call

Fixes 20172
@david-allison david-allison added the Blocked by dependency Currently blocked by some other dependent / related change label Jan 28, 2026
@ZornHadNoChoice
Copy link

How Has This Been Tested?

541754429-d87f4359-0162-4ea7-a146-8316ac793676

In case you didn't know, you can undo the note type change without this PR.

@david-allison
Copy link
Member Author

I wasn't aware, but the 'one-way sync' icon now disappears when the undo occurs.

@david-allison david-allison added this to the 2.24 release milestone Jan 29, 2026
Copy link
Member

@Haz3-jolt Haz3-jolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!!

@Haz3-jolt Haz3-jolt added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 29, 2026
@david-allison david-allison marked this pull request as draft January 29, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Blocked by dependency Currently blocked by some other dependent / related change Needs Second Approval Has one approval, one more approval to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing note types from the dialog breaks the undo stack

3 participants