From f094c7547c580932508fe6b63d99c1c11156913c Mon Sep 17 00:00:00 2001 From: Tima Gixe Date: Sun, 26 Nov 2023 15:07:36 +0200 Subject: [PATCH 1/3] fix: adjust edge on collapse RTL selection --- packages/slate-react/src/components/editable.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index b2cae4d98a..b28fd39b78 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -1501,7 +1501,7 @@ 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 @@ -1513,7 +1513,7 @@ 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 From 9e8ba4fffb0f63d0001e066db7746660d430b110 Mon Sep 17 00:00:00 2001 From: Tima Gixe Date: Sun, 26 Nov 2023 15:17:37 +0200 Subject: [PATCH 2/3] style: fix linting issue --- packages/slate-react/src/components/editable.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index b28fd39b78..9a3939f6fb 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -1501,7 +1501,9 @@ export const Editable = (props: EditableProps) => { if (selection && Range.isCollapsed(selection)) { Transforms.move(editor, { reverse: !isRTL }) } else { - Transforms.collapse(editor, { edge: isRTL ? 'end' : 'start' }) + Transforms.collapse(editor, { + edge: isRTL ? 'end' : 'start', + }) } return @@ -1513,7 +1515,9 @@ export const Editable = (props: EditableProps) => { if (selection && Range.isCollapsed(selection)) { Transforms.move(editor, { reverse: isRTL }) } else { - Transforms.collapse(editor, { edge: isRTL ? 'start' : 'end' }) + Transforms.collapse(editor, { + edge: isRTL ? 'start' : 'end', + }) } return From 4c844e4d35bca97677456d69837c5a9e40e7d030 Mon Sep 17 00:00:00 2001 From: Tima Gixe Date: Sun, 26 Nov 2023 15:23:53 +0200 Subject: [PATCH 3/3] chore: add changeset --- .changeset/unlucky-paws-allow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-paws-allow.md diff --git a/.changeset/unlucky-paws-allow.md b/.changeset/unlucky-paws-allow.md new file mode 100644 index 0000000000..1b06c0a257 --- /dev/null +++ b/.changeset/unlucky-paws-allow.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Fix cursor position on selection collapse for RTL direction