-
-
Notifications
You must be signed in to change notification settings - Fork 788
Fixed issue of merging block contents upon pressing backspace at start of second block with some content #7373
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new line to the previous paragraph. The expectation here is that the second paragraph will be added to the end of the previous paragraph, without adding a new line.
@wesleybl Thanks for pointing this out. It is fixed in the latest commit. Now merging happens Inline without adding a new line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the merge, the cursor must be before the first character of the second paragraph.
Fixed, the Cursor is now placed before the first character of the second paragraph. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a Changes entry: https://6.docs.plone.org/volto/contributing/index.html#change-log-entry
and fix the lint errors: https://6.docs.plone.org/volto/contributing/linting.html#linting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I press Backspace and then Enter, the content that was originally in the second paragraph remains in the first paragraph.
…o a new block. Added changelog entry and fixed lint issues
@wesleybl PR updated:
|
@aryan7081 You also need a changelog file in packages/volto/news since you added the cypress test there. Use the extension .internal for that one since the change there is not a user-facing change. |
@davisagli Thanks for the guidance! I’ve added the internal changelog for the Cypress test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I positioned the cursor before the first character of a paragraph. Then I pressed Enter several times. When I press backspace once, it removed the previous block. But after that, I had to press backspace twice to remove the remaining blocks.
@@ -0,0 +1 @@ | |||
Fix Backspace at start of a text block: merge current block into previous inline (no extra newline), delete the current block, and place the caret before the first character of the merged content. Also handle Enter immediately after such inline merge by splitting back into two blocks. (@aryan7081) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally do not put the author's name in parentheses.
@wesleybl I have removed the author's name from the changelog entry and fixed the issue of pressing backspace twice to remove the remaining blocks. |
@@ -0,0 +1 @@ | |||
Fix Backspace at start of a text block: merge current block into previous inline (no extra newline), delete the current block, and place the caret before the first character of the merged content. Also handle Enter immediately after such inline merge by splitting back into two blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add your username in the note.
|
||
// Else the editor contains characters, so we merge the current block's | ||
// `editor` with the block before, `otherBlock`. | ||
const cursor = mergeSlateWithBlockBackward(editor, otherBlock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why weren't the changes made to mergeSlateWithBlockBackward
? Have you considered whether the code there is needed? Even if it isn't needed, the implementation can be done there to make the code more modular and separate. mergeSlateWithBlockBackward
is only used here.
packages/volto/news/7373.internal
Outdated
@@ -0,0 +1 @@ | |||
Added Cypress test for backspace behavior in slate blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add your username in the note.
…g instead of custom merging logic
@wesleybl Thanks, I investigated and found that |
export * from './unwrapEmptyString'; | ||
export * from './slashMenu'; | ||
export * from './cancelEsc'; | ||
export * from './splitAtSeam'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use barrel import. Remove this line and import the full path.
@wesleybl I have replaced barrel import with direct module import. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@wesleybl May I know the reason why you have edited the pr description from Fixes |
@aryan7081 It's because this PR doesn't fix #7263. They are similar but not the same situations. |
@wesleybl Okay, got it. Thanks for the clarification. |
Ref #7263
Inside the
joinWithPreviousBlock
function ofpackages/volto-slate/src/blocks/Text/keyboard/joinBlocks.js
, pressing Backspace (Delete on mac) at the start of a block incorrectly merged the previous block's content into the current block, instead of merging the current block into previous one.This happened because the implementation relied on
mergeSlateWithBlockBackward(editor, otherBlock)
which altered the current block's editor slate causing the wrong merge direction.This fix removes the dependency and explicitly appends the current block's children (
editor.children
) into the previous block's value, then deletes the current block.