mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 10:40:54 +00:00
Convert some actions to use named fields
Co-authored-by: Nathan Sobo <nathan@zed.dev> Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
parent
5242a3a6dc
commit
c801a52492
3 changed files with 82 additions and 30 deletions
|
@ -85,10 +85,14 @@ pub struct Input(pub String);
|
|||
pub struct Tab(pub Direction);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SelectToBeginningOfLine(pub bool);
|
||||
pub struct SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SelectToEndOfLine(pub bool);
|
||||
pub struct SelectToEndOfLine {
|
||||
stop_at_soft_wraps: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ToggleCodeActions(pub bool);
|
||||
|
@ -301,7 +305,9 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
Binding::new("alt-shift-F", SelectToNextWordEnd, Some("Editor")),
|
||||
Binding::new(
|
||||
"cmd-shift-left",
|
||||
SelectToBeginningOfLine(true),
|
||||
SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
Some("Editor"),
|
||||
),
|
||||
Binding::new(
|
||||
|
@ -312,11 +318,25 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
Binding::new("ctrl-alt-shift-F", SelectToNextSubwordEnd, Some("Editor")),
|
||||
Binding::new(
|
||||
"ctrl-shift-A",
|
||||
SelectToBeginningOfLine(true),
|
||||
SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
Some("Editor"),
|
||||
),
|
||||
Binding::new(
|
||||
"cmd-shift-right",
|
||||
SelectToEndOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
Some("Editor"),
|
||||
),
|
||||
Binding::new(
|
||||
"ctrl-shift-E",
|
||||
SelectToEndOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
Some("Editor"),
|
||||
),
|
||||
Binding::new("cmd-shift-right", SelectToEndOfLine(true), Some("Editor")),
|
||||
Binding::new("ctrl-shift-E", SelectToEndOfLine(true), Some("Editor")),
|
||||
Binding::new("cmd-shift-up", SelectToBeginning, Some("Editor")),
|
||||
Binding::new("cmd-shift-down", SelectToEnd, Some("Editor")),
|
||||
Binding::new("cmd-a", SelectAll, Some("Editor")),
|
||||
|
@ -3905,12 +3925,12 @@ impl Editor {
|
|||
|
||||
pub fn select_to_beginning_of_line(
|
||||
&mut self,
|
||||
SelectToBeginningOfLine(stop_at_soft_boundaries): &SelectToBeginningOfLine,
|
||||
action: &SelectToBeginningOfLine,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.move_selection_heads(cx, |map, head, _| {
|
||||
(
|
||||
movement::line_beginning(map, head, *stop_at_soft_boundaries),
|
||||
movement::line_beginning(map, head, action.stop_at_soft_wraps),
|
||||
SelectionGoal::None,
|
||||
)
|
||||
});
|
||||
|
@ -3922,7 +3942,12 @@ impl Editor {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.transact(cx, |this, cx| {
|
||||
this.select_to_beginning_of_line(&SelectToBeginningOfLine(false), cx);
|
||||
this.select_to_beginning_of_line(
|
||||
&SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: false,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
this.backspace(&Backspace, cx);
|
||||
});
|
||||
}
|
||||
|
@ -3935,12 +3960,12 @@ impl Editor {
|
|||
|
||||
pub fn select_to_end_of_line(
|
||||
&mut self,
|
||||
SelectToEndOfLine(stop_at_soft_boundaries): &SelectToEndOfLine,
|
||||
action: &SelectToEndOfLine,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.move_selection_heads(cx, |map, head, _| {
|
||||
(
|
||||
movement::line_end(map, head, *stop_at_soft_boundaries),
|
||||
movement::line_end(map, head, action.stop_at_soft_wraps),
|
||||
SelectionGoal::None,
|
||||
)
|
||||
});
|
||||
|
@ -3948,14 +3973,24 @@ impl Editor {
|
|||
|
||||
pub fn delete_to_end_of_line(&mut self, _: &DeleteToEndOfLine, cx: &mut ViewContext<Self>) {
|
||||
self.transact(cx, |this, cx| {
|
||||
this.select_to_end_of_line(&SelectToEndOfLine(false), cx);
|
||||
this.select_to_end_of_line(
|
||||
&SelectToEndOfLine {
|
||||
stop_at_soft_wraps: false,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
this.delete(&Delete, cx);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn cut_to_end_of_line(&mut self, _: &CutToEndOfLine, cx: &mut ViewContext<Self>) {
|
||||
self.transact(cx, |this, cx| {
|
||||
this.select_to_end_of_line(&SelectToEndOfLine(false), cx);
|
||||
this.select_to_end_of_line(
|
||||
&SelectToEndOfLine {
|
||||
stop_at_soft_wraps: false,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
this.cut(&Cut, cx);
|
||||
});
|
||||
}
|
||||
|
@ -7296,7 +7331,12 @@ mod tests {
|
|||
|
||||
view.update(cx, |view, cx| {
|
||||
view.move_left(&MoveLeft, cx);
|
||||
view.select_to_beginning_of_line(&SelectToBeginningOfLine(true), cx);
|
||||
view.select_to_beginning_of_line(
|
||||
&SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
assert_eq!(
|
||||
view.selected_display_ranges(cx),
|
||||
&[
|
||||
|
@ -7307,7 +7347,12 @@ mod tests {
|
|||
});
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_to_beginning_of_line(&SelectToBeginningOfLine(true), cx);
|
||||
view.select_to_beginning_of_line(
|
||||
&SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
assert_eq!(
|
||||
view.selected_display_ranges(cx),
|
||||
&[
|
||||
|
@ -7318,7 +7363,12 @@ mod tests {
|
|||
});
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_to_beginning_of_line(&SelectToBeginningOfLine(true), cx);
|
||||
view.select_to_beginning_of_line(
|
||||
&SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
assert_eq!(
|
||||
view.selected_display_ranges(cx),
|
||||
&[
|
||||
|
@ -7329,7 +7379,12 @@ mod tests {
|
|||
});
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_to_end_of_line(&SelectToEndOfLine(true), cx);
|
||||
view.select_to_end_of_line(
|
||||
&SelectToEndOfLine {
|
||||
stop_at_soft_wraps: true,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
assert_eq!(
|
||||
view.selected_display_ranges(cx),
|
||||
&[
|
||||
|
|
|
@ -90,7 +90,10 @@ pub struct Open(pub Arc<AppState>);
|
|||
pub struct OpenNew(pub Arc<AppState>);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OpenPaths(pub OpenParams);
|
||||
pub struct OpenPaths {
|
||||
pub paths: Vec<PathBuf>,
|
||||
pub app_state: Arc<AppState>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ToggleFollow(pub PeerId);
|
||||
|
@ -109,7 +112,7 @@ pub fn init(client: &Arc<Client>, cx: &mut MutableAppContext) {
|
|||
|
||||
cx.add_global_action(open);
|
||||
cx.add_global_action(move |action: &OpenPaths, cx: &mut MutableAppContext| {
|
||||
open_paths(&action.0.paths, &action.0.app_state, cx).detach();
|
||||
open_paths(&action.paths, &action.app_state, cx).detach();
|
||||
});
|
||||
cx.add_global_action(move |action: &OpenNew, cx: &mut MutableAppContext| {
|
||||
open_new(&action.0, cx)
|
||||
|
@ -211,12 +214,6 @@ pub struct AppState {
|
|||
) -> Workspace,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OpenParams {
|
||||
pub paths: Vec<PathBuf>,
|
||||
pub app_state: Arc<AppState>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JoinProjectParams {
|
||||
pub project_id: u64,
|
||||
|
@ -2113,9 +2110,9 @@ impl Element for AvatarRibbon {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for OpenParams {
|
||||
impl std::fmt::Debug for OpenPaths {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("OpenParams")
|
||||
f.debug_struct("OpenPaths")
|
||||
.field("paths", &self.paths)
|
||||
.finish()
|
||||
}
|
||||
|
@ -2130,7 +2127,7 @@ fn open(action: &Open, cx: &mut MutableAppContext) {
|
|||
});
|
||||
cx.spawn(|mut cx| async move {
|
||||
if let Some(paths) = paths.recv().await.flatten() {
|
||||
cx.update(|cx| cx.dispatch_global_action(OpenPaths(OpenParams { paths, app_state })));
|
||||
cx.update(|cx| cx.dispatch_global_action(OpenPaths { paths, app_state }));
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
|
|
@ -14,7 +14,7 @@ use smol::process::Command;
|
|||
use std::{env, fs, path::PathBuf, sync::Arc};
|
||||
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use util::ResultExt;
|
||||
use workspace::{self, AppState, OpenNew, OpenParams, OpenPaths};
|
||||
use workspace::{self, AppState, OpenNew, OpenPaths};
|
||||
use zed::{
|
||||
self,
|
||||
assets::Assets,
|
||||
|
@ -158,7 +158,7 @@ fn main() {
|
|||
if paths.is_empty() {
|
||||
cx.dispatch_global_action(OpenNew(app_state.clone()));
|
||||
} else {
|
||||
cx.dispatch_global_action(OpenPaths(OpenParams { paths, app_state }));
|
||||
cx.dispatch_global_action(OpenPaths { paths, app_state });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue