Skip to content

Commit 751b1a5

Browse files
Add support for select() imperative method (#576)
2 parents d4bcc5b + 5473f57 commit 751b1a5

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "0.116.0"
3+
"version": "0.116.1-alpha-select.0"
44
}

packages/slate-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prezly/slate-editor",
3-
"version": "0.116.0",
3+
"version": "0.116.1-alpha-select.0",
44
"description": "The Prezly Slate Editor",
55
"license": "MIT",
66
"type": "module",

packages/slate-editor/src/modules/editor/Editor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ export const Editor = forwardRef<EditorRef, EditorProps>((props, forwardedRef) =
323323
EditorCommands.resetNodes(editor, value, editor.selection);
324324
setInitialValue(value);
325325
},
326+
select: (target) => {
327+
Transforms.select(editor, target);
328+
},
326329
}),
327330
);
328331

packages/slate-editor/src/modules/editor/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Events } from '@prezly/events';
22
import type { Decorate, EditorCommands } from '@prezly/slate-commons';
33
import type { Alignment } from '@prezly/slate-types';
44
import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';
5-
import type { Editor, Element, Node } from 'slate';
5+
import type { Editor, Element, Node, Location } from 'slate';
66
import type { Transforms } from 'slate';
77

88
import type { AllowedBlocksExtensionConfiguration } from '#extensions/allowed-blocks';
@@ -72,6 +72,12 @@ export interface EditorRef {
7272
isModified(): boolean;
7373

7474
resetValue(value: Value): void;
75+
76+
/**
77+
* Programmatically set the selection in the editor.
78+
* @param target - The target location for the selection.
79+
*/
80+
select(target: Location): void;
7581
}
7682

7783
export type Value = Element[];

0 commit comments

Comments
 (0)