Skip to content
gpdoc
Playground

Floating menu

Show a menu at the caret in an empty top-level paragraph.

Click at the end of “Meeting notes” and press Enter. The menu appears above the empty paragraph. Type a word to dismiss it.

Terminal window
cargo add gpdoc-plugin-floating-menu gpdoc-plugin-heading

Attach a renderer to show a menu at the caret in an empty top-level paragraph in the Quickstart editor.

use gpdoc::{EditorConfig, EditorView};
use gpdoc_plugin_heading::heading;
use gpdoc_plugin_floating_menu::floating_menu;
use gpdoc_plugin_paragraph::paragraph;
use gpui::{App, Div, Entity, Window, div, prelude::*};
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(heading())
.plugin(floating_menu().with_view(insert_menu))
.build()
.expect("configure editor");
fn insert_menu(_: Entity<EditorView>, _: &mut Window, _: &mut App) -> Div {
div().child("Insert a block")
}

Press Enter at the end of a top-level paragraph to see Insert a block.

The plugin opens the menu for the config’s default text block and keeps focus in the editor while you click its controls.

floating_menu().with_view(...) Positions the menu at the caret in an empty top-level paragraph
└── div().id(...) Runs an editor command on click

Replace insert_menu with a button that runs the Heading plugin’s command on the same editor.

use gpdoc_plugin_heading::{Level, Set};
use gpui::Stateful;
fn insert_menu(editor: Entity<EditorView>, _: &mut Window, _: &mut App) -> Stateful<Div> {
div()
.id("floating_menu-heading")
.child("Heading 2")
.on_click(move |_, window, cx| {
editor.update(cx, |view, cx| {
view.run(Set(Level::H2), window, cx).expect("set heading");
});
})
}

Create an empty paragraph and click Heading 2. The menu closes and you can type the heading.

See Bubble menu for controls above selected content.

floating-menu/src/lib.rs