The menu builder runs while the editor is mid-update, where reading its state panics, so the real menu is built and shown on the next tick.
Showing 1 changed file with 11 additions and 1 deletion.
| @@ -251,7 +251,17 @@ impl RenderOnce for MarkdownInput { | ||
| 251 | 251 | Editor::new(&self.state) |
| 252 | 252 | .appearance(false) |
| 253 | 253 | .h(line_height * rows as f32 + px(PADDING_Y * 2.)) |
| 254 | - .context_menu(move |menu, _, cx| context_menu(&menu_state, menu, cx)) | |
| 254 | + .context_menu(move |menu, window, cx| { | |
| 255 | + // The builder runs while the editor is mid-update, where | |
| 256 | + // reading its state panics, so the real menu waits a tick | |
| 257 | + // and the empty one returned here shows nothing. | |
| 258 | + let state = menu_state.clone(); | |
| 259 | + window.defer(cx, move |window, cx| { | |
| 260 | + let position = window.mouse_position(); | |
| 261 | + context_menu(&state, NativeMenu::new(), cx).show(position, window, cx); | |
| 262 | + }); | |
| 263 | + menu | |
| 264 | + }) | |
| 255 | 265 | .font_family(metal::SANS) |
| 256 | 266 | .text_size(rems(0.875)) |
| 257 | 267 | .line_height(rems(1.25)) |