# Focus

> Highlight the block containing the selection anchor while the editor has focus.

## Try it

Click either quoted paragraph. The highlight follows the paragraph containing the caret.

[Focus example](https://gpdoc.dev/docs/plugins/behavior/focus/#focus-example)

## Install

```sh
cargo add gpdoc-plugin-focus
```

## Example

```rust
use gpdoc_plugin_focus::{FocusMode, focus, paint_focus};
use gpdoc_plugin_paragraph::paragraph;


let config = gpdoc::EditorConfig::builder()
    .plugin(paragraph())
    .plugin(focus(FocusMode::Deepest).with_view(paint_focus))
    .build()
    .expect("configure editor");
```

Pass your own painter to `.with_view(...)` to change the appearance. It receives the selected block’s bounds, window, and app. With `FocusMode::All`, the plugin calls it once for each visible enclosing block.

Place the caret in a paragraph inside a blockquote. `FocusMode::Deepest` highlights the paragraph. Use `Shallowest` for the outermost enclosing block or `All` to paint each enclosing block. Moving focus out of the editor hides the highlight.

## Source code

[focus/src/lib.rs](/source/plugins/focus/src/lib.rs.txt)