Skip to content

Commit

Permalink
Don't remove selection when hovering over a non-selectable DOM element (
Browse files Browse the repository at this point in the history
#4577)

* Don't remove selection when hovering over a non-selectable node

Fixes #4545

To reproduce the buggy behavior:

1. Create a page that renders a Slate element with a `contentEditable: false` element in it.
2. Start selecting some text with the mouse.
3. During the drag, mouseover the `contentEditable: false` element.

Expected behavior: After doing a drag-to-select with the mouse, from a valid anchor point on mousedown to a valid focus point on mouseup, the selection is set to those anchor and focus points.

Actual behavior: your selection is removed as soon as your mouse hits the `contentEditable: false` element. This is because the current behavior clears the selection if it is momentarily not a valid Slate location.

* Add changeset
  • Loading branch information
jameshfisher authored Oct 12, 2021
1 parent 11ef83b commit 4b2e400
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-timers-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fixed a bug that removed the selection when hovering over a non-selectable DOM element
2 changes: 0 additions & 2 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ export const Editable = (props: EditableProps) => {
exactMatch: false,
})
Transforms.select(editor, range)
} else {
Transforms.deselect(editor)
}
}
}, 100),
Expand Down

0 comments on commit 4b2e400

Please sign in to comment.