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

fix: the code block wrap state shoud be persisted in database #7062

Merged
merged 1 commit into from
May 16, 2024

Conversation

akumatus
Copy link
Member

@akumatus akumatus commented May 15, 2024

TL;DR

This Pull Request moves the wrap property from temporary state to persistent data model. When user refreshes the web browser, the code block warp style keeps.

Fix affine-design/issue/BS-297.

What changed?

  • In code-block.ts, the _wrap private state variable has been removed, and all references to it have instead been directed to this.model.wrap.
  • A setWrap function has been added to handle updating the wrap property in the block model, which can be persisted in database.

How to test?

Test this change by creating a code block in document and toggle the wrap icon. Check if this modifies the wrap state in the model and updates the UI accordingly. Refresh the browser, the code block warp styles keeps.

截屏2024-05-15 16 03 20 截屏2024-05-15 16 03 02

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2024 6:39am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview May 16, 2024 6:39am

Copy link

graphite-app bot commented May 15, 2024

Your org has enabled the Graphite merge queue for merging into master

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@akumatus
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @akumatus and the rest of your teammates on Graphite Graphite

@Flrande
Copy link
Member

Flrande commented May 15, 2024

Can you add a test for this case?

Copy link
Member

@doodlewind doodlewind left a comment

Choose a reason for hiding this comment

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

Need to test that for legacy data without the wrap field, whether the backward compatibility could be supported.

@akumatus akumatus force-pushed the fix/code-block-wrap-persistence branch from 92221a1 to f97f465 Compare May 15, 2024 09:41
@akumatus
Copy link
Member Author

akumatus commented May 15, 2024

Can you add a test for this case?

@Flrande Thanks for your comments! I have added several tests in tests/code.spec.ts.

@akumatus
Copy link
Member Author

akumatus commented May 15, 2024

Need to test that for legacy data without the wrap field, whether the backward compatibility could be supported.

const defaultProps = schema.model.props?.(internalPrimitives);

const defaultProps = schema.model.props?.(internalPrimitives) ?? {};

@doodlewind I suppose that legacy data will filled with default wrap:false value, because of the above code. But I don't know how to write the test in that case, could you give me a hint?

@Flrande
Copy link
Member

Flrande commented May 15, 2024

Need to test that for legacy data without the wrap field, whether the backward compatibility could be supported.

const defaultProps = schema.model.props?.(internalPrimitives);

@doodlewind I suppose that legacy data will filled with default wrap:false value, because of the above code. But I don't know how to write the test in that case, could you give me a hint?

You can test by importing an old snapshot.

@akumatus
Copy link
Member Author

Need to test that for legacy data without the wrap field, whether the backward compatibility could be supported.

I have tested both import old snapshot and paste old code block cases, and everything works fine!

@donteatfriedrice
Copy link
Member

donteatfriedrice commented May 15, 2024

If we move the wrap property to the model, we may need to disable the wrap code button in code toolbar when readonly mode.

Screen.Recording.2024-05-16.at.01.29.05.mov

@akumatus akumatus force-pushed the fix/code-block-wrap-persistence branch from f97f465 to 0d1daec Compare May 16, 2024 02:59
Copy link
Member

@doodlewind doodlewind left a comment

Choose a reason for hiding this comment

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

LGTM, for the feedback in #7062 (comment), it could be implemented in a standalone PR or simply marked help wanted!

@akumatus
Copy link
Member Author

If we move the wrap property to the model, we may need to disable the wrap code button in code toolbar when readonly mode.

Screen.Recording.2024-05-16.at.01.29.05.mov

Got it! Thanks for your comment, it helps a lot.

Copy link

graphite-app bot commented May 16, 2024

Merge activity

  • May 16, 2:35 AM EDT: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • May 16, 2:35 AM EDT: Saul-Mirone added this pull request to the Graphite merge queue.
  • May 16, 2:44 AM EDT: Saul-Mirone merged this pull request with the Graphite merge queue.

### TL;DR

This Pull Request moves the `wrap` property from temporary state to persistent data model. When user refreshes the web browser, the code block warp style keeps.

Fix affine-design/issue/BS-297.

### What changed?

- In `code-block.ts`, the `_wrap` private state variable has been removed, and all references to it have instead been directed to `this.model.wrap`.
- A `setWrap` function has been added to handle updating the `wrap` property in the block model, which can be persisted in database.

### How to test?

Test this change by creating a code block in document and toggle the `wrap` icon. Check if this modifies the wrap state in the model and updates the UI accordingly. Refresh the browser, the code block warp styles keeps.

<img width="735" alt="截屏2024-05-15 16 03 20" src="https://github.com/toeverything/blocksuite/assets/12724894/4a36124c-9bfb-451a-a1d4-bbc3888f7fa7">

<img width="723" alt="截屏2024-05-15 16 03 02" src="https://github.com/toeverything/blocksuite/assets/12724894/d613f033-038f-4f53-a476-4be87083fd2f">

---
@Saul-Mirone Saul-Mirone force-pushed the fix/code-block-wrap-persistence branch from a03c577 to 3274a6c Compare May 16, 2024 06:36
@graphite-app graphite-app bot merged commit 3274a6c into master May 16, 2024
19 checks passed
@graphite-app graphite-app bot deleted the fix/code-block-wrap-persistence branch May 16, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants