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

live-preview: Checks element to decide whether it can be moved #5204

Closed
wants to merge 1 commit into from

Conversation

hunger
Copy link
Member

@hunger hunger commented May 8, 2024

Be way more conservative with when an element can be moved around. Look at eleemnt properties, element id, etc.

Start out simple that errs on the side of caution.

This is following up on what Olivier suggested during the coffee break: To disallow dropping onto something, not to forbid drag and drop altogether.

Note that this is very restrictive and basically only keeps really simple objects movable for now. We can lift the limits as we figure out ways to do so.

@ogoffart
Copy link
Member

ogoffart commented May 8, 2024

IMHO this is way too strict.
It prevents moving anything in our current example. Like none of the widget of the gallery could be moved because they have bindings.

And yet this is far from sufficient to prevent all errors.
(eg, dragging an element that have bindings like row: or col: out of a GridLayout, or moving non-repeated things into a ListView on a non-empty ListView. And that's just some few thing i can think of on top of my head)

So I think this is way too restrictive.

@hunger
Copy link
Member Author

hunger commented May 10, 2024

So it is too restrictive, yet you only list more things I can not allow?

I am getting mixed signals :-)

…n be moved

Be way more conservative with when an element can be moved around. Look at
eleemnt properties, element id, etc.

Start out simple that errs on the side of caution.
@hunger
Copy link
Member Author

hunger commented May 10, 2024

The latest version allows any move that does not re-parent the element.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also should prevent deleting element that can be referenced.

But I still think this cure is worse than the disease.

}

let is_simple_element = selected_element.with_decorated_node(|node| match node.kind() {
SyntaxKind::ConditionalElement | SyntaxKind::RepeatedElement => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that breaking anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition/model will most likely reference some local data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to parse the condition/model/etc. properly to figure that out. I did not want to do that before the release though.

Comment on lines +561 to +563
let se: syntax_nodes::SubElement = node.clone().into();
se.first_token().map(|t| t.kind()).unwrap_or(SyntaxKind::Error)
== SyntaxKind::Identifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be written as

Suggested change
let se: syntax_nodes::SubElement = node.clone().into();
se.first_token().map(|t| t.kind()).unwrap_or(SyntaxKind::Error)
== SyntaxKind::Identifier
node.child_token(SyntaxKind::Identifier).is_some()

Comment on lines +554 to +556
if drop_target.children().contains(selected_element) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, what you can check, is if they are in the same scope instead of the same parent. Either from the nodes: try to find the first ancestor which is either a Component, or a ConditionalElement; or a RepeatedElement, and they must be the same for both node.
Or easier from the ElementRc if they are in the same item tree (The enclosing component of the ElementRc)

@ogoffart
Copy link
Member

So it is too restrictive, yet you only list more things I can not allow?
I am getting mixed signals :-)

My point is tat this is too restrictive and prevent the d&d feature to be useful, while at the same time not doing what it's supposed to do: prevent any operation to cause errors.

@hunger
Copy link
Member Author

hunger commented May 10, 2024

My point is tat this is too restrictive and prevent the d&d feature to be useful, while at the same time not doing what it's supposed to do: prevent any operation to cause errors.

Yeap, I know:-/

The only reliable way to detect that moving a element is not going to cause a compile error is to do the change and compile the changed code. Everything else is going to be flawed in some major way.

The compiler is unfortunately too slow to run on every move() event... Do you think we can speed it up for "minor changes" like moving some element somehow? Or maybe have some "check mode" in the compiler that skips most of the passes and the actual code gen? That would be similar to what the LSP does already, maybe I can reuse the logic from there?

It would also require changes to how we do things right now, but the preview has all the code, so we could probably drive the compiler somehow. That could be a step towards not needing an editor to do the actual edits for us, too.

@hunger
Copy link
Member Author

hunger commented May 16, 2024

I'll try to compile-test the change now. If that is too slow, we can come back to this and discuss better heuristics.

@hunger hunger closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants