-
-
Notifications
You must be signed in to change notification settings - Fork 756
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 slate RichTextwidget to allow support slate extensions refs#6570 #6586
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fd6a804
fix: add extensions in RichtextWidget refs#6570
nileshgulia1 9c6eb23
fix: add changelog
nileshgulia1 1cd9f34
fix: eslint .
nileshgulia1 e790e36
fix: place changelog in correct place
nileshgulia1 efb6d55
Merge branch 'main' into fix-slateWidget
sneridagh 4fde077
Merge branch 'main' into fix-slateWidget
nileshgulia1 0192de0
fix: also support slate-extensions for HtmlSlateWidget
nileshgulia1 cd3d121
Merge branch 'main' into fix-slateWidget
nileshgulia1 259d605
Update packages/volto-slate/news/6570.bugfix
davisagli b8df923
tests(cypress): add break-list on empty li for htmlSlateWidget
nileshgulia1 0145af2
chore: update changelog
nileshgulia1 9b0580b
Merge branch 'main' into fix-slateWidget
nileshgulia1 1bc8466
Merge branch 'main' into fix-slateWidget
nileshgulia1 5a3dbaf
fix changelog
davisagli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
In `RichTextWidget` and `HtmlSlateWidget`, fix breaking a list by typing Enter. @nileshgulia1 |
67 changes: 67 additions & 0 deletions
67
packages/volto-slate/src/blocks/Text/extensions/breakListInWidget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Editor, Range, Transforms } from 'slate'; | ||
|
||
import config from '@plone/volto/registry'; | ||
import { isCursorAtBlockEnd } from '@plone/volto-slate/utils/selection'; | ||
import { getCurrentListItem } from '@plone/volto-slate/utils/lists'; | ||
import { createEmptyParagraph } from '@plone/volto-slate/utils/blocks'; | ||
|
||
export const breakListInWidget = (editor) => { | ||
const { insertBreak } = editor; | ||
|
||
editor.insertBreak = () => { | ||
if (!(editor.selection && Range.isCollapsed(editor.selection))) { | ||
insertBreak(); | ||
return false; | ||
} | ||
|
||
const { slate } = config.settings; | ||
const { anchor } = editor.selection; | ||
|
||
const ref = Editor.rangeRef(editor, editor.selection, { | ||
affinity: 'inward', | ||
}); | ||
|
||
const [listItem, listItemPath] = getCurrentListItem(editor); | ||
if (listItem) { | ||
if (Editor.string(editor, listItemPath)) { | ||
Transforms.splitNodes(editor, { | ||
at: editor.selection, | ||
match: (node) => node.type === slate.listItemType, | ||
always: true, | ||
}); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
const [parent] = Editor.parent(editor, anchor.path); | ||
|
||
if (parent.type !== slate.listItemType || anchor.offset > 0) { | ||
insertBreak(); | ||
return; | ||
} | ||
|
||
Editor.deleteBackward(editor, { unit: 'line' }); | ||
// also account for empty nodes [{text: ''}] | ||
if (Editor.isEmpty(editor, parent)) { | ||
Transforms.removeNodes(editor, { at: ref.current }); | ||
|
||
Transforms.insertNodes(editor, createEmptyParagraph(), { | ||
at: [editor.children.length], | ||
}); | ||
Transforms.select(editor, Editor.end(editor, [])); | ||
|
||
return true; | ||
} | ||
|
||
Transforms.removeNodes(editor, { at: ref.current }); | ||
|
||
if (isCursorAtBlockEnd(editor)) { | ||
Editor.insertNode(editor, createEmptyParagraph()); | ||
return true; | ||
} | ||
return true; | ||
}; | ||
|
||
return editor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nileshgulia1 Use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test(cypress): fix breaking a list by typing Enter refs- #6586 @nileshgulia1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 fixed the issue with inconsistency, htmlSlateWidget is used as
richtext
and we override this in our policy adddon. Thus, the same extension should be ported here as well.I will write the cypress for this scenario.
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.
-cc @davisagli