@@ -1814,34 +1814,34 @@ impl Editor {
this
}
- fn dispatch_context(&self, cx: &AppContext) -> KeyContext {
- let mut dispatch_context = KeyContext::default();
- dispatch_context.add("Editor");
+ fn key_context(&self, cx: &AppContext) -> KeyContext {
+ let mut key_context = KeyContext::default();
+ key_context.add("Editor");
let mode = match self.mode {
EditorMode::SingleLine => "single_line",
EditorMode::AutoHeight { .. } => "auto_height",
EditorMode::Full => "full",
};
- dispatch_context.set("mode", mode);
+ key_context.set("mode", mode);
if self.pending_rename.is_some() {
- dispatch_context.add("renaming");
+ key_context.add("renaming");
}
if self.context_menu_visible() {
match self.context_menu.read().as_ref() {
Some(ContextMenu::Completions(_)) => {
- dispatch_context.add("menu");
- dispatch_context.add("showing_completions")
+ key_context.add("menu");
+ key_context.add("showing_completions")
}
Some(ContextMenu::CodeActions(_)) => {
- dispatch_context.add("menu");
- dispatch_context.add("showing_code_actions")
+ key_context.add("menu");
+ key_context.add("showing_code_actions")
}
None => {}
}
}
for layer in self.keymap_context_layers.values() {
- dispatch_context.extend(layer);
+ key_context.extend(layer);
}
if let Some(extension) = self
@@ -1850,10 +1850,10 @@ impl Editor {
.as_singleton()
.and_then(|buffer| buffer.read(cx).file()?.path().extension()?.to_str())
{
- dispatch_context.set("extension", extension.to_string());
+ key_context.set("extension", extension.to_string());
}
- dispatch_context
+ key_context
}
pub fn new_file(
@@ -275,36 +275,48 @@ impl EditorElement {
register_action(view, cx, Editor::copy_relative_path);
register_action(view, cx, Editor::copy_highlight_json);
register_action(view, cx, |editor, action, cx| {
- editor
- .format(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.format(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, Editor::restart_language_server);
register_action(view, cx, Editor::show_character_palette);
register_action(view, cx, |editor, action, cx| {
- editor
- .confirm_completion(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.confirm_completion(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, |editor, action, cx| {
- editor
- .confirm_code_action(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.confirm_code_action(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, |editor, action, cx| {
- editor
- .rename(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.rename(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, |editor, action, cx| {
- editor
- .confirm_rename(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.confirm_rename(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, |editor, action, cx| {
- editor
- .find_all_references(action, cx)
- .map(|task| task.detach_and_log_err(cx));
+ if let Some(task) = editor.find_all_references(action, cx) {
+ task.detach_and_log_err(cx);
+ } else {
+ cx.propagate();
+ }
});
register_action(view, cx, Editor::next_copilot_suggestion);
register_action(view, cx, Editor::previous_copilot_suggestion);
@@ -2802,49 +2814,38 @@ impl Element for EditorElement {
};
let focus_handle = editor.focus_handle(cx);
- let dispatch_context = self.editor.read(cx).dispatch_context(cx);
- cx.with_key_dispatch(
- Some(dispatch_context),
- Some(focus_handle.clone()),
- |_, cx| {
- self.register_actions(cx);
- self.register_key_listeners(cx);
-
- // We call with_z_index to establish a new stacking context.
- cx.with_z_index(0, |cx| {
- cx.with_content_mask(Some(ContentMask { bounds }), |cx| {
- // Paint mouse listeners at z-index 0 so any elements we paint on top of the editor
- // take precedence.
- cx.with_z_index(0, |cx| {
- self.paint_mouse_listeners(
- bounds,
- gutter_bounds,
- text_bounds,
- &layout,
- cx,
- );
- });
- let input_handler =
- ElementInputHandler::new(bounds, self.editor.clone(), cx);
- cx.handle_input(&focus_handle, input_handler);
+ let key_context = self.editor.read(cx).key_context(cx);
+ cx.with_key_dispatch(Some(key_context), Some(focus_handle.clone()), |_, cx| {
+ self.register_actions(cx);
+ self.register_key_listeners(cx);
+
+ // We call with_z_index to establish a new stacking context.
+ cx.with_z_index(0, |cx| {
+ cx.with_content_mask(Some(ContentMask { bounds }), |cx| {
+ // Paint mouse listeners at z-index 0 so any elements we paint on top of the editor
+ // take precedence.
+ cx.with_z_index(0, |cx| {
+ self.paint_mouse_listeners(bounds, gutter_bounds, text_bounds, &layout, cx);
+ });
+ let input_handler = ElementInputHandler::new(bounds, self.editor.clone(), cx);
+ cx.handle_input(&focus_handle, input_handler);
- self.paint_background(gutter_bounds, text_bounds, &layout, cx);
- if layout.gutter_size.width > Pixels::ZERO {
- self.paint_gutter(gutter_bounds, &mut layout, cx);
- }
- self.paint_text(text_bounds, &mut layout, cx);
+ self.paint_background(gutter_bounds, text_bounds, &layout, cx);
+ if layout.gutter_size.width > Pixels::ZERO {
+ self.paint_gutter(gutter_bounds, &mut layout, cx);
+ }
+ self.paint_text(text_bounds, &mut layout, cx);
- if !layout.blocks.is_empty() {
- cx.with_z_index(1, |cx| {
- cx.with_element_id(Some("editor_blocks"), |cx| {
- self.paint_blocks(bounds, &mut layout, cx);
- })
+ if !layout.blocks.is_empty() {
+ cx.with_z_index(1, |cx| {
+ cx.with_element_id(Some("editor_blocks"), |cx| {
+ self.paint_blocks(bounds, &mut layout, cx);
})
- }
- });
+ })
+ }
});
- },
- )
+ });
+ })
}
}