Skip to content

Commit

Permalink
Add support for select() imperative method
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadxali committed Dec 20, 2024
1 parent d4bcc5b commit c8118ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/slate-editor/src/modules/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ export const Editor = forwardRef<EditorRef, EditorProps>((props, forwardedRef) =
EditorCommands.resetNodes(editor, value, editor.selection);
setInitialValue(value);
},
select: (target) => {
Transforms.select(editor, target);
},
}),
);

Expand Down
8 changes: 7 additions & 1 deletion packages/slate-editor/src/modules/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Events } from '@prezly/events';
import type { Decorate, EditorCommands } from '@prezly/slate-commons';
import type { Alignment } from '@prezly/slate-types';
import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';
import type { Editor, Element, Node } from 'slate';
import type { Editor, Element, Node, Location } from 'slate';
import type { Transforms } from 'slate';

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

resetValue(value: Value): void;

/**
* Programmatically set the selection in the editor.
* @param target - The target location for the selection.
*/
select(target: Location): void;
}

export type Value = Element[];
Expand Down

0 comments on commit c8118ed

Please sign in to comment.