Mention
Insert a reference to a person or other named item.
mention() adds an inline node with an id, a display label, and a suggestion character that defaults to @. The host supplies the records shown in the picker.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-mentionExample
Section titled “Example”Register the mention picker alongside the paragraph plugin in the Quickstart editor configuration.
use gpdoc::{EditorConfig, PluginViewExt, ViewPlugin};use gpdoc_plugin_mention::{Mention, MentionCatalog, MentionMenu, mention, mention_catalog_picker};use gpdoc_plugin_paragraph::paragraph;
let people = MentionCatalog::new([ Mention::new("user-42", "Ada"), Mention::new("user-57", "Alex"),]);let config = EditorConfig::builder() .plugin(paragraph()) .plugin(mention().with_metadata(people).with_view(people_views)) .build() .expect("configure editor");
fn person_name(person: &Mention) -> String { person.label.as_ref().or(person.id.as_ref()).cloned().unwrap_or_default()}
fn people_views() -> ViewPlugin { mention_catalog_picker(|menu: MentionMenu, _, _| menu.labeled_list(person_name))}Run the app and type @A. Press Down to move from Ada to Alex, then Enter to insert @Alex. The mention stores Alex’s ID, user-57, and the caret lands after a space.
Compose a mention picker and chip
Section titled “Compose a mention picker and chip”Build the picker from a popover, a list, and a row for each match. A separate chip view renders the mention in the document after the user picks a person.
Anatomy
Section titled “Anatomy”mention_catalog_picker(...) Finds matching records in the installed catalogs└── menu.popover(...) Anchors the menu below the caret └── menu.list(6, ...) Shows up to six matches, including the active row └── row.element() Accepts a record on click and keeps editor focus
mention_chip(...) Receives the inserted mention└── div() Your chip inside the measured mention labelAssemble the picker and chip
Section titled “Assemble the picker and chip”In the example above, add the imports below and replace people_views. Put the name inside row.element() so clicking the name accepts the match.
use gpdoc_plugin_mention::mention_chip;use gpui::{div, prelude::*};
fn people_views() -> [ViewPlugin; 2] { let picker = mention_catalog_picker(|menu: MentionMenu, _, _| { let list = menu.list(6, |row| { row.element().child(person_name(row.value)) }); menu.popover(list) });
let chip = mention_chip(|chip, _, _| { div().child(format!("{}{}", chip.trigger(), chip.label())) }); [picker, chip]}Type @Ad and press Enter or click Ada. The picker closes and the chip displays @Ada in the paragraph.
For application-owned search, use mention_picker(search, render) with the same menu renderer. The search function receives the query text and returns a Vec<Mention>.
Settings
Section titled “Settings”delete_trigger
Section titled “delete_trigger”mention() preserves the trigger when Backspace removes a mention. To remove the trigger too, use mention_with_backspace(delete_trigger: bool). The default is false.
let mention = gpdoc_plugin_mention::mention_with_backspace(true);Commands
Section titled “Commands”acceptMention
Section titled “acceptMention”Replaces the active query with a mention and one space. The caret must be at the end of the query. The default trigger matches at the start of the text or after a space. Use the Suggestion helper to match the query while your picker is open.
use gpdoc_plugin_mention::{Accept, Mention};
editor.run(Accept(Mention::new("user-42", "Ada")))?;The optional strings id and label both default to null. The view displays the trigger followed by the label, falling back to the ID. To accept a query beginning with another character, set the Mention::trigger field. Its default is '@'. The serialized attribute is mentionSuggestionChar.
deleteMentionBackward
Section titled “deleteMentionBackward”With a caret immediately after a mention, replaces that mention with its trigger or deletes it according to delete_trigger. Takes no arguments. Both mention commands return CommandOutcome::NotApplicable if the selection does not meet their requirements.
editor.run(gpdoc_plugin_mention::DeleteBackward)?;Keyboard shortcuts
Section titled “Keyboard shortcuts”| Shortcut | Command |
|---|---|
| Backspace | deleteMentionBackward |