2021-04-21 17:03:33 +08:00
# focus
2021-05-28 03:37:47 +08:00
This command sets the focus back to the editor.
2021-04-21 17:03:33 +08:00
2021-05-28 03:37:47 +08:00
When a user clicks on a button outside the editor, the browser sets the focus to that button. In most scenarios you want to focus the editor then again. That’ s why you’ ll see that in basically every demo here.
2021-06-23 03:28:20 +08:00
See also: [setTextSelection ](/api/commands/set-text-selection ), [blur ](/api/commands/blur )
2021-05-28 03:37:47 +08:00
## Parameters
2021-11-22 17:17:06 +08:00
`position: 'start' | 'end' | 'all' | number | boolean | null (false)`
2021-05-28 03:37:47 +08:00
By default, it’ s restoring the cursor position (and text selection). Pass a position to move the cursor too.
2021-05-27 16:53:34 +08:00
2022-02-03 17:15:34 +08:00
`options: { scrollIntoView: boolean }`
2021-11-26 00:18:30 +08:00
Defines whether to scroll to the cursor when focusing. Defaults to `true` .
2021-05-27 16:53:34 +08:00
## Usage
```js
// Set the focus to the editor
editor.commands.focus()
// Set the cursor to the first position
editor.commands.focus('start')
// Set the cursor to the last position
editor.commands.focus('end')
2021-05-28 03:37:47 +08:00
2021-11-22 17:17:06 +08:00
// Selects the whole document
editor.commands.focus('all')
2021-05-28 03:37:47 +08:00
// Set the cursor to position 10
editor.commands.focus(10)
2021-05-27 16:53:34 +08:00
```