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

Move hasRange to core #4191

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dull-kiwis-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'slate': minor
'slate-react': minor
---

Move hasRange to core
2 changes: 1 addition & 1 deletion packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const Editable = (props: EditableProps) => {
// then its children might just change - DOM responds to it on its own
// but Slate's value is not being updated through any operation
// and thus it doesn't transform selection on its own
if (selection && !ReactEditor.hasRange(editor, selection)) {
if (selection && !Editor.hasRange(editor, selection)) {
editor.selection = ReactEditor.toSlateRange(editor, domSelection)
return
}
Expand Down
8 changes: 0 additions & 8 deletions packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { IS_CHROME } from '../utils/environment'
export interface ReactEditor extends BaseEditor {
insertData: (data: DataTransfer) => void
setFragmentData: (data: DataTransfer) => void
hasRange: (editor: ReactEditor, range: Range) => boolean
}

export const ReactEditor = {
Expand Down Expand Up @@ -587,11 +586,4 @@ export const ReactEditor = {

return { anchor, focus }
},

hasRange(editor: ReactEditor, range: Range): boolean {
const { anchor, focus } = range
return (
Editor.hasPath(editor, anchor.path) && Editor.hasPath(editor, focus.path)
)
},
}
13 changes: 13 additions & 0 deletions packages/slate/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface EditorInterface {
hasBlocks: (editor: Editor, element: Element) => boolean
hasInlines: (editor: Editor, element: Element) => boolean
hasPath: (editor: Editor, path: Path) => boolean
hasRange: (editor: Editor, range: Range) => boolean
hasTexts: (editor: Editor, element: Element) => boolean
insertBreak: (editor: Editor) => void
insertFragment: (editor: Editor, fragment: Node[]) => void
Expand Down Expand Up @@ -485,6 +486,18 @@ export const Editor: EditorInterface = {
const fragment = Node.fragment(editor, range)
return fragment
},

/**
* Check if range exists
*/

hasRange(editor: Editor, range: Range): boolean {
const { anchor, focus } = range
return (
Editor.hasPath(editor, anchor.path) && Editor.hasPath(editor, focus.path)
)
},

/**
* Check if a node has block children.
*/
Expand Down