Skip to content

Fix part syncing when a Box item is pasted#33675

Merged
ajuncosa merged 2 commits into
musescore:mainfrom
ajuncosa:fix-box-paste
Jun 12, 2026
Merged

Fix part syncing when a Box item is pasted#33675
ajuncosa merged 2 commits into
musescore:mainfrom
ajuncosa:fix-box-paste

Conversation

@ajuncosa

@ajuncosa ajuncosa commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Resolves: #33657

Box elements were not being synced across parts when pasted. The Measure::drop() function was missing a call to manageExclusionFromParts() to properly trigger this syncing. Since the relevant part of the function seemed to have the same behaviour as Score::insertBox(), I slightly refactored that part of the code as well as the insertBox function to avoid duplication.

@ajuncosa ajuncosa changed the title Fix box paste Fix part syncing when a Box item is pasted Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a09416fd-4b76-4a2b-a2b7-20656991facc

📥 Commits

Reviewing files that changed from the base of the PR and between 0141076 and e3cd441.

📒 Files selected for processing (3)
  • src/engraving/dom/measure.cpp
  • src/engraving/dom/score.h
  • src/engraving/editing/edit.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/engraving/dom/score.h
  • src/engraving/editing/edit.cpp
  • src/engraving/dom/measure.cpp

📝 Walkthrough

Walkthrough

Adds a new Score::insertBox(MeasureBase*) overload and moves box initialization, linkage (tick/prev/next), FBOX setup, undo registration (InsertMeasures), and option handling into it. The ElementType overload now validates/creates a MeasureBase and delegates to the new overload. Measure::drop was simplified to call the new insertBox overload directly.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description adequately explains the problem (missing manageExclusionFromParts call), the fix, and the refactoring rationale. However, the template's checklist items are not completed as required by the repository guidelines. Complete the required checklist items in the PR description template, including CLA signature, commit message verification, testing confirmation, and unit test creation if applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix part syncing when a Box item is pasted' directly describes the main change: fixing box element syncing across parts during paste operations, which aligns with the core objective of the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #33657 by adding the missing manageExclusionFromParts() call and refactoring Score::insertBox() to ensure boxes are properly synced across parts when pasted.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing box syncing on paste. The refactoring of insertBox and modifications to Measure::drop are necessary and focused on resolving the linked issue without introducing unrelated changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/engraving/dom/measure.cpp

In file included from src/engraving/dom/measure.cpp:28:
In file included from src/engraving/dom/measure.h:30:
In file included from src/engraving/dom/measurebase.h:31:
src/engraving/dom/engravingitem.h:25:10: fatal error: 'draw/types/color.h' file not found
25 | #include "draw/types/color.h"
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/e3cd44146018dece4185aa9b9443cbcc41c8b891-ff5532262d8116dd/tmp/clang_command_.tmp.64ca2f.txt
++Contents of '/tmp/coderabbit-infer/e3cd44146018dece4185aa9b9443cbcc41c8b891-ff5532262d8116dd/tmp/clang_command_.tmp.64ca2f.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-

... [truncated 1258 characters] ...

stall/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1"
"-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/ff5532262d8116dd/file.o" "-x" "c++"
"src/engraving/dom/measure.cpp" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"

src/engraving/editing/edit.cpp

In file included from src/engraving/editing/edit.cpp:26:
In file included from src/engraving/editing/../dom/accidental.h:27:
src/engraving/editing/../dom/engravingitem.h:25:10: fatal error: 'draw/types/color.h' file not found
25 | #include "draw/types/color.h"
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
src/engraving/editing/edit.cpp:1565:17-1572:9: ERROR translating statement 'CompoundStmt'
Aborting translation of method 'mu::engraving::Score::cmdAddTimeSig' in file 'src/engraving/editing/edit.cpp': "Assert_failure src/clang/cAst_utils.ml:249:53"
Uncaught Internal Error: "Assert_failure src/clang/cAst_utils.ml:249:53"
Error backtrace:
Raised at ClangFrontend__CAst_utils.get_decl_from_typ_ptr in file "src/clang/cAst_utils.ml", line 249, characters 53-65
Called from ClangFrontend__CTrans.CTrans_funct.get_destructor_decl_ref in file "src/clang/cTrans.ml", line 658, characters 12-59
Called from ClangFrontend__CTrans.CTrans_funct.destructor_calls.(fun) in file "src/clang/cT

... [truncated 2200 characters] ...

in file "src/clang/cTrans.ml", line 5389, characters 6-70
Called from ClangFrontend__CTrans.CTrans_funct.compoundStmt_trans in file "src/clang/cTrans.ml", line 2090, characters 36-97
Called from ClangFrontend__CTrans.CTrans_funct.instruction_insert_cxx_temporary_markers in file "src/clang/cTrans.ml", line 4866, characters 22-60
Called from ClangFrontend__CTrans.CTrans_funct.instruction_scope in file "src/clang/cTrans.ml", line 4850, characters 22-79
Called from ClangFrontend__CTrans.CTrans_funct.instruction_log.(fun) in file "src/clang/cTrans.ml", line 4782, characters 12-47
Re-raised at IStdlib__IExn.reraise_after in file "src/istd/IExn.ml" (inlined), line 13, characters 2-50
Called from ClangFrontend__CTrans.CTrans_funct.instruction_log.(fun) in file "src/clang/cTrans.ml", line 4784, cha


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/engraving/editing/edit.cpp (1)

4759-4811: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Rebind the incoming box to the destination score before insertion.

This overload now accepts an existing MeasureBase*, but it never updates box->score(). The new caller is the paste/drop path, so the box can arrive as a clone from another score context; in that case InsertMeasures and manageExclusionFromParts(false) will run with stale ownership.

Suggested fix
 MeasureBase* Score::insertBox(MeasureBase* box, MeasureBase* beforeMeasure, const InsertMeasureOptions& options)
 {
     IF_ASSERT_FAILED(box) {
         return nullptr;
     }

     ElementType type = box->type();
     const bool isFrame = type == ElementType::FBOX || type == ElementType::HBOX || type == ElementType::TBOX || type == ElementType::VBOX;
     if (!isFrame) {
         return nullptr;
     }
+
+    if (box->score() != this) {
+        box->setScore(this);
+    }

     Fraction tick;

If setScore() does not cascade to children, those descendants need rebinding too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/engraving/editing/edit.cpp` around lines 4759 - 4811, The incoming
MeasureBase* box passed into Score::insertBox must be rebound to this Score
before insertion so InsertMeasures and manageExclusionFromParts(false) operate
on the correct ownership; call box->setScore(this) (and if setScore does not
update descendants, traverse box's children and call setScore(this) on them as
well) after computing tick and before undo(new InsertMeasures(...)) and before
manageExclusionFromParts; ensure you update any nested frames/contents (use
existing accessors on MeasureBase/FBox/Measure) so all descendants reference
this Score.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/engraving/editing/edit.cpp`:
- Around line 4759-4811: The incoming MeasureBase* box passed into
Score::insertBox must be rebound to this Score before insertion so
InsertMeasures and manageExclusionFromParts(false) operate on the correct
ownership; call box->setScore(this) (and if setScore does not update
descendants, traverse box's children and call setScore(this) on them as well)
after computing tick and before undo(new InsertMeasures(...)) and before
manageExclusionFromParts; ensure you update any nested frames/contents (use
existing accessors on MeasureBase/FBox/Measure) so all descendants reference
this Score.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5f17f4ad-abcc-4a84-b80d-8d10668cb5d0

📥 Commits

Reviewing files that changed from the base of the PR and between f6262b2 and 0141076.

📒 Files selected for processing (3)
  • src/engraving/dom/measure.cpp
  • src/engraving/dom/score.h
  • src/engraving/editing/edit.cpp

@ajuncosa ajuncosa requested a review from mike-spa June 3, 2026 06:44
@davidstephengrant davidstephengrant self-assigned this Jun 3, 2026
@davidstephengrant

Copy link
Copy Markdown
Contributor

@ajuncosa Tested and approved in Ubuntu 24.04.4 LTS.

@ajuncosa ajuncosa merged commit d53a8ed into musescore:main Jun 12, 2026
14 checks passed
@ajuncosa ajuncosa deleted the fix-box-paste branch June 12, 2026 15:29
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.

copy and paste of frames in the score is not synced with parts

3 participants