Skip to content

fix(ui): refuse a locked cell's edit before a draft blocks Save (#2945) - #3040

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
maxm11:fix/2945-protected-cell-stuck-draft
Nov 1, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
maxm11:fix/2945-protected-cell-stuck-draft

Conversation

@maxm11

@maxm11 maxm11 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Typing into a locked cell of a protected sheet opened the in-cell editor. On Enter the engine correctly refused cell.set, but the UI kept the draft open with the warning. That draft could only be closed with Esc, and until then every file.* command ran settle_drafts, so Save was refused and there was no undo step to take back (the edit never entered the workbook).

Closes #2945.

Cause

SheetApp::begin_edit never checked sheet protection. commit_edit_here treated every refusal as "fix the draft and retry" — correct for data validation and formula errors, but a protection refusal left a draft that could never be entered.

Fix

  • Session::locked_cell_message exposes the engine's existing protection check (locked_cell_error + the cell's locked style + Allow Edit Ranges unlocked in the session) as one query, so the UI asks the same rule the engine enforces.
  • begin_edit refuses before creating an editor, with Excel's warning, so no draft (and no undo/dirty/save side effect) ever exists.
  • commit_edit_here cancels a draft that becomes locked while it is open (sheet protected or cell locked concurrently) instead of keeping a draft that can never be committed.

Tests

  • Unit (app::editing): typing in a locked cell opens no editor, adds no undo step, leaves dirty state alone and Save works; an unlocked cell on the same sheet still edits, undoes and saves; a draft that becomes locked is cancelled.
  • Integration (kittest, tests/it/protected_cell.rs): real typed text into a locked cell shows the warning, Enter dismisses it, Save is not blocked, and an unlocked cell still edits, undoes and saves.
  • Engine: locked_cell_message reports locked vs unlocked cells and an unknown sheet.

Validation

  • cargo xtask ci (with CRAFT_FONTS_DIR): i18n-report, fmt, clippy, test, doctest, assets and layers pass; cargo xtask parity --check and cargo xtask keytips --check pass separately.
  • The local wasm step fails before compiling this change: this Homebrew Rust install has no wasm32-unknown-unknown target (can't find crate for core). That is environmental; the changed crates are engine and UI and no wasm-only code was touched.
  • Without CRAFT_FONTS_DIR, two pre-existing integration tests fail on missing glyphs (ẞ, ẻ); both pass with the pinned fonts input.

Summary by CodeRabbit

  • Bug Fixes
    • Editing a locked cell on a protected sheet is blocked, with a warning displayed instead of opening an editor or changing the cell.
    • If a cell becomes locked while an edit is in progress, the draft is discarded and a warning is shown.
    • Unlocked cells on protected sheets remain editable, undoable, and savable.
    • Saving remains available while a protection warning is displayed, and pressing Enter dismisses the warning.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 40b254c and edcb626.

Files selected for processing: 1
  • contributors/people.toml

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

The session now provides protection messages for locked cells on protected sheets. The UI checks protection when editing begins and when a draft is committed. Tests cover warnings, cell values, undo, and saving.

Changes: Protected Cell Editing

Layer / File(s) Summary
Protection message contract
crates/engine/src/lib.rs, crates/engine/src/tests.rs
Session::locked_cell_message returns a protection error for a locked cell on a protected sheet. Tests check the message and cases that return no message.
Editing guards and validation
crates/ui-egui/src/app/editing.rs, crates/ui-egui/tests/it/*
Editing refuses locked cells before opening an editor. If a draft becomes locked, the UI discards it and displays a warning. Tests cover unlocked-cell editing, undo, and saving.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: aiongg

Merge Risk: Minimal · up to edcb6

The protected-cell behavior is covered at edit start and commit without an identified regression; the change is mergeable.

Security architecture risk: Minimal · up to edcb6

Protected cells are checked earlier without weakening existing write protections. Drafts that become locked are discarded with a warning instead of blocking Save. The reviewed changes introduce no material security risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The affected write route includes individual cell edits and selection fills within a workbook. Although the UI preflight checks the draft’s anchor cell, the engine’s general commit check still evaluates changed locked cells before accepting the workbook update.

Trust Boundaries and Controls

  • observed — UI input remains subject to authoritative engine enforcement. Bypassing the new editor preflight does not remove the existing cell.set guard or the general protection check; authorization responsibility therefore remains in the engine rather than moving into the UI.

Resilience and Maintainability Implications

  • inferred — Protection cancellation is idempotent: it removes the editor without issuing a cell write, so subsequent settlement has no draft to retry. Ordinary formula or validation failures still restore the draft and abort settlement, preserving the distinction between retryable input errors and the newly handled protection refusal.
Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Out of Scope Changes check Warning The editing changes and their tests support issue #2945. The added contributors/people.toml entry for people.maxm11 does not implement or test protected-cell editing, Save, or undo behavior. It is… Remove the unrelated contributors/people.toml change, or provide a concrete issue-related coding requirement that requires this contributor entry.
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing edits to locked cells before an uncommittable draft can block Save.
Linked Issues check Passed Issue #2945 requires that a protected-cell edit does not leave the file unsavable or the user without a valid undo path. The change checks protection before begin_edit creates a draft and cancels a …
Full details: Linked Issues check

Explanation

Issue #2945 requires that a protected-cell edit does not leave the file unsavable or the user without a valid undo path. The change checks protection before begin_edit creates a draft and cancels a draft that becomes locked. The reported unit, engine, and integration tests cover the warning, unchanged state, Save, undo, and editing of an unlocked cell.

Full details: Out of Scope Changes check

Explanation

The editing changes and their tests support issue #2945. The added contributors/people.toml entry for people.maxm11 does not implement or test protected-cell editing, Save, or undo behavior. It is unrelated to the issue scope.

Resolution

Remove the unrelated contributors/people.toml change, or provide a concrete issue-related coding requirement that requires this contributor entry.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ReviewerA — source-read COMMENT (not an approval)

I read the first hunks: the PR adds the author to contributors/people.toml (sync_github_name = true, matching other entries) and changes the engine so that, per the title (#2945), an edit of a locked cell is refused up front, before a draft is created that then blocks Save. Refusing before the draft exists is right: a draft in a protected cell can neither be committed nor discarded cleanly. The message should name the reason (sheet protection) and how to lift it. I did not read the engine change. Add tests for typing in a locked cell on a protected sheet (refused, no draft), an unlocked cell (accepted), a protected sheet with the option to select locked cells off, and Save afterwards (works). Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 49ed44c into storytold:main Nov 1, 2026
1 check passed
@echelon

echelon commented Nov 1, 2026

Copy link
Copy Markdown
Member

Merged in ea1d52f. Thanks! Refusing the locked cell before a draft exists is the right fix for the blocked Save.

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.

Bug: Typing in a protected cell causes file save lock and prevents undo, leaving the user stuck

4 participants