mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-09 02:44:49 +00:00
Fix confirming rename not working on editor2 (#3532)
Release Notes: - N/A
This commit is contained in:
commit
2c2c633104
2 changed files with 71 additions and 70 deletions
|
@ -1814,34 +1814,34 @@ impl Editor {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_context(&self, cx: &AppContext) -> KeyContext {
|
fn key_context(&self, cx: &AppContext) -> KeyContext {
|
||||||
let mut dispatch_context = KeyContext::default();
|
let mut key_context = KeyContext::default();
|
||||||
dispatch_context.add("Editor");
|
key_context.add("Editor");
|
||||||
let mode = match self.mode {
|
let mode = match self.mode {
|
||||||
EditorMode::SingleLine => "single_line",
|
EditorMode::SingleLine => "single_line",
|
||||||
EditorMode::AutoHeight { .. } => "auto_height",
|
EditorMode::AutoHeight { .. } => "auto_height",
|
||||||
EditorMode::Full => "full",
|
EditorMode::Full => "full",
|
||||||
};
|
};
|
||||||
dispatch_context.set("mode", mode);
|
key_context.set("mode", mode);
|
||||||
if self.pending_rename.is_some() {
|
if self.pending_rename.is_some() {
|
||||||
dispatch_context.add("renaming");
|
key_context.add("renaming");
|
||||||
}
|
}
|
||||||
if self.context_menu_visible() {
|
if self.context_menu_visible() {
|
||||||
match self.context_menu.read().as_ref() {
|
match self.context_menu.read().as_ref() {
|
||||||
Some(ContextMenu::Completions(_)) => {
|
Some(ContextMenu::Completions(_)) => {
|
||||||
dispatch_context.add("menu");
|
key_context.add("menu");
|
||||||
dispatch_context.add("showing_completions")
|
key_context.add("showing_completions")
|
||||||
}
|
}
|
||||||
Some(ContextMenu::CodeActions(_)) => {
|
Some(ContextMenu::CodeActions(_)) => {
|
||||||
dispatch_context.add("menu");
|
key_context.add("menu");
|
||||||
dispatch_context.add("showing_code_actions")
|
key_context.add("showing_code_actions")
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for layer in self.keymap_context_layers.values() {
|
for layer in self.keymap_context_layers.values() {
|
||||||
dispatch_context.extend(layer);
|
key_context.extend(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(extension) = self
|
if let Some(extension) = self
|
||||||
|
@ -1850,10 +1850,10 @@ impl Editor {
|
||||||
.as_singleton()
|
.as_singleton()
|
||||||
.and_then(|buffer| buffer.read(cx).file()?.path().extension()?.to_str())
|
.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(
|
pub fn new_file(
|
||||||
|
|
|
@ -275,36 +275,48 @@ impl EditorElement {
|
||||||
register_action(view, cx, Editor::copy_relative_path);
|
register_action(view, cx, Editor::copy_relative_path);
|
||||||
register_action(view, cx, Editor::copy_highlight_json);
|
register_action(view, cx, Editor::copy_highlight_json);
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.format(action, cx) {
|
||||||
.format(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, Editor::restart_language_server);
|
register_action(view, cx, Editor::restart_language_server);
|
||||||
register_action(view, cx, Editor::show_character_palette);
|
register_action(view, cx, Editor::show_character_palette);
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.confirm_completion(action, cx) {
|
||||||
.confirm_completion(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.confirm_code_action(action, cx) {
|
||||||
.confirm_code_action(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.rename(action, cx) {
|
||||||
.rename(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.confirm_rename(action, cx) {
|
||||||
.confirm_rename(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
editor
|
if let Some(task) = editor.find_all_references(action, cx) {
|
||||||
.find_all_references(action, cx)
|
task.detach_and_log_err(cx);
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
register_action(view, cx, Editor::next_copilot_suggestion);
|
register_action(view, cx, Editor::next_copilot_suggestion);
|
||||||
register_action(view, cx, Editor::previous_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 focus_handle = editor.focus_handle(cx);
|
||||||
let dispatch_context = self.editor.read(cx).dispatch_context(cx);
|
let key_context = self.editor.read(cx).key_context(cx);
|
||||||
cx.with_key_dispatch(
|
cx.with_key_dispatch(Some(key_context), Some(focus_handle.clone()), |_, cx| {
|
||||||
Some(dispatch_context),
|
self.register_actions(cx);
|
||||||
Some(focus_handle.clone()),
|
self.register_key_listeners(cx);
|
||||||
|_, cx| {
|
|
||||||
self.register_actions(cx);
|
|
||||||
self.register_key_listeners(cx);
|
|
||||||
|
|
||||||
// We call with_z_index to establish a new stacking context.
|
// We call with_z_index to establish a new stacking context.
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(0, |cx| {
|
||||||
cx.with_content_mask(Some(ContentMask { bounds }), |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
|
// Paint mouse listeners at z-index 0 so any elements we paint on top of the editor
|
||||||
// take precedence.
|
// take precedence.
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(0, |cx| {
|
||||||
self.paint_mouse_listeners(
|
self.paint_mouse_listeners(bounds, gutter_bounds, text_bounds, &layout, cx);
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue