Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer index when inserting block elements #7827

Open
EGRoBBeRTiT opened this issue Aug 2, 2024 · 0 comments
Open

Layer index when inserting block elements #7827

EGRoBBeRTiT opened this issue Aug 2, 2024 · 0 comments

Comments

@EGRoBBeRTiT
Copy link

EGRoBBeRTiT commented Aug 2, 2024

When you insert canvas elements, they are inserted on top of all others. However, when inserting blocks (an image or a note), they are inserted under the canvas elements. Is this behavior good for you or not?
It seems that any element that is inserted must be on top of all the others.

I found a block of code where the index for the block is generated if the last layer type is canvas. It is located in packages/blocks/src/surface-block/managers/layer-manager.ts:

      if (lastLayer.type === 'canvas') {
        const secondLastLayer = nToLast(this.layers, 2);
        const secondLastLayerIndex = secondLastLayer
          ? ungroupIndex(secondLastLayer.indexes[1])
          : null;
        const lastLayerIndex = ungroupIndex(lastLayer.indexes[0]);

        return generateKeyBetween(
          secondLastLayerIndex,
          secondLastLayerIndex && secondLastLayerIndex >= lastLayerIndex
            ? null
            : lastLayerIndex
        );
      }

Here you take not the last index of the last layer, but the last index of the penultimate layer (which in this case will be of type block). At the same time, you forgot to check that the penultimate layer exists and this occurs when you generate a key between null and null.
If the penultimate element exists, then an index is generated between the last index of the penultimate layer and the first index of the last layer, or null. That is, you deliberately position the blocks under the canvas elements. Why did you do this and is this normal or did you make a mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant