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: Actually store the document version #4605

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

hunger
Copy link
Member

@hunger hunger commented Feb 12, 2024

... so that we can detect outdated edits later.

... so that we can detect outdated edits later.
@hunger hunger merged commit 088337b into slint-ui:master Feb 12, 2024
34 of 35 checks passed
@hunger hunger deleted the lp_dnd_6 branch February 12, 2024 12:48
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.

Hard to review such a change in isolation because I'm not seeing the big picture.

How will this help to detect outdated edits? And what will happen when an outdated edits edit is detected?

let old = cache.source_code.insert(url.url().clone(), (url.version().clone(), content.clone()));
if cache.dependency.contains(url.url()) {
if let Some((old_version, old)) = old {
if content == old && old_version == *url.version() {
Copy link
Member

Choose a reason for hiding this comment

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

I think we wouldn't need to reload the preview if the version change but the document didn't. Do i'd skip the test on the version there.

Copy link
Member Author

Choose a reason for hiding this comment

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

But then we stick with the old version :-/

It should not happen in practice anyway that the version changed and the content did not, so this is more of a safety net.

@hunger
Copy link
Member Author

hunger commented Feb 12, 2024

This is to prevent the editor to mess up the text buffers.

How will this help to detect outdated edits?

It's the document version number used by the LS protocol, which we send along in all WorkspaceEdit requests. If the editor has a newer version of the document than the one the live preview/LSP request a change on, that change will be rejected by the editor.

And what will happen when an outdated edits edit is detected?

The editor will reject to apply edits and will push out the new document version -- which triggres the LSP/previewer to update. So it's not handled per se: Our inputs change and we update.

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.

2 participants