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

blockSeperator in getTextBetween, will return double new line characters when call editor.getText() #3369

Closed
1 of 2 tasks
Matrixbirds opened this issue Oct 29, 2022 · 7 comments
Labels
Info: Stale The issue or pullrequest has not been updated in a while and might be stale Type: Bug The issue or pullrequest is related to a bug

Comments

@Matrixbirds
Copy link
Contributor

What’s the bug you are facing?

I'd like to custom shortcut key with 'Enter'. When keypress Enter, it should splitBlock instead of using hardBreak to append
in the current element:

.

Which browser was this experienced in? Are any special extensions installed?

Chromium 107.0.5304.87 (Official Build) (arm64)
Offical Github repo. commit id: bbf0803

Node version:
LTS
macOS
My setup scripts

npm install
npm run start

How can we reproduce the bug on our side?

Step 1. Typing any character as below.

// typing in content editor
abcdefg

Step 2. RunsplitBlock by editor instance, then <p> tag in will be forked.

editor.splitBlock({keepMarks: false}).focus().scrollIntoView().run();

Step 3. Keep typing any characters like this.

// typing in content editor
abcdefg
hijkl

Step 4. Check the content editor html structure.

<p>abcedfg</p>
<p>hijkl</p>

It looks like two paragraph element and it did correct when call editor.getJSON() then return value only contain two paragraph items.
But the editor.getText() will return abcedfg\n\nhijkl.

I'm digging in the implementation of getText. I find there is the code will serialize textNodes and it will add blockSeparator = \n\n. I don't know the blockSeparator works for what. But If we can modify assign as \n. Maybe it works for me.

Can you provide a CodeSandbox?

No response

What did you expect to happen?

The getText method should return single newline character whenever item has been splitBlock.
So In this case: editor.getText should return return abcedfg\nhijkl.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@Matrixbirds Matrixbirds added the Type: Bug The issue or pullrequest is related to a bug label Oct 29, 2022
@Matrixbirds Matrixbirds changed the title Customize Shortcut Enter key with splitBlock, call getText return double newline characters, like '\n\n' blockSeperator in getTextBetween, will return double new line characters when call editor.getText() Oct 29, 2022
@github-actions
Copy link
Contributor

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label Jan 28, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2023
@HZZformGD
Copy link

i have the same confusion, why?

// typing in content editor
abcdefg
hijkl
// break 1
// break 2
// break 3

when editor.getText() it will return abcedfg\n\nhijkl\n\n
what i want is abcedfg\nhijkl\n\n\n

@J-Yaleen
Copy link

any update?

@tecoad
Copy link

tecoad commented Nov 7, 2023

Same for me.

@hivokas
Copy link
Contributor

hivokas commented Apr 11, 2024

@Matrixbirds @HZZformGD @J-Yaleen @tecoad you can use editor.getText({ blockSeparator: '\n' }); to override default blockSeparator.

@hivokas
Copy link
Contributor

hivokas commented Apr 11, 2024

I've submitted #5055 PR that tweaks getTextBetween to prepend blockSeparator to block node even if block node doesn't have any children (it means empty paragraphs won't be ignored like in @HZZformGD's comment).

@Matrixbirds @HZZformGD @J-Yaleen @tecoad

@luckrnx09
Copy link

@Matrixbirds @HZZformGD @J-Yaleen @tecoad you can use editor.getText({ blockSeparator: '\n' }); to override default blockSeparator.

It works for me! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Info: Stale The issue or pullrequest has not been updated in a while and might be stale Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

6 participants