Skip to content

Edit: duplicating during a text edit ends the edit (#2226) - #2266

Merged
bflatastic merged 1 commit into
storytold:mainfrom
SusieeTheLinuxUser:fix/2226-duplicate-ends-text-edit
Oct 29, 2026
Merged

bflatastic merged 1 commit into
storytold:mainfrom
SusieeTheLinuxUser:fix/2226-duplicate-ends-text-edit

Conversation

@SusieeTheLinuxUser

@SusieeTheLinuxUser SusieeTheLinuxUser commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2226

What was wrong

Edit > Duplicate (edit.duplicate) replaces the layer selection with the copies
(st.selected_layers = created), but an open in-canvas text edit (state.text_edit) kept
pointing at the original layer. The canvas caret stayed on the now-unselected original: typing
after the duplicate edited the unselected layer while the copy was the selected one.

Root cause

duplicate (crates/engine/src/cmd/edit.rs) updated the selection without regard for the
text-edit state. The delete command right next to it already special-cases an open text edit;
duplicate did not.

What changed

After the duplicate applies, if the edited layer is no longer among the selected layers, the
command calls text_edit::end_edit — the same close the rest of the app uses (including its
empty-created-layer cleanup), in the one place every caller (menu, shortcut, MCP, control
channel) dispatches through. This is the issue's first option, "the edit ends when the selection
moves" — the #2096 invariant for Deselect All, and After Effects' observable behaviour (the edit
commits; the copy is selected with no edit open). The alternative (moving the edit onto the copy)
was not taken.

Test

tests::text_edit::duplicate_during_a_text_edit_ends_the_edit (the crate's existing command-test
style): a text layer with an open edit (text.edit {layer, caret}), edit.duplicate {layers:[t]} —
asserts the copy is selected, state.text_edit is none, and original and copy both carry the
text. It fails before the fix (the edit is still open on the original) and passes after.

cargo test -p effectcraft-engine --lib duplicate_during_a_text_edit

Counts


Written by GLM-5.3-Flash in ZCode, then reviewed with Claude Code and by me (@SusieeTheLinuxUser) before submitting.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Duplicating a text layer during editing now ends the edit session when the original layer is no longer selected. The original and duplicate retain their text, and the duplicate becomes selected.
    • If the edited layer remains selected after duplication, the edit session stays open.

@coderabbitai

coderabbitai Bot commented Oct 24, 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 7c0a022 and 60a356e.

Files selected for processing: 2
  • crates/engine/src/cmd/edit.rs
  • crates/engine/src/tests/text_edit.rs

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

Walkthrough

When duplication selects a copy instead of the layer being edited, the command ends the active text-edit session. A regression test checks that the copy is selected, editing ends, and both layers retain “Hello.”

Changes: Text edit duplication

Layer / File(s) Summary
Update edit state after duplication
crates/engine/src/cmd/edit.rs, crates/engine/src/tests/text_edit.rs
After duplication selects the copies, the command ends text editing if the edited layer is no longer selected. The regression test checks selection, edit state, and text retention.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: echelon

Merge Risk: Minimal · up to 60a35

No concrete merge-blocking defect remains identified in the reviewed change.

Architecture risk: Low · up to 7c0a0

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/engine/src/commands/edit.rs: After duplication selects the copies, duplicate now ends an open text edit if its layer is absent from the selected layers.
  • observed — Modified behavior in crates/engine/src/tests_text_edit.rs: Adds a test for duplicating a layer during text editing. It asserts that the duplicate is selected, the edit ends, and both the original and copy retain “Hello.”
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% 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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Edit: duplicating during a text edit ends the edit (#2226)" names the main behavior change: duplicate now ends an active text edit when the edited layer is no longer selected. The raw summa…
Linked Issues check Passed [#2226] The issue requires that a duplicate made during an in-canvas text edit must not leave the edit open on an unselected original layer. The issue allows either ending the edit when selection move…
Out of Scope Changes check Passed The whole-PR changes are limited to two areas. The first is the post-edit check and end_edit call added to duplicate in crates/engine/src/cmd/edit.rs, which implements the #2226 objective. The sec…
Full details: Title check

Explanation

The title "Edit: duplicating during a text edit ends the edit (#2226)" names the main behavior change: duplicate now ends an active text edit when the edited layer is no longer selected. The raw summary and PR objectives both describe this change, and the regression test matches it. The title is specific and short, so it passes. The linked issue #2226 is referenced in the title, which helps traceability. The PR comments about rebasing and CI do not affect the title assessment.

Full details: Linked Issues check

Explanation

[#2226] The issue requires that a duplicate made during an in-canvas text edit must not leave the edit open on an unselected original layer. The issue allows either ending the edit when selection moves or moving the edit to the copy. At head, duplicate in crates/engine/src/cmd/edit.rs sets st.selected_layers = created inside s.edit("Duplicate", ...). It then checks s.state.text_edit.as_ref().is_some_and(|e| !s.state.selected_layers.contains(&e.layer)) and calls super::text_edit::end_edit(s, &Value::Null). This ends the edit when the edited layer is no longer selected, which is the first option the issue allows. The regression test duplicate_during_a_text_edit_ends_the_edit in crates/engine/src/tests/text_edit.rs opens a text edit with text.edit, runs edit.duplicate on the layer, and asserts that the copy is selected, state.text_edit is none, and both the original and the copy keep the text "Hello". The test covers the reported behavior. Evidence limit: the whole-PR text diff for edit.rs could not be read because changed blobs were missing from the checkout. The verdict uses the full file read at head, which shows the complete duplicate function, and the test diff. The PR objectives report baseline and after-change test counts and rebase/CI tasks. These are non-coding or verification notes and do not change this verdict. The previous PASS remains supported by the code at head.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes are limited to two areas. The first is the post-edit check and end_edit call added to duplicate in crates/engine/src/cmd/edit.rs, which implements the #2226 objective. The second is the regression test added to crates/engine/src/tests/text_edit.rs, which verifies that objective. The test diff contains only the new test function and its doc comment. The raw summary reports +5/-0 for edit.rs and +14/-0 for the test file, which matches this scope. No unrelated refactoring or unrelated file changes appear in the reviewed evidence. The PR description and objectives mention rebase, lint, and CI work. Those items concern process and verification, not code outside the linked issue scope. The edit.rs diff could not be read directly, so the scope judgment for that file relies on the full file read at head and the raw summary. No unrelated change was found in the evidence available.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% 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 1 functions across 2 files.

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

Comment @coderabbitai help to get the list of available commands.

@bflatastic

Copy link
Copy Markdown
Member

Hi @SusieeTheLinuxUser, thanks for this PR! main has changed a lot since it was opened, and it now conflicts with main, so it needs a rebase before we can review it for merging.

Most of the conflict comes from the shared module layout (#2491), which moved or split files this PR touches:

  • crates/engine/src/commands/edit.rs → crates/engine/src/cmd/edit.rs
  • crates/engine/src/tests_text_edit.rs: its folder moved to crates/engine/src/tests/

When you rebase, please also make sure it fits the other recent changes:

CI (cargo xtask ci) now runs on PRs. Once it's green on the rebased branch, we'll take a look. Thank you!

Edit > Duplicate replaces the layer selection with the copies, but an
open in-canvas text edit stayed on the original layer: typing kept
editing a layer that was no longer selected. When the duplicate leaves
the edited layer deselected, end the edit the way storytold#2096's Deselect All
does (text_edit::end_edit), in the command every caller — menu, shortcut,
MCP — dispatches through.

Co-Authored-By: GLM-5.3-Flash <noreply@z.ai>
@SusieeTheLinuxUser
SusieeTheLinuxUser force-pushed the fix/2226-duplicate-ends-text-edit branch from 7c0a022 to 60a356e Compare October 29, 2026 04:30
@SusieeTheLinuxUser

Copy link
Copy Markdown
Contributor Author

Rebased onto main (990fa66) and moved into the #2491 layout (cmd/edit.rs, tests/text_edit.rs). cargo clippy --all-targets -- -D warnings, cargo fmt --check and the touched crate's tests pass locally. Could you approve the CI workflow run? Thanks!

@bflatastic
bflatastic merged commit c35fe91 into storytold:main Oct 29, 2026
1 check passed
@bflatastic

Copy link
Copy Markdown
Member

Merged, thank you @SusieeTheLinuxUser! It landed on main with a batch of community PRs, after a full workspace build and test run on Windows against the refactored main (fmt, strict clippy, about 4,100 tests, layers, assets and wasm). I changed Fixes #2226 to Part of #2226: #2268 covers Cmd+D typed inside the text editor.

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.

2 participants