Fix #129324: Merge Down operator always appends merged layers at the end

The Merge-Down operator for layers was inserting existing layers first,
then appending the 2 merged layers at the end (top of stack).

Now merged layers are inserted at the position of the layer below the
active, so the layer order remains unchanged.

Note that merging a layer group has a similar issue, with the new
layers getting appended at the top. This is a bit more difficult because
looping only over layers drops the relative ordering of groups and
layers. A separate fix is needed for that.

Pull Request: https://projects.blender.org/blender/blender/pulls/130146
This commit is contained in:
Lukas Tönne
2024-11-11 18:42:10 +01:00
committed by Falk David
parent f93108fa28
commit 1158130995

View File

@@ -779,12 +779,18 @@ static int grease_pencil_merge_layer_exec(bContext *C, wmOperator *op)
/* Map all the other layers to their own index. */
const Span<const Layer *> layers = grease_pencil.layers();
for (const int layer_i : layers.index_range()) {
if (layer_i != prev_layer_index && layer_i != active_layer_index) {
if (layer_i == active_layer_index) {
/* Active layer is merged into previous, skip. */
}
else if (layer_i == prev_layer_index) {
/* Previous layer merges itself and the active layer. */
src_layer_indices_by_dst_layer.append({prev_layer_index, active_layer_index});
}
else {
/* Other layers remain unchanged. */
src_layer_indices_by_dst_layer.append({layer_i});
}
}
/* Map the two layers to one index so they will be merged. */
src_layer_indices_by_dst_layer.append({prev_layer_index, active_layer_index});
/* Store the name of the current active layer as the name of the merged layer. */
merged_layer_name = grease_pencil.layer(prev_layer_index).name();