Fixed #24243.

The problem was that the canvas was ajusting its position using the
segment, but the segment starts from the first staff.
Fix: find the first element in the selection and set the canvas
     position there
1/ We don't use do while loop
2/ if ((e = s->element(i)) != 0) ; we don't use that either.

Can you try something like this?

Segment* s = s1;
Element e = nullptr
while (s!=s2) {
  for (int i = dstStaffStart * VOICES; i < (endStaff + 1) * VOICES; i++) {
    e = s->element(i);
    if (e)
      break;
  }
  s = s->next1MM();
}