- {
- Grob_array *ga = unsmob_grob_array (valign_->get_object ("elements"));
- vector<Grob*> &arr = ga->array_reference ();
-
- Grob *added = arr.back ();
- arr.pop_back ();
- for (vsize i = 0; i < arr.size (); i++)
- {
- if (arr[i] == before_grob)
- {
- arr.insert (arr.begin () + i, added);
- added->set_property ("staff-affinity", scm_from_int (DOWN));
- break;
- }
- else if (arr[i] == after_grob)
- {
- arr.insert (arr.begin () + i + 1, added);
- added->set_property ("staff-affinity", scm_from_int (UP));
- break;
- }
- }
- }
+ {
+ Grob_array *ga = unsmob<Grob_array> (valign_->get_object ("elements"));
+ vector<Grob *> &arr = ga->array_reference ();
+
+ Grob *added = arr.back ();
+ arr.pop_back ();
+ for (vsize i = 0; i < arr.size (); i++)
+ {
+ if (arr[i] == before_grob)
+ {
+ arr.insert (arr.begin () + i, added);
+
+ /* Only set staff affinity if it already has one. That way we won't
+ set staff-affinity on things that don't want it (like staves). */
+ if (scm_is_number (added->get_property ("staff-affinity")))
+ added->set_property ("staff-affinity", scm_from_int (DOWN));
+ break;
+ }
+ else if (arr[i] == after_grob)
+ {
+ arr.insert (arr.begin () + i + 1, added);
+ if (scm_is_number (added->get_property ("staff-affinity")))
+ added->set_property ("staff-affinity", scm_from_int (UP));
+ break;
+ }
+ }
+ }