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

direct copy paste - clone for page or another component #70

Open
FabienArcellier opened this issue Dec 26, 2024 · 1 comment
Open

direct copy paste - clone for page or another component #70

FabienArcellier opened this issue Dec 26, 2024 · 1 comment
Labels
design proposal a ticket that propose a technical solution to solve a specific point

Comments

@FabienArcellier
Copy link
Owner

FabienArcellier commented Dec 26, 2024

  • When I copy then paste a page immediately, I expect a clone to appear right after the page that has been copy.
  • When I copy then paste a block of text immediately, I expect it to be duplicated right after the block that has been copy.

Rule to clone a component (CTRL C + CTRL V immediately)

R1: If the target is the previous component, then the target would be the parent. The component is paste right after. For example, I copy a section then paste it directly

Rule to copy a component inside another one (current behavior)

R2 : If the target is a viable container (isSubtreeIngestable), the component is paste inside. For example, I copy a block of text, then select a section.

Rule to copy a component after another one

R3 : If the target is not a viable container and the parent is, the component is paste right after. For example, I copy a block of text, then paste it.

@FabienArcellier FabienArcellier added the design proposal a ticket that propose a technical solution to solve a specific point label Dec 26, 2024
@FabienArcellier FabienArcellier changed the title copy paste in place - clone for page direct copy paste - clone for page or another component Dec 26, 2024
@madeindjs
Copy link

I think R3 is not that difficult to implement.

We might just need to :

  1. change isPasteAlowed
    function isPasteAllowed(targetId: Component["id"]): boolean {
    const component = wf.getComponentById(targetId);
    if (!component || component.isCodeManaged) return false;
    const clipboard = ssbm.getClipboard();
    if (clipboard === null) return false;
    const { jsonSubtree } = clipboard;
    const subtree: Component[] = JSON.parse(jsonSubtree);
    if (subtree.length == 0) return false;
    // Mutate the subtree to reflect tentative parent
    subtree[0].parentId = targetId;
    return isSubtreeIngestable(subtree);
    }
  2. update pasteComponent to target sibling node if the current node can't contain child
    function pasteComponent(targetParentId: Component["id"]): void {
    const targetParent = wf.getComponentById(targetParentId);
    if (!targetParent) return;
    const clipboard = ssbm.getClipboard();
    if (clipboard === null) return;
    const { operation, jsonSubtree } = clipboard;
    const subtree = JSON.parse(jsonSubtree);
    const rootComponent = subtree[0];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design proposal a ticket that propose a technical solution to solve a specific point
Projects
None yet
Development

No branches or pull requests

2 participants