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(blocks): unexpected newline appears while pasting multiply-paragr… #8154

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

raintoway
Copy link
Contributor

…aph-blocks to code-block

issue

effect as follow

7

Copy link

changeset-bot bot commented Sep 4, 2024

⚠️ No Changeset found

Latest commit: 0e605b3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 4, 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 Sep 4, 2024 11:48am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Sep 4, 2024 11:48am

Copy link

graphite-app bot commented Sep 4, 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.

Copy link

nx-cloud bot commented Sep 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 0e605b3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@@ -232,6 +232,7 @@ export class PlainTextAdapter extends BaseAdapter<PlainText> {
return null;
}
payload.file = payload.file.replaceAll('\r', '');
payload.file = payload.file.replace(/\n$/, '');
Copy link
Contributor

@L-Sun L-Sun Sep 5, 2024

Choose a reason for hiding this comment

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

I think the reason is in the exporter side, not here. @fourdim cc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i think so too , here is the export side in /packages/blocks/src/_common/adapters/plain-text.ts

  private async _traverseSnapshot(
    snapshot: BlockSnapshot
  ): Promise<{ mixtext: string }> {
    ...
    walker.setEnter(o => {
      const text = (o.node.props.text ?? { delta: [] }) as {
        delta: DeltaInsert[];
      };
      switch (o.node.flavour) {
        ...
        case 'affine:paragraph': {
          buffer += text.delta.map(delta => delta.insert).join('');
          buffer += '\n';
          break;
        }
 ...

but i think change here will affect a lot , so i only change the adapter

Copy link
Contributor

Choose a reason for hiding this comment

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

No, changing this adapter will affect a lot.

It's not about adding an extra newline at the end of a file, it's about not removing the newline that should be there.

The C standard specifies that a C file should end with a newline (C11, 5.1.1.2, 2.) and that a last line without a newline yields undefined behavior (C11, J.2, 2nd item).

https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file

@L-Sun L-Sun requested a review from fourdim September 5, 2024 07:11
@@ -232,6 +232,7 @@ export class PlainTextAdapter extends BaseAdapter<PlainText> {
return null;
}
payload.file = payload.file.replaceAll('\r', '');
payload.file = payload.file.replace(/\n$/, '');
Copy link
Contributor

Choose a reason for hiding this comment

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

No, changing this adapter will affect a lot.

It's not about adding an extra newline at the end of a file, it's about not removing the newline that should be there.

The C standard specifies that a C file should end with a newline (C11, 5.1.1.2, 2.) and that a last line without a newline yields undefined behavior (C11, J.2, 2nd item).

https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants