Commit graph

133 commits

Author SHA1 Message Date
Tobias Hunger
543bff941f live preview: Introduce a SelectionRectangle struct 2024-03-19 08:58:34 +01:00
Tobias Hunger
6ee2eec8a4 live preview: Do not try to set length to NaN
Also handle inifinite values while at it...

Fixes: #4848
2024-03-18 16:24:56 +01:00
Tobias Hunger
9873cfd7c0 janitor: Run cargo clippy --fix
Only the hand-picked sensible things, not all of it ;-)

Also fix a few typos that cspell complained about when I
tried to commit and some formatting changes that cargo fmt
insisted on when commiting.
2024-03-14 13:42:38 +01:00
Tobias Hunger
feb96bb03b preview: Add more data to ComponentInformation
Add `fills_aprent` and `default_properties` to
`ComponentInformation`. The first is a bool showing
whether the Component will fill its parent or not.

The later is a set of properties that the UI will set
when the widget gets dropped.

Refactor the data passing a bit: Keep the data on known
components around. Pass only the component name into
the UI, but pass the entire `ComponentInformation` to
the `drop_location` methods.
2024-03-06 17:31:08 +01:00
Tobias Hunger
d0fc025bc8 live preview: Do not drop on elements that can not have children
Slpit up `lookup_type_for_child_elemnt` (in the compiler) into the
part that looks at the element itself only (called `accepts_child_element`)
and the part that looks at the child.

When deciding whether we can drop something into another element in
the live preview, we know the child type is going to be OK, even when
the `TypeRegister` does not contain it yet (as it is not imported yet).
2024-03-06 12:15:10 +01:00
Tobias Hunger
3ba59dad46 lsp: Use ElementRcNode when handling properties
We recently got better support for inlined elements. Use
The `ElementRcNode` when accessing properties, so that
we can actually have a better idea which SyntaxNode we
need to work on.

This is actually not too critical as the LSP does little
inlining, but I wanted to reuse this on the preview side
as well, which does inlining much more aggressively.

Do NOT access properties in the live preview though:
It is heavily optiomized, so most properties are just
gone there;-)
2024-03-05 13:10:41 +01:00
Tobias Hunger
3ad3a42656 live preview: Do import handling in drop_location
Remove the AddComponent and the AdjustSelection messages
from the communication between LSP and preview.

Also remove the code to delete an element.
2024-03-01 18:54:40 +01:00
Tobias Hunger
b0f2e8cd28 live preview: Re-enable moving and resizing when no layout is in sight
Allow moving and resizing of elements provided:

 * The element is not layout. This approximates
   "fills its parent", which is what we aim for once
   we can query type info rom within the Preview.
 * The element is not *inside* a layout
2024-02-28 22:33:39 +01:00
Tobias Hunger
e668a0a91e live preview: Fix thinko leading to wrong elements getting selected
The `SelectedElement` does not need a `debug_index` as the interesting node
is fully specified by the source location it already contains.
2024-02-28 22:33:39 +01:00
Tobias Hunger
6ab0a30192 live preview: Disable moving/resizing of selected elements 2024-02-28 22:33:39 +01:00
Tobias Hunger
a0b862b096 live preview: Delete an element again
* Refactor the code a bit: Move element edit functions
  into the `element_edit` module below `language`
2024-02-28 15:53:49 +01:00
Tobias Hunger
1f44bdad2f live preview: Store selected node, not just the selected element 2024-02-28 15:53:49 +01:00
Olivier Goffart
a3c99555a0 LSP: fix compilation without the preview features
Use the format test to test this compilation
2024-02-26 11:14:02 +01:00
Tobias Hunger
23cc7cde61 live preview: Move reselection of element code into element_selection module 2024-02-23 10:06:36 +01:00
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
2c096aa885 live preview: Update selection when size of UI changes
Changing the size of a UI will most likely move elements
around. So reselect the current selection when that happens.

This is not a proper solution: It e.g. ignores animations
changing element sizes, etc. but it does handle one
annoying case.
2024-02-20 12:30:49 +01:00
Tobias Hunger
08372e5a07 live preview: Implement resizing and moving of selected eleement
Much polish needed, but it is a basis to build upon.
2024-02-19 22:27:32 +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
5d13878e68 lsp: Simplify sending messages from preview to lsp
... in native mode,

Have the channel between the two transport
`PreviewToLspMessages` directly instead of wrapping
those into `Notifications` of the language server
protocol.

Unformtunately the notification code eneds to stay in
place, as that is what the WASM preview uses to talk
to a native LSP.

I did nto unify wasm and native handling of the
`PreviewToLspMessage`s: The different async runtimes
we need to integrate with got into the way.
2024-02-13 17:03:58 +01:00
Tobias Hunger
b615baf98d live preview: Implement dropping an Element onto the canvas
... and make it show up in the code/live preview.

Currently layouts are not supported and it will try to drop
onto elements not accepting children.

But it does add the necessary import statement already.
2024-02-13 17:03:58 +01:00
Tobias Hunger
dd8fefd6a2 live preview: Polish drag-and-drop UI
* Add the import path into the sheared data so that
  is available when needed.
* Fix drop location, mouse pointers, ...
2024-02-12 15:03:08 +01:00
Tobias Hunger
088337b0b0 live preview: Actually store the document version
... so that we can detect outdated edits later.
2024-02-12 13:48:46 +01:00
Tobias Hunger
6dbbc761e4 LSP: Add some getters to common data structs
Just for convenience :-)
2024-02-12 12:44:22 +01:00
Tobias Hunger
b9ae753edd lsp: Make it clearer what is sent to the editor
Move the code that sends to the editor from within the LSP and the live
preview into a module in common.

This makes it clearer what actually happens and allows to remove some
code from the preview that does not really belong there.
2024-02-09 15:24:13 +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
5b0ee206be LSP: Simplify the lsp to preview messaging
Don't use a trait, but always dispatch through  a LspToPreviewMessage
2024-01-25 18:55:15 +01:00
Olivier Goffart
bcd73bb6ef LSP preview: De-duplicate some code between native and wasm 2024-01-25 18:55:15 +01:00
Olivier Goffart
7d255a1a18 Fix (native) preview not taking account change in other files than the main file
Because it wouldn't take the files from the cache
2024-01-25 14:44:30 +01:00
Tobias Hunger
7543a62da9 lsp: Fix style selection in Preview UI 2024-01-25 13:31:23 +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
Tobias Hunger
03bed1a4eb lsp: Implement UI side of drag and drop
... the rust side is just qa mock yet.
2024-01-19 09:14:02 +01:00
Tobias Hunger
7754fccdd4 lsp: Add Sidebar showing available Components
Just show what all the components currently available.
2024-01-19 09:14:02 +01:00
Tobias Hunger
192f805586 lsp: Find images not loading in native preview
I broke that when using URLs more consistently. Our path is either a
path or a URL is so easy to break.
2024-01-16 10:49:23 +01:00
Tobias Hunger
bb11166cde lsp: Show UI even if the first time preview rendering failed 2024-01-15 14:46:39 +01:00
Tobias Hunger
19cf90a319 lsp: Send document versions from lsp to previewer
We want the previewer to become interactive, so we need to pass on the
document versions so we can detect the editor, lsp and previewer going
out of sync.
2024-01-15 14:46:39 +01:00
Tobias Hunger
9b7a9b3f77 lsp: Update selection code to changed double-click handling 2024-01-10 11:41:55 +01:00
Olivier Goffart
ba738be0a7 LSP preview: fix some issue related to geometry
- make sure that the initial size is proper by calling show() on the preview ui
   after the factory has been set
 - ensure that there is no recursion if the inner layout info depends on the size
   (Fixes #3989)
 - Ensure that the geometry constraints are respected when previewing a component
   that was already resized
2024-01-02 10:48:12 +01:00
Tobias Hunger
378280e0a7 lsp: Ignore the "Window" when selecting in preview
The compiler automatically adds a Window on top of the actual root
element when that isn't a Window already. When selecting the added
window element would get ignored and the "real" root element would get
selected as its only child. That causes the cursor to jump to the end of
the document.

So skip auto-added Windows when selecting, starting with the "real" root
element.
2023-12-20 19:28:35 +01:00
Tobias Hunger
9436a23546 lsp: Reset selection on preview update 2023-12-20 19:28:35 +01:00
Tobias Hunger
9e5806cfe8 lsp: Use lsp_types::Range over lots of usize 2023-12-20 19:28:35 +01:00
Tobias Hunger
ca1263c3e5 lsp: Handle selections and highlighting in the LSP
Ask the interpreter for all the necessary information, but handle the
look and feel in the LSP preview UI.
2023-12-20 19:28:35 +01:00
Tobias Hunger
c9414d98fa lsp: Add element tree printing functionality (unused!) 2023-12-20 19:28:35 +01:00
Olivier Goffart
09de1dc5b5
LSP: Also close the popup on wasm
Move the code to close the popup in the function that is common with native and wasm.

Amend af34e4f182
2023-12-01 09:58:51 +01:00
Olivier Goffart
184cb5f580 LSP: Simplify the preview config handling
- Put the config in a struct so its easier to pass around
 - respect the command line args as default for the style
 - fix compilation without the preview feature
2023-11-24 14:08:06 +01:00