This commit is contained in:
Nathan Sobo 2021-08-22 13:29:54 -06:00
parent 24639ec900
commit 638b533fc7
4 changed files with 312 additions and 304 deletions

View File

@ -132,7 +132,7 @@ impl AnyAction for () {
#[macro_export]
macro_rules! action {
($name:ident, $arg:ty) => {
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug)]
pub struct $name(pub $arg);
impl $crate::Action for $name {
@ -3677,13 +3677,13 @@ mod tests {
});
let actions_clone = actions.clone();
cx.add_action(move |view: &mut ViewB, action: &Action, cx| {
cx.add_action(move |view: &mut ViewB, _: &Action, cx| {
cx.propagate_action();
actions_clone.borrow_mut().push(format!("{} c", view.id));
});
let actions_clone = actions.clone();
cx.add_action(move |view: &mut ViewB, action: &Action, cx| {
cx.add_action(move |view: &mut ViewB, _: &Action, cx| {
cx.propagate_action();
actions_clone.borrow_mut().push(format!("{} d", view.id));
});

View File

@ -419,6 +419,13 @@ mod tests {
action!(B);
action!(Ab);
impl PartialEq for A {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Eq for A {}
#[derive(Clone, Debug, Eq, PartialEq)]
struct ActionArg {
a: &'static str,
@ -465,7 +472,7 @@ mod tests {
}
impl Matcher {
fn test_keystroke<A: Action>(
fn test_keystroke<A: Action + Eq>(
&mut self,
keystroke: &str,
view_id: usize,

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
use super::{DisplayPoint, Editor, SelectPhase, Snapshot};
use super::{DisplayPoint, Editor, Select, SelectPhase, Snapshot, Insert, Scroll};
use crate::time::ReplicaId;
use gpui::{
color::Color,
@ -55,7 +55,7 @@ impl EditorElement {
if paint.text_bounds.contains_point(position) {
let snapshot = self.snapshot(cx.app);
let position = paint.point_for_position(&snapshot, layout, position);
cx.dispatch_action("buffer:select", SelectPhase::Begin { position, add: cmd });
cx.dispatch_action(Select(SelectPhase::Begin { position, add: cmd }));
true
} else {
false
@ -64,7 +64,7 @@ impl EditorElement {
fn mouse_up(&self, _position: Vector2F, cx: &mut EventContext) -> bool {
if self.view(cx.app.as_ref()).is_selecting() {
cx.dispatch_action("buffer:select", SelectPhase::End);
cx.dispatch_action(Select(SelectPhase::End));
true
} else {
false
@ -113,16 +113,13 @@ impl EditorElement {
let snapshot = self.snapshot(cx.app);
let position = paint.point_for_position(&snapshot, layout, position);
cx.dispatch_action(
"buffer:select",
SelectPhase::Update {
position,
scroll_position: (snapshot.scroll_position() + scroll_delta).clamp(
Vector2F::zero(),
layout.scroll_max(&font_cache, &text_layout_cache),
),
},
);
cx.dispatch_action(Select(SelectPhase::Update {
position,
scroll_position: (snapshot.scroll_position() + scroll_delta).clamp(
Vector2F::zero(),
layout.scroll_max(&font_cache, &text_layout_cache),
),
}));
true
} else {
false
@ -139,7 +136,7 @@ impl EditorElement {
if chars.chars().any(|c| c.is_control()) {
false
} else {
cx.dispatch_action("buffer:insert", chars.to_string());
cx.dispatch_action(Insert(chars.to_string()));
true
}
}
@ -177,7 +174,7 @@ impl EditorElement {
layout.scroll_max(font_cache, layout_cache),
);
cx.dispatch_action("buffer:scroll", scroll_position);
cx.dispatch_action(Scroll(scroll_position));
true
}