Floating menu
Show a menu at the caret in an empty top-level paragraph.
Try it
Section titled “Try it”Click at the end of “Meeting notes” and press Enter. The menu appears above the empty paragraph. Type a word to dismiss it.
Install
Section titled “Install”cargo add gpdoc-plugin-floating-menu gpdoc-plugin-headingExample
Section titled “Example”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.
Compose a floating menu
Section titled “Compose a floating menu”The plugin opens the menu for the config’s default text block and keeps focus in the editor while you click its controls.
Anatomy
Section titled “Anatomy”floating_menu().with_view(...) Positions the menu at the caret in an empty top-level paragraph└── div().id(...) Runs an editor command on clickTurn the paragraph into a heading
Section titled “Turn the paragraph into a heading”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.