Revert actions! changes

This commit is contained in:
Conrad Irwin 2023-12-11 10:19:03 -07:00
parent b66b4915cf
commit c97c9f98c0
15 changed files with 389 additions and 334 deletions

View file

@ -1,45 +1,46 @@
use std::ops::Range;
use editor::{scroll::autoscroll::Autoscroll, MultiBufferSnapshot, ToOffset, ToPoint};
use gpui::{Action, AppContext, WindowContext};
use gpui::{impl_actions, AppContext, ViewContext, WindowContext};
use language::{Bias, Point};
use serde::Deserialize;
use workspace::Workspace;
use crate::{state::Mode, Vim};
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Increment {
#[serde(default)]
step: bool,
}
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Decrement {
#[serde(default)]
step: bool,
}
pub fn init(cx: &mut AppContext) {
// todo!();
// cx.add_action(|_: &mut Workspace, action: &Increment, cx| {
// Vim::update(cx, |vim, cx| {
// vim.record_current_action(cx);
// let count = vim.take_count(cx).unwrap_or(1);
// let step = if action.step { 1 } else { 0 };
// increment(vim, count as i32, step, cx)
// })
// });
// cx.add_action(|_: &mut Workspace, action: &Decrement, cx| {
// Vim::update(cx, |vim, cx| {
// vim.record_current_action(cx);
// let count = vim.take_count(cx).unwrap_or(1);
// let step = if action.step { -1 } else { 0 };
// increment(vim, count as i32 * -1, step, cx)
// })
// });
impl_actions!(vim, [Increment, Decrement]);
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
workspace.register_action(|_: &mut Workspace, action: &Increment, cx| {
Vim::update(cx, |vim, cx| {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let step = if action.step { 1 } else { 0 };
increment(vim, count as i32, step, cx)
})
});
workspace.register_action(|_: &mut Workspace, action: &Decrement, cx| {
Vim::update(cx, |vim, cx| {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let step = if action.step { -1 } else { 0 };
increment(vim, count as i32 * -1, step, cx)
})
});
}
fn increment(vim: &mut Vim, mut delta: i32, step: i32, cx: &mut WindowContext) {

View file

@ -4,14 +4,14 @@ use editor::{
display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, ClipboardSelection,
DisplayPoint,
};
use gpui::{Action, AppContext, ViewContext};
use gpui::{impl_actions, ViewContext};
use language::{Bias, SelectionGoal};
use serde::Deserialize;
use workspace::Workspace;
use crate::{state::Mode, utils::copy_selections_content, Vim};
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Paste {
#[serde(default)]
@ -20,9 +20,10 @@ struct Paste {
preserve_clipboard: bool,
}
pub(crate) fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(paste);
impl_actions!(vim, [Paste]);
pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
workspace.register_action(paste);
}
fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {

View file

@ -5,10 +5,10 @@ use crate::{
visual::visual_motion,
Vim,
};
use gpui::{actions, Action, AppContext, WindowContext};
use gpui::{actions, Action, AppContext, ViewContext, WindowContext};
use workspace::Workspace;
actions!(Repeat, EndRepeat);
actions!(vim, [Repeat, EndRepeat]);
fn should_replay(action: &Box<dyn Action>) -> bool {
// skip so that we don't leave the character palette open
@ -39,16 +39,15 @@ fn repeatable_insert(action: &ReplayableAction) -> Option<Box<dyn Action>> {
}
}
pub(crate) fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(|_: &mut Workspace, _: &EndRepeat, cx| {
// Vim::update(cx, |vim, cx| {
// vim.workspace_state.replaying = false;
// vim.switch_mode(Mode::Normal, false, cx)
// });
// });
pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
workspace.register_action(|_: &mut Workspace, _: &EndRepeat, cx| {
Vim::update(cx, |vim, cx| {
vim.workspace_state.replaying = false;
vim.switch_mode(Mode::Normal, false, cx)
});
});
// cx.add_action(|_: &mut Workspace, _: &Repeat, cx| repeat(cx, false));
workspace.register_action(|_: &mut Workspace, _: &Repeat, cx| repeat(cx, false));
}
pub(crate) fn repeat(cx: &mut WindowContext, from_insert_mode: bool) {

View file

@ -8,40 +8,42 @@ use gpui::{actions, AppContext, ViewContext};
use language::Bias;
use workspace::Workspace;
actions!(LineUp, LineDown, ScrollUp, ScrollDown, PageUp, PageDown,);
actions!(
vim,
[LineUp, LineDown, ScrollUp, ScrollDown, PageUp, PageDown]
);
pub fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(|_: &mut Workspace, _: &LineDown, cx| {
// scroll(cx, false, |c| ScrollAmount::Line(c.unwrap_or(1.)))
// });
// cx.add_action(|_: &mut Workspace, _: &LineUp, cx| {
// scroll(cx, false, |c| ScrollAmount::Line(-c.unwrap_or(1.)))
// });
// cx.add_action(|_: &mut Workspace, _: &PageDown, cx| {
// scroll(cx, false, |c| ScrollAmount::Page(c.unwrap_or(1.)))
// });
// cx.add_action(|_: &mut Workspace, _: &PageUp, cx| {
// scroll(cx, false, |c| ScrollAmount::Page(-c.unwrap_or(1.)))
// });
// cx.add_action(|_: &mut Workspace, _: &ScrollDown, cx| {
// scroll(cx, true, |c| {
// if let Some(c) = c {
// ScrollAmount::Line(c)
// } else {
// ScrollAmount::Page(0.5)
// }
// })
// });
// cx.add_action(|_: &mut Workspace, _: &ScrollUp, cx| {
// scroll(cx, true, |c| {
// if let Some(c) = c {
// ScrollAmount::Line(-c)
// } else {
// ScrollAmount::Page(-0.5)
// }
// })
// });
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
workspace.register_action(|_: &mut Workspace, _: &LineDown, cx| {
scroll(cx, false, |c| ScrollAmount::Line(c.unwrap_or(1.)))
});
workspace.register_action(|_: &mut Workspace, _: &LineUp, cx| {
scroll(cx, false, |c| ScrollAmount::Line(-c.unwrap_or(1.)))
});
workspace.register_action(|_: &mut Workspace, _: &PageDown, cx| {
scroll(cx, false, |c| ScrollAmount::Page(c.unwrap_or(1.)))
});
workspace.register_action(|_: &mut Workspace, _: &PageUp, cx| {
scroll(cx, false, |c| ScrollAmount::Page(-c.unwrap_or(1.)))
});
workspace.register_action(|_: &mut Workspace, _: &ScrollDown, cx| {
scroll(cx, true, |c| {
if let Some(c) = c {
ScrollAmount::Line(c)
} else {
ScrollAmount::Page(0.5)
}
})
});
workspace.register_action(|_: &mut Workspace, _: &ScrollUp, cx| {
scroll(cx, true, |c| {
if let Some(c) = c {
ScrollAmount::Line(-c)
} else {
ScrollAmount::Page(-0.5)
}
})
});
}
fn scroll(

View file

@ -1,37 +1,37 @@
use gpui::{actions, Action, AppContext, ViewContext};
use gpui::{actions, impl_actions, Action, AppContext, ViewContext};
use search::{buffer_search, BufferSearchBar, SearchMode, SearchOptions};
use serde_derive::Deserialize;
use workspace::{searchable::Direction, Pane, Workspace};
use crate::{motion::Motion, normal::move_cursor, state::SearchState, Vim};
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub(crate) struct MoveToNext {
#[serde(default)]
partial_word: bool,
}
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub(crate) struct MoveToPrev {
#[serde(default)]
partial_word: bool,
}
#[derive(Action, Clone, Deserialize, PartialEq)]
#[derive(Clone, Deserialize, PartialEq)]
pub(crate) struct Search {
#[serde(default)]
backwards: bool,
}
#[derive(Action, Debug, Clone, PartialEq, Deserialize)]
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct FindCommand {
pub query: String,
pub backwards: bool,
}
#[derive(Action, Debug, Clone, PartialEq, Deserialize)]
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct ReplaceCommand {
pub query: String,
}
@ -44,18 +44,21 @@ struct Replacement {
is_case_sensitive: bool,
}
actions!(SearchSubmit);
actions!(vim, [SearchSubmit]);
impl_actions!(
vim,
[FindCommand, ReplaceCommand, Search, MoveToPrev, MoveToNext]
);
pub(crate) fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(move_to_next);
// cx.add_action(move_to_prev);
// cx.add_action(search);
// cx.add_action(search_submit);
// cx.add_action(search_deploy);
pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
workspace.register_action(move_to_next);
workspace.register_action(move_to_prev);
workspace.register_action(search);
workspace.register_action(search_submit);
workspace.register_action(search_deploy);
// cx.add_action(find_command);
// cx.add_action(replace_command);
workspace.register_action(find_command);
workspace.register_action(replace_command);
}
fn move_to_next(workspace: &mut Workspace, action: &MoveToNext, cx: &mut ViewContext<Workspace>) {
@ -103,7 +106,7 @@ fn search(workspace: &mut Workspace, action: &Search, cx: &mut ViewContext<Works
}
// hook into the existing to clear out any vim search state on cmd+f or edit -> find.
fn search_deploy(_: &mut Pane, _: &buffer_search::Deploy, cx: &mut ViewContext<Pane>) {
fn search_deploy(_: &mut Workspace, _: &buffer_search::Deploy, cx: &mut ViewContext<Workspace>) {
Vim::update(cx, |vim, _| vim.workspace_state.search = Default::default());
cx.propagate();
}

View file

@ -1,32 +1,31 @@
use editor::movement;
use gpui::{actions, AppContext, WindowContext};
use gpui::{actions, ViewContext, WindowContext};
use language::Point;
use workspace::Workspace;
use crate::{motion::Motion, utils::copy_selections_content, Mode, Vim};
actions!(Substitute, SubstituteLine);
actions!(vim, [Substitute, SubstituteLine]);
pub(crate) fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(|_: &mut Workspace, _: &Substitute, cx| {
// Vim::update(cx, |vim, cx| {
// vim.start_recording(cx);
// let count = vim.take_count(cx);
// substitute(vim, count, vim.state().mode == Mode::VisualLine, cx);
// })
// });
pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
workspace.register_action(|_: &mut Workspace, _: &Substitute, cx| {
Vim::update(cx, |vim, cx| {
vim.start_recording(cx);
let count = vim.take_count(cx);
substitute(vim, count, vim.state().mode == Mode::VisualLine, cx);
})
});
// cx.add_action(|_: &mut Workspace, _: &SubstituteLine, cx| {
// Vim::update(cx, |vim, cx| {
// vim.start_recording(cx);
// if matches!(vim.state().mode, Mode::VisualBlock | Mode::Visual) {
// vim.switch_mode(Mode::VisualLine, false, cx)
// }
// let count = vim.take_count(cx);
// substitute(vim, count, true, cx)
// })
// });
workspace.register_action(|_: &mut Workspace, _: &SubstituteLine, cx| {
Vim::update(cx, |vim, cx| {
vim.start_recording(cx);
if matches!(vim.state().mode, Mode::VisualBlock | Mode::Visual) {
vim.switch_mode(Mode::VisualLine, false, cx)
}
let count = vim.take_count(cx);
substitute(vim, count, true, cx)
})
});
}
pub fn substitute(vim: &mut Vim, count: Option<usize>, line_mode: bool, cx: &mut WindowContext) {