-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 delete behaviour when selection ends in void element #3990
Merged
Merged
Changes from 1 commit
Commits
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
Binary file not shown.
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 |
---|---|---|
|
@@ -1265,6 +1265,13 @@ export const Editor = { | |
at: end, | ||
match: n => Editor.isBlock(editor, n), | ||
}) | ||
|
||
// If last element is a void node, unhang range by including void node in range | ||
if (Editor.isVoid(editor, endBlock[0])) { | ||
end = { path: end.path, offset: 1 } | ||
return { anchor: start, focus: end } | ||
} | ||
|
||
const blockPath = endBlock ? endBlock[1] : [] | ||
const first = Editor.start(editor, []) | ||
const before = { anchor: first, focus: end } | ||
|
@@ -1274,7 +1281,7 @@ export const Editor = { | |
at: before, | ||
match: Text.isText, | ||
reverse: true, | ||
voids, | ||
voids: true, | ||
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. I think we might want to leave this as a variable and perhaps change how |
||
})) { | ||
if (skip) { | ||
skip = false | ||
|
40 changes: 40 additions & 0 deletions
40
packages/slate/test/transforms/delete/voids-true/delete-void-and-newline-at-end.tsx
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,40 @@ | ||
/** @jsx jsx */ | ||
import { Editor, Transforms } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<text> | ||
<anchor /> | ||
This is a first paragraph | ||
</text> | ||
</block> | ||
<block> | ||
<text>This is the second paragraph</text> | ||
</block> | ||
<block void> | ||
<text /> | ||
</block> | ||
<block> | ||
<text> | ||
<focus /> | ||
</text> | ||
</block> | ||
</editor> | ||
) | ||
export const run = editor => { | ||
editor.deleteFragment(editor) | ||
} | ||
export const output = ( | ||
<editor> | ||
<block> | ||
<text> | ||
<cursor /> | ||
</text> | ||
</block> | ||
<block> | ||
<text /> | ||
</block> | ||
</editor> | ||
) |
34 changes: 34 additions & 0 deletions
34
packages/slate/test/transforms/delete/voids-true/delete-void-at-end.tsx
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,34 @@ | ||
/** @jsx jsx */ | ||
import { Editor, Transforms } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<text> | ||
<anchor /> | ||
This is a first paragraph | ||
</text> | ||
</block> | ||
<block> | ||
<text>This is the second paragraph</text> | ||
</block> | ||
<block void> | ||
<text> | ||
<focus /> | ||
</text> | ||
</block> | ||
</editor> | ||
) | ||
export const run = editor => { | ||
editor.deleteFragment(editor) | ||
} | ||
export const output = ( | ||
<editor> | ||
<block> | ||
<text> | ||
<cursor /> | ||
</text> | ||
</block> | ||
</editor> | ||
) |
Binary file not shown.
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 am not sure this the best solution. Should we just simply not unhang the range in
Transforms.delete
if the selection end is inside a void node? I think maybe we should handle this inTransforms.delete
vs. changing the default behavior ofunhangRange
? Let's pair on it.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 thought there were some path issues before, but I didn't realize that they're handled further down in
Transforms.delete
. I've moved the end void node handling toTransforms.delete
so that it now skipsunhangRange
. If you think there are still changes that could be made I'm happy to pair. Thanks for the feedback!