Commit graph

66 commits

Author SHA1 Message Date
Tobias Hunger
df1db6aafe live preview: Retrieve ElementSelection from preview_state
... and not the selected element directly. This will allow to move
more code into the proper submodules.
2024-02-23 10:06:36 +01:00
Olivier Goffart
fac0921579 Compiler: keep the layout debugging info next to its node 2024-02-21 11:33:37 +01:00
Tobias Hunger
f53a051114 live preview: Fix moving of elements
The positioning needs to happen relative to the position
of the parent element, not using global coordinates.
2024-02-20 14:04:31 +01:00
Tobias Hunger
e1aefc6f16 lsp: Notify preview about text edits
Have the LS notify the live preview about changes it initiates, so
the live preview can update its selection.

This is not possible for all edits the LS generates: Many are sent
to the editor which may or may not trigger them later, but the
notification happens when the LS adds changes on top of changes
requested by the live preview (e.g. by adding an import). This
fixes having a newly added element selected once it is rendered.
2024-02-19 22:27:32 +01:00
Tobias Hunger
e4a0a85e2f lsp: Pick one good instance when selecting/highlighting
We need to decorate an Element so we can interact with it. I want
to decorate only *one* instance of a repeated element to avoid
cluttering up the screen. So pick one good candidate for decoration:
Ideally the one the user clicked on, got for the first one
otherwise.

Store this information so we can get it back after re-rendering,
and so that we can actually mark newly added elements for selection
after they get rendered.
2024-02-19 22:27:32 +01:00
Tobias Hunger
25f0fd116d lsp: Simplify filter_ignore_nodes_in_element to a function
... returning a bool.

Do the iteration where needed instead.
2024-02-12 14:59:04 +01:00
Tobias Hunger
3bcf22beec live preview: Make some members and function in element selection pub
... so that I can reuse them.
2024-02-12 12:45:20 +01:00
Olivier Goffart
cf0dfe161b Fix preview::element_selection::root_element
Since the added Window no longer have a node, the current code that
checks that it has one doesn't work.
Instead, to skip the added window, just take the first element if the
root don't have a node
2024-01-30 11:19:17 +01:00
Tobias Hunger
2cd74463ff lsp: Add a way to ignore nodes
... and use it e.g. for the nodes the preview adds into the code itself.

Now that we mark the preview helper we add into the file as `ignore`, we
can make sure we never try to navigate to it. It was text that got
appended to the actual source code, so the editor tended to jump to the
end of the document when selecting the root element. That was created by
merging the artifical Preview node and the real root node, with the
artificial node being stored first.
2024-01-26 18:11:41 +01:00
Olivier Goffart
804971d5f6 Alsways use a Url in PreviewToLspMessage::ShowDocument
The messages serialized through the LSP should use the LSP's url type.
And keep type information as long as possible.

Otherwise, we'd end up in show_document_request_from_element_callback
with either an URL or a path, depending if the preview is native or not,
and that would fail when re-serializing to an URL to send back to
through the LSP
2024-01-25 18:55:15 +01:00
Olivier Goffart
09dc25f107 Keep all nodes for a given element (even if it is optimized out) 2024-01-25 14:45:22 +01:00
Olivier Goffart
024b8b1277 LSP preview selection: also work on the non-first repeated item 2024-01-25 11:27:39 +01:00
Olivier Goffart
b8bf81a963 Fix warnings about unused functions 2024-01-25 11:27:39 +01:00
Tobias Hunger
0b626ccbb5 lsp: More visual selection
This is a long odyssee :-/

I am back to file-based navigation now: The component-based navigation
felt so very tree-based again.

So you can click anywhere to select the "topmost" rendered element that
is defined in the same file that is getting previewed.

A double-click is again punching through the layers: It goes deeper into
the rendering layers, selecting an item at the same point but covered by
the current selection.

Ctrl makes the selection ignore file boundaries when picking something.

Shift reverses the search direction when double clicking: It will pick
an element in the click position that is rendered after the currently
selected item.
2024-01-25 11:27:39 +01:00
Tobias Hunger
d50373951f lsp: Use a more "visual" element selection for Preview UI
Try a more visual selection approach over the rather technical
tree-based one from earlier.

In this commit, a click selects the element that was rendered at the
click position *last*. I use rendered loosely here: It even takes
elements into account that are invisible but still cover the clicked
location.

A double-click punshes through to the item rendered earlier (behind) the
currently selected item that also covers the clicked position.

A shift-double-click moves towards the later rendered elements again,
usually undoing the last double-click.
2024-01-25 11:27:39 +01:00
Tobias Hunger
e93b307643 lsp: Change selection mode in preview
It is tree based now: Allowing you to visit children, the siblings and
the parent of the current selection.

Advantage: You can actually get to all elements now, even those covered by
other elements.

Disadvantage: You basically need the document outline to make sense of
the navigation:-/

We need a more visual way to select elements! But how can we even tell
which elements are going to be visible in the UI and which are not?

Here is how you navigate in this PR:

 * Click selects an element. If the click hits the currently selected
   element, then it will do nothing. Otherwise it will look whether a
   sibling was hit, working its way up the tree to the root element.
 * Double-click selects a child of the current selection: the "foremost"
   child that covers the click location will be selected.
 * shift-double-click: Takes you to the current selections parent.
 * Ctrl-click: Select a sibling of the current selected element "behind"
   the sibling that covers the current click location.
 * Shift-ctrl-click: Selects a sibling of the current selected element
   in front of the current selection that cover s the click location.
2024-01-25 11:27:39 +01:00