# Invisible characters

> Display markers for spaces, line breaks, and paragraph ends.

## Try it

Click after “Two words” and press **Space** to add a space marker. Press **Enter** to see a new paragraph end.

[Invisible characters example](https://gpdoc.dev/docs/plugins/behavior/invisible-characters/#invisible-characters-example)

## Install

```sh
cargo add gpdoc-plugin-invisible-characters
```

## Example

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_invisible_characters::{character_markers, invisible_characters, paint_marker};
use gpdoc_plugin_paragraph::paragraph;


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(invisible_characters(true).with_view(|| character_markers(paint_marker)))
    .build()
    .expect("configure editor");
```

The document plugin stores visibility for each editor. Pass `true` to show markers when the editor opens, or `false` to start with them hidden. The view paints the markers over the document.

Run `toggleInvisibleCharacters` to switch visibility. Use `showInvisibleCharacters` or `hideInvisibleCharacters` to set it explicitly. These commands preserve the document’s text.

## Compose character markers

### Anatomy

```text
invisible_characters(true).with_view(...)  Starts with the markers visible
└── character_markers(...)                 Calls your painter for each visible marker
    ├── marker.kind                        Space, LineBreak, or ParagraphEnd
    └── marker.bounds                      Where to paint the glyph
```

### Show only paragraph ends

Pass `paragraph_end` to `character_markers` in the example. Use the marker kind to choose which glyphs reach the default painter.

```rust
use gpdoc::DecorationFrame;
use gpdoc_plugin_invisible_characters::{CharacterMarker, MarkerKind};
use gpui::{App, Window};


fn paragraph_end(marker: CharacterMarker, frame: &DecorationFrame<'_>, window: &mut Window, cx: &mut App) {
    if marker.kind == MarkerKind::ParagraphEnd {
        paint_marker(marker, frame, window, cx);
    }
}
```

Type two words separated by a space and press **Enter**. A **¶** appears at the end of each paragraph.

## Source code

[invisible-characters/src/lib.rs](/source/plugins/invisible-characters/src/lib.rs.txt)