Skip to content

[NRT-508] Automatically protect fields when edited#1259

Draft
RisingOrange wants to merge 6 commits intomainfrom
NRT-508
Draft

[NRT-508] Automatically protect fields when edited#1259
RisingOrange wants to merge 6 commits intomainfrom
NRT-508

Conversation

@RisingOrange
Copy link
Copy Markdown
Collaborator

@RisingOrange RisingOrange commented Mar 18, 2026

Add auto-protect feature that automatically tags fields as protected when users edit them, preventing future AnkiHub syncs from overwriting local changes. Globally protected fields (set by deck owners on the web app) are cached locally and skipped to avoid conflicts when global protection is later removed. Also includes UI improvements to the Deck Management dialog (new checkbox, heading style, spacing) and the Protect Fields dialog (globally protected fields shown as greyed-out, OK disabled when unchanged).

Related issues

Proposed changes

  • Settings: Add auto_protect_fields_when_edited toggle (enabled by default) and globally_protected_fields cache to DeckConfig
  • Editor hook: Hook into editor_did_unfocus_field to auto-add AnkiHub_Protect::FieldName tags when a field is edited (skips unchanged fields, non-AnkiHub notes, the ankihub_id field, already protected fields, and globally protected fields)
  • Deck Management dialog: Add "Automatically protect fields when edited" checkbox with tooltip and help link; minor UI polish (heading size, link text, emoji removal)
  • Protect Fields dialog (choose_subset): Add checked_and_disabled_choices param to show globally protected fields as greyed-out non-interactive items; add disable_ok_when_unchanged param; use ApplicationModal so the dialog has a title bar on macOS
  • Sync/install caching: Cache globally protected fields from the API on every deck sync (deck_updater.py) and on initial install (deck_installation.py)
  • Browser: Fix protect fields docs link URL; pass globally protected fields as disabled choices to the Protect Fields dialog

How to reproduce

  1. Subscribe to an AnkiHub deck
  2. Open Deck Management → select the deck → verify the "Automatically protect fields when edited" checkbox appears and is checked by default
  3. Open a note from that deck in the browser/editor and edit a field
  4. Verify the AnkiHub_Protect::FieldName tag is added to the note
  5. Edit a field back to its original AnkiHub value → verify the protection tag is removed
  6. Open the Protect Fields dialog (right-click → Protect fields) → verify globally protected fields appear greyed out and cannot be toggled
  7. If a field is globally protected, edit it in the editor → verify no personal AnkiHub_Protect tag is added for it

Screenshots and videos

N/A — UI changes are minimal (one checkbox added to existing options panel)

Further comments

  • Globally protected fields are skipped intentionally: if personal tags were added for globally protected fields, they'd block updates when a deck owner later removes global protection
  • 8 integration tests cover: auto-protect on edit, feature disabled, no double protection, globally protected skip, unchanged field skip, protection tag removal, non-AnkiHub note skip, and ankihub_id field skip

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces an "auto-protect" feature that automatically tags fields as protected when a user edits them, preventing local changes from being overwritten by future AnkiHub syncs. It also incorporates handling for globally protected fields, caching them locally and ensuring they are not personally protected to avoid conflicts if global protection is later removed.

Highlights

  • Automatic Field Protection: Implemented a new feature to automatically tag fields as protected (AnkiHub_Protect::FieldName) when a user edits them in the editor, preventing AnkiHub syncs from overwriting local modifications.
  • Global Protection Handling: Introduced local caching for fields that are globally protected by deck owners, ensuring these fields are not affected by the auto-protect feature and are displayed as disabled in the "Protect Fields" dialog.
  • User Interface Enhancements: Added a new "Automatically protect fields when edited" toggle to the Deck Management dialog, complete with a tooltip and a help link, and refined existing UI elements.
  • Improved "Protect Fields" Dialog: The choose_subset utility now supports displaying globally protected fields as greyed-out, non-interactive options, and includes new parameters for header text and disabling the OK button when no changes are made.
  • Configuration and Caching: Extended DeckConfig with auto_protect_fields_when_edited and globally_protected_fields settings, and integrated caching of globally protected fields during deck syncs and initial installations.
  • Comprehensive Testing: Added 8 integration tests to validate the auto-protect functionality, covering various scenarios including feature enablement/disablement, existing protection, global protection, unchanged fields, non-AnkiHub notes, and the ankihub_id field.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@RisingOrange RisingOrange force-pushed the NRT-508 branch 4 times, most recently from eb699e1 to 813df27 Compare March 23, 2026 14:10
Add auto_protect_fields_when_edited option to DeckConfig that, when enabled,
automatically adds AnkiHub_Protect tags when a user edits a field in the editor.
Globally protected fields (cached from the API at sync time) are skipped to
avoid redundant personal tags.

Also updates the Protect Fields dialog to show globally protected fields as
disabled items, fixes the protect fields docs link, and applies minor UI
improvements to the Deck Management dialog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant