Skip to content

Commit

Permalink
Adjust cursor position when on selection collapse for RTL direction (#…
Browse files Browse the repository at this point in the history
…5567)

* fix: adjust edge on collapse RTL selection

* style: fix linting issue

* chore: add changeset
  • Loading branch information
timagixe authored Nov 30, 2023
1 parent 0312531 commit 07f59e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-paws-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fix cursor position on selection collapse for RTL direction
8 changes: 6 additions & 2 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,9 @@ export const Editable = (props: EditableProps) => {
if (selection && Range.isCollapsed(selection)) {
Transforms.move(editor, { reverse: !isRTL })
} else {
Transforms.collapse(editor, { edge: 'start' })
Transforms.collapse(editor, {
edge: isRTL ? 'end' : 'start',
})
}

return
Expand All @@ -1513,7 +1515,9 @@ export const Editable = (props: EditableProps) => {
if (selection && Range.isCollapsed(selection)) {
Transforms.move(editor, { reverse: isRTL })
} else {
Transforms.collapse(editor, { edge: 'end' })
Transforms.collapse(editor, {
edge: isRTL ? 'start' : 'end',
})
}

return
Expand Down

0 comments on commit 07f59e3

Please sign in to comment.