Revert actions! changes
This commit is contained in:
parent
b66b4915cf
commit
c97c9f98c0
15 changed files with 389 additions and 334 deletions
|
@ -1,6 +1,6 @@
|
||||||
use command_palette::CommandInterceptResult;
|
use command_palette::CommandInterceptResult;
|
||||||
use editor::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
|
use editor::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
|
||||||
use gpui::{Action, AppContext};
|
use gpui::{impl_actions, Action, AppContext, ViewContext};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use workspace::{SaveIntent, Workspace};
|
use workspace::{SaveIntent, Workspace};
|
||||||
|
|
||||||
|
@ -15,19 +15,20 @@ use crate::{
|
||||||
Vim,
|
Vim,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Action, Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct GoToLine {
|
pub struct GoToLine {
|
||||||
pub line: u32,
|
pub line: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
impl_actions!(vim, [GoToLine]);
|
||||||
// todo!()
|
|
||||||
// cx.add_action(|_: &mut Workspace, action: &GoToLine, cx| {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// Vim::update(cx, |vim, cx| {
|
workspace.register_action(|_: &mut Workspace, action: &GoToLine, cx| {
|
||||||
// vim.switch_mode(Mode::Normal, false, cx);
|
Vim::update(cx, |vim, cx| {
|
||||||
// move_cursor(vim, Motion::StartOfDocument, Some(action.line as usize), cx);
|
vim.switch_mode(Mode::Normal, false, cx);
|
||||||
// });
|
move_cursor(vim, Motion::StartOfDocument, Some(action.line as usize), cx);
|
||||||
// });
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command_interceptor(mut query: &str, _: &AppContext) -> Option<CommandInterceptResult> {
|
pub fn command_interceptor(mut query: &str, _: &AppContext) -> Option<CommandInterceptResult> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Vim, VimEvent};
|
use crate::Vim;
|
||||||
use editor::{Editor, EditorBlurred, EditorEvent, EditorFocused, EditorReleased};
|
use editor::{Editor, EditorBlurred, EditorEvent, EditorFocused, EditorReleased};
|
||||||
use gpui::{AppContext, Entity, EntityId, View, ViewContext, WindowContext};
|
use gpui::{AppContext, Entity, EntityId, View, ViewContext, WindowContext};
|
||||||
use workspace::item::WeakItemHandle;
|
use workspace::item::WeakItemHandle;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use crate::{normal::repeat, state::Mode, Vim};
|
use crate::{normal::repeat, state::Mode, Vim};
|
||||||
use editor::{scroll::autoscroll::Autoscroll, Bias};
|
use editor::{scroll::autoscroll::Autoscroll, Bias};
|
||||||
use gpui::{actions, Action, AppContext, ViewContext};
|
use gpui::{actions, Action, ViewContext};
|
||||||
use language::SelectionGoal;
|
use language::SelectionGoal;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
actions!(NormalBefore);
|
actions!(vim, [NormalBefore]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(normal_before);
|
||||||
// cx.add_action(normal_before);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normal_before(_: &mut Workspace, action: &NormalBefore, cx: &mut ViewContext<Workspace>) {
|
fn normal_before(_: &mut Workspace, action: &NormalBefore, cx: &mut ViewContext<Workspace>) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use gpui::{div, AnyElement, Div, Element, Entity, IntoElement, Render, Subscript
|
||||||
use settings::{Settings, SettingsStore};
|
use settings::{Settings, SettingsStore};
|
||||||
use workspace::{item::ItemHandle, ui::Label, StatusItemView};
|
use workspace::{item::ItemHandle, ui::Label, StatusItemView};
|
||||||
|
|
||||||
use crate::{state::Mode, Vim, VimEvent, VimModeSetting};
|
use crate::{state::Mode, Vim, VimModeSetting};
|
||||||
|
|
||||||
pub struct ModeIndicator {
|
pub struct ModeIndicator {
|
||||||
pub mode: Option<Mode>,
|
pub mode: Option<Mode>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use editor::{
|
||||||
movement::{self, find_boundary, find_preceding_boundary, FindRange, TextLayoutDetails},
|
movement::{self, find_boundary, find_preceding_boundary, FindRange, TextLayoutDetails},
|
||||||
Bias, CharKind, DisplayPoint, ToOffset,
|
Bias, CharKind, DisplayPoint, ToOffset,
|
||||||
};
|
};
|
||||||
use gpui::{actions, px, Action, AppContext, WindowContext};
|
use gpui::{actions, impl_actions, px, AppContext, ViewContext, WindowContext};
|
||||||
use language::{Point, Selection, SelectionGoal};
|
use language::{Point, Selection, SelectionGoal};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -43,168 +43,194 @@ pub enum Motion {
|
||||||
GoToColumn,
|
GoToColumn,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct NextWordStart {
|
struct NextWordStart {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ignore_punctuation: bool,
|
ignore_punctuation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct NextWordEnd {
|
struct NextWordEnd {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ignore_punctuation: bool,
|
ignore_punctuation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct PreviousWordStart {
|
struct PreviousWordStart {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ignore_punctuation: bool,
|
ignore_punctuation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub(crate) struct Up {
|
pub(crate) struct Up {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(crate) display_lines: bool,
|
pub(crate) display_lines: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Down {
|
struct Down {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
display_lines: bool,
|
display_lines: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct FirstNonWhitespace {
|
struct FirstNonWhitespace {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
display_lines: bool,
|
display_lines: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct EndOfLine {
|
struct EndOfLine {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
display_lines: bool,
|
display_lines: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct StartOfLine {
|
pub struct StartOfLine {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(crate) display_lines: bool,
|
pub(crate) display_lines: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
struct RepeatFind {
|
struct RepeatFind {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
backwards: bool,
|
backwards: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
actions!(
|
impl_actions!(
|
||||||
Left,
|
vim,
|
||||||
Backspace,
|
[
|
||||||
Right,
|
RepeatFind,
|
||||||
CurrentLine,
|
StartOfLine,
|
||||||
StartOfParagraph,
|
EndOfLine,
|
||||||
EndOfParagraph,
|
FirstNonWhitespace,
|
||||||
StartOfDocument,
|
Down,
|
||||||
EndOfDocument,
|
Up,
|
||||||
Matching,
|
PreviousWordStart,
|
||||||
NextLineStart,
|
NextWordEnd,
|
||||||
StartOfLineDownward,
|
NextWordStart
|
||||||
EndOfLineDownward,
|
]
|
||||||
GoToColumn,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
actions!(
|
||||||
// todo!()
|
vim,
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Left, cx: _| motion(Motion::Left, cx));
|
[
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Backspace, cx: _| motion(Motion::Backspace, cx));
|
Left,
|
||||||
// cx.add_action(|_: &mut Workspace, action: &Down, cx: _| {
|
Backspace,
|
||||||
// motion(
|
Right,
|
||||||
// Motion::Down {
|
CurrentLine,
|
||||||
// display_lines: action.display_lines,
|
StartOfParagraph,
|
||||||
// },
|
EndOfParagraph,
|
||||||
// cx,
|
StartOfDocument,
|
||||||
// )
|
EndOfDocument,
|
||||||
// });
|
Matching,
|
||||||
// cx.add_action(|_: &mut Workspace, action: &Up, cx: _| {
|
NextLineStart,
|
||||||
// motion(
|
StartOfLineDownward,
|
||||||
// Motion::Up {
|
EndOfLineDownward,
|
||||||
// display_lines: action.display_lines,
|
GoToColumn,
|
||||||
// },
|
]
|
||||||
// cx,
|
);
|
||||||
// )
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Right, cx: _| motion(Motion::Right, cx));
|
|
||||||
// cx.add_action(|_: &mut Workspace, action: &FirstNonWhitespace, cx: _| {
|
|
||||||
// motion(
|
|
||||||
// Motion::FirstNonWhitespace {
|
|
||||||
// display_lines: action.display_lines,
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, action: &StartOfLine, cx: _| {
|
|
||||||
// motion(
|
|
||||||
// Motion::StartOfLine {
|
|
||||||
// display_lines: action.display_lines,
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, action: &EndOfLine, cx: _| {
|
|
||||||
// motion(
|
|
||||||
// Motion::EndOfLine {
|
|
||||||
// display_lines: action.display_lines,
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &CurrentLine, cx: _| motion(Motion::CurrentLine, cx));
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &StartOfParagraph, cx: _| {
|
|
||||||
// motion(Motion::StartOfParagraph, cx)
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &EndOfParagraph, cx: _| {
|
|
||||||
// motion(Motion::EndOfParagraph, cx)
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &StartOfDocument, cx: _| {
|
|
||||||
// motion(Motion::StartOfDocument, cx)
|
|
||||||
// });
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &EndOfDocument, cx: _| motion(Motion::EndOfDocument, cx));
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Matching, cx: _| motion(Motion::Matching, cx));
|
|
||||||
|
|
||||||
// cx.add_action(
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// |_: &mut Workspace, &NextWordStart { ignore_punctuation }: &NextWordStart, cx: _| {
|
workspace.register_action(|_: &mut Workspace, _: &Left, cx: _| motion(Motion::Left, cx));
|
||||||
// motion(Motion::NextWordStart { ignore_punctuation }, cx)
|
workspace
|
||||||
// },
|
.register_action(|_: &mut Workspace, _: &Backspace, cx: _| motion(Motion::Backspace, cx));
|
||||||
// );
|
workspace.register_action(|_: &mut Workspace, action: &Down, cx: _| {
|
||||||
// cx.add_action(
|
motion(
|
||||||
// |_: &mut Workspace, &NextWordEnd { ignore_punctuation }: &NextWordEnd, cx: _| {
|
Motion::Down {
|
||||||
// motion(Motion::NextWordEnd { ignore_punctuation }, cx)
|
display_lines: action.display_lines,
|
||||||
// },
|
},
|
||||||
// );
|
cx,
|
||||||
// cx.add_action(
|
)
|
||||||
// |_: &mut Workspace,
|
});
|
||||||
// &PreviousWordStart { ignore_punctuation }: &PreviousWordStart,
|
workspace.register_action(|_: &mut Workspace, action: &Up, cx: _| {
|
||||||
// cx: _| { motion(Motion::PreviousWordStart { ignore_punctuation }, cx) },
|
motion(
|
||||||
// );
|
Motion::Up {
|
||||||
// cx.add_action(|_: &mut Workspace, &NextLineStart, cx: _| motion(Motion::NextLineStart, cx));
|
display_lines: action.display_lines,
|
||||||
// cx.add_action(|_: &mut Workspace, &StartOfLineDownward, cx: _| {
|
},
|
||||||
// motion(Motion::StartOfLineDownward, cx)
|
cx,
|
||||||
// });
|
)
|
||||||
// cx.add_action(|_: &mut Workspace, &EndOfLineDownward, cx: _| {
|
});
|
||||||
// motion(Motion::EndOfLineDownward, cx)
|
workspace.register_action(|_: &mut Workspace, _: &Right, cx: _| motion(Motion::Right, cx));
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, action: &FirstNonWhitespace, cx: _| {
|
||||||
// cx.add_action(|_: &mut Workspace, &GoToColumn, cx: _| motion(Motion::GoToColumn, cx));
|
motion(
|
||||||
// cx.add_action(|_: &mut Workspace, action: &RepeatFind, cx: _| {
|
Motion::FirstNonWhitespace {
|
||||||
// repeat_motion(action.backwards, cx)
|
display_lines: action.display_lines,
|
||||||
// })
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, action: &StartOfLine, cx: _| {
|
||||||
|
motion(
|
||||||
|
Motion::StartOfLine {
|
||||||
|
display_lines: action.display_lines,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, action: &EndOfLine, cx: _| {
|
||||||
|
motion(
|
||||||
|
Motion::EndOfLine {
|
||||||
|
display_lines: action.display_lines,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &CurrentLine, cx: _| {
|
||||||
|
motion(Motion::CurrentLine, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &StartOfParagraph, cx: _| {
|
||||||
|
motion(Motion::StartOfParagraph, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &EndOfParagraph, cx: _| {
|
||||||
|
motion(Motion::EndOfParagraph, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &StartOfDocument, cx: _| {
|
||||||
|
motion(Motion::StartOfDocument, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &EndOfDocument, cx: _| {
|
||||||
|
motion(Motion::EndOfDocument, cx)
|
||||||
|
});
|
||||||
|
workspace
|
||||||
|
.register_action(|_: &mut Workspace, _: &Matching, cx: _| motion(Motion::Matching, cx));
|
||||||
|
|
||||||
|
workspace.register_action(
|
||||||
|
|_: &mut Workspace, &NextWordStart { ignore_punctuation }: &NextWordStart, cx: _| {
|
||||||
|
motion(Motion::NextWordStart { ignore_punctuation }, cx)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
workspace.register_action(
|
||||||
|
|_: &mut Workspace, &NextWordEnd { ignore_punctuation }: &NextWordEnd, cx: _| {
|
||||||
|
motion(Motion::NextWordEnd { ignore_punctuation }, cx)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
workspace.register_action(
|
||||||
|
|_: &mut Workspace,
|
||||||
|
&PreviousWordStart { ignore_punctuation }: &PreviousWordStart,
|
||||||
|
cx: _| { motion(Motion::PreviousWordStart { ignore_punctuation }, cx) },
|
||||||
|
);
|
||||||
|
workspace.register_action(|_: &mut Workspace, &NextLineStart, cx: _| {
|
||||||
|
motion(Motion::NextLineStart, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, &StartOfLineDownward, cx: _| {
|
||||||
|
motion(Motion::StartOfLineDownward, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, &EndOfLineDownward, cx: _| {
|
||||||
|
motion(Motion::EndOfLineDownward, cx)
|
||||||
|
});
|
||||||
|
workspace
|
||||||
|
.register_action(|_: &mut Workspace, &GoToColumn, cx: _| motion(Motion::GoToColumn, cx));
|
||||||
|
workspace.register_action(|_: &mut Workspace, action: &RepeatFind, cx: _| {
|
||||||
|
repeat_motion(action.backwards, cx)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
|
pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::{
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use editor::scroll::autoscroll::Autoscroll;
|
use editor::scroll::autoscroll::Autoscroll;
|
||||||
use editor::{Bias, DisplayPoint};
|
use editor::{Bias, DisplayPoint};
|
||||||
use gpui::{actions, AppContext, ViewContext, WindowContext};
|
use gpui::{actions, ViewContext, WindowContext};
|
||||||
use language::SelectionGoal;
|
use language::SelectionGoal;
|
||||||
use log::error;
|
use log::error;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -33,20 +33,23 @@ use self::{
|
||||||
};
|
};
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
InsertAfter,
|
vim,
|
||||||
InsertBefore,
|
[
|
||||||
InsertFirstNonWhitespace,
|
InsertAfter,
|
||||||
InsertEndOfLine,
|
InsertBefore,
|
||||||
InsertLineAbove,
|
InsertFirstNonWhitespace,
|
||||||
InsertLineBelow,
|
InsertEndOfLine,
|
||||||
DeleteLeft,
|
InsertLineAbove,
|
||||||
DeleteRight,
|
InsertLineBelow,
|
||||||
ChangeToEndOfLine,
|
DeleteLeft,
|
||||||
DeleteToEndOfLine,
|
DeleteRight,
|
||||||
Yank,
|
ChangeToEndOfLine,
|
||||||
YankLine,
|
DeleteToEndOfLine,
|
||||||
ChangeCase,
|
Yank,
|
||||||
JoinLines,
|
YankLine,
|
||||||
|
ChangeCase,
|
||||||
|
JoinLines,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
|
@ -123,12 +126,12 @@ pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// paste::init(cx);
|
paste::register(workspace, cx);
|
||||||
// repeat::init(cx);
|
repeat::register(workspace, cx);
|
||||||
// scroll::init(cx);
|
scroll::register(workspace, cx);
|
||||||
// search::init(cx);
|
search::register(workspace, cx);
|
||||||
// substitute::init(cx);
|
substitute::register(workspace, cx);
|
||||||
// increment::init(cx);
|
increment::register(workspace, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normal_motion(
|
pub fn normal_motion(
|
||||||
|
|
|
@ -1,45 +1,46 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use editor::{scroll::autoscroll::Autoscroll, MultiBufferSnapshot, ToOffset, ToPoint};
|
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 language::{Bias, Point};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::{state::Mode, Vim};
|
use crate::{state::Mode, Vim};
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Increment {
|
struct Increment {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
step: bool,
|
step: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Decrement {
|
struct Decrement {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
step: bool,
|
step: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
impl_actions!(vim, [Increment, Decrement]);
|
||||||
// todo!();
|
|
||||||
// cx.add_action(|_: &mut Workspace, action: &Increment, cx| {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// Vim::update(cx, |vim, cx| {
|
workspace.register_action(|_: &mut Workspace, action: &Increment, cx| {
|
||||||
// vim.record_current_action(cx);
|
Vim::update(cx, |vim, cx| {
|
||||||
// let count = vim.take_count(cx).unwrap_or(1);
|
vim.record_current_action(cx);
|
||||||
// let step = if action.step { 1 } else { 0 };
|
let count = vim.take_count(cx).unwrap_or(1);
|
||||||
// increment(vim, count as i32, step, cx)
|
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| {
|
workspace.register_action(|_: &mut Workspace, action: &Decrement, cx| {
|
||||||
// vim.record_current_action(cx);
|
Vim::update(cx, |vim, cx| {
|
||||||
// let count = vim.take_count(cx).unwrap_or(1);
|
vim.record_current_action(cx);
|
||||||
// let step = if action.step { -1 } else { 0 };
|
let count = vim.take_count(cx).unwrap_or(1);
|
||||||
// increment(vim, count as i32 * -1, step, cx)
|
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) {
|
fn increment(vim: &mut Vim, mut delta: i32, step: i32, cx: &mut WindowContext) {
|
||||||
|
|
|
@ -4,14 +4,14 @@ use editor::{
|
||||||
display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, ClipboardSelection,
|
display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, ClipboardSelection,
|
||||||
DisplayPoint,
|
DisplayPoint,
|
||||||
};
|
};
|
||||||
use gpui::{Action, AppContext, ViewContext};
|
use gpui::{impl_actions, ViewContext};
|
||||||
use language::{Bias, SelectionGoal};
|
use language::{Bias, SelectionGoal};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::{state::Mode, utils::copy_selections_content, Vim};
|
use crate::{state::Mode, utils::copy_selections_content, Vim};
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Paste {
|
struct Paste {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
@ -20,9 +20,10 @@ struct Paste {
|
||||||
preserve_clipboard: bool,
|
preserve_clipboard: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn init(cx: &mut AppContext) {
|
impl_actions!(vim, [Paste]);
|
||||||
// todo!()
|
|
||||||
// cx.add_action(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>) {
|
fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
|
||||||
|
|
|
@ -5,10 +5,10 @@ use crate::{
|
||||||
visual::visual_motion,
|
visual::visual_motion,
|
||||||
Vim,
|
Vim,
|
||||||
};
|
};
|
||||||
use gpui::{actions, Action, AppContext, WindowContext};
|
use gpui::{actions, Action, AppContext, ViewContext, WindowContext};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
actions!(Repeat, EndRepeat);
|
actions!(vim, [Repeat, EndRepeat]);
|
||||||
|
|
||||||
fn should_replay(action: &Box<dyn Action>) -> bool {
|
fn should_replay(action: &Box<dyn Action>) -> bool {
|
||||||
// skip so that we don't leave the character palette open
|
// 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) {
|
pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(|_: &mut Workspace, _: &EndRepeat, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &EndRepeat, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
// Vim::update(cx, |vim, cx| {
|
vim.workspace_state.replaying = false;
|
||||||
// vim.workspace_state.replaying = false;
|
vim.switch_mode(Mode::Normal, false, cx)
|
||||||
// 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) {
|
pub(crate) fn repeat(cx: &mut WindowContext, from_insert_mode: bool) {
|
||||||
|
|
|
@ -8,40 +8,42 @@ use gpui::{actions, AppContext, ViewContext};
|
||||||
use language::Bias;
|
use language::Bias;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
actions!(LineUp, LineDown, ScrollUp, ScrollDown, PageUp, PageDown,);
|
actions!(
|
||||||
|
vim,
|
||||||
|
[LineUp, LineDown, ScrollUp, ScrollDown, PageUp, PageDown]
|
||||||
|
);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(|_: &mut Workspace, _: &LineDown, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &LineDown, cx| {
|
scroll(cx, false, |c| ScrollAmount::Line(c.unwrap_or(1.)))
|
||||||
// scroll(cx, false, |c| ScrollAmount::Line(c.unwrap_or(1.)))
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &LineUp, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &LineUp, cx| {
|
scroll(cx, false, |c| ScrollAmount::Line(-c.unwrap_or(1.)))
|
||||||
// scroll(cx, false, |c| ScrollAmount::Line(-c.unwrap_or(1.)))
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &PageDown, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &PageDown, cx| {
|
scroll(cx, false, |c| ScrollAmount::Page(c.unwrap_or(1.)))
|
||||||
// scroll(cx, false, |c| ScrollAmount::Page(c.unwrap_or(1.)))
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &PageUp, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &PageUp, cx| {
|
scroll(cx, false, |c| ScrollAmount::Page(-c.unwrap_or(1.)))
|
||||||
// scroll(cx, false, |c| ScrollAmount::Page(-c.unwrap_or(1.)))
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &ScrollDown, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &ScrollDown, cx| {
|
scroll(cx, true, |c| {
|
||||||
// scroll(cx, true, |c| {
|
if let Some(c) = c {
|
||||||
// if let Some(c) = c {
|
ScrollAmount::Line(c)
|
||||||
// ScrollAmount::Line(c)
|
} else {
|
||||||
// } else {
|
ScrollAmount::Page(0.5)
|
||||||
// ScrollAmount::Page(0.5)
|
}
|
||||||
// }
|
})
|
||||||
// })
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &ScrollUp, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &ScrollUp, cx| {
|
scroll(cx, true, |c| {
|
||||||
// scroll(cx, true, |c| {
|
if let Some(c) = c {
|
||||||
// if let Some(c) = c {
|
ScrollAmount::Line(-c)
|
||||||
// ScrollAmount::Line(-c)
|
} else {
|
||||||
// } else {
|
ScrollAmount::Page(-0.5)
|
||||||
// ScrollAmount::Page(-0.5)
|
}
|
||||||
// }
|
})
|
||||||
// })
|
});
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll(
|
fn scroll(
|
||||||
|
|
|
@ -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 search::{buffer_search, BufferSearchBar, SearchMode, SearchOptions};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use workspace::{searchable::Direction, Pane, Workspace};
|
use workspace::{searchable::Direction, Pane, Workspace};
|
||||||
|
|
||||||
use crate::{motion::Motion, normal::move_cursor, state::SearchState, Vim};
|
use crate::{motion::Motion, normal::move_cursor, state::SearchState, Vim};
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub(crate) struct MoveToNext {
|
pub(crate) struct MoveToNext {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
partial_word: bool,
|
partial_word: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub(crate) struct MoveToPrev {
|
pub(crate) struct MoveToPrev {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
partial_word: bool,
|
partial_word: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
pub(crate) struct Search {
|
pub(crate) struct Search {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
backwards: bool,
|
backwards: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct FindCommand {
|
pub struct FindCommand {
|
||||||
pub query: String,
|
pub query: String,
|
||||||
pub backwards: bool,
|
pub backwards: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct ReplaceCommand {
|
pub struct ReplaceCommand {
|
||||||
pub query: String,
|
pub query: String,
|
||||||
}
|
}
|
||||||
|
@ -44,18 +44,21 @@ struct Replacement {
|
||||||
is_case_sensitive: bool,
|
is_case_sensitive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
actions!(SearchSubmit);
|
actions!(vim, [SearchSubmit]);
|
||||||
|
impl_actions!(
|
||||||
|
vim,
|
||||||
|
[FindCommand, ReplaceCommand, Search, MoveToPrev, MoveToNext]
|
||||||
|
);
|
||||||
|
|
||||||
pub(crate) fn init(cx: &mut AppContext) {
|
pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(move_to_next);
|
||||||
// cx.add_action(move_to_next);
|
workspace.register_action(move_to_prev);
|
||||||
// cx.add_action(move_to_prev);
|
workspace.register_action(search);
|
||||||
// cx.add_action(search);
|
workspace.register_action(search_submit);
|
||||||
// cx.add_action(search_submit);
|
workspace.register_action(search_deploy);
|
||||||
// cx.add_action(search_deploy);
|
|
||||||
|
|
||||||
// cx.add_action(find_command);
|
workspace.register_action(find_command);
|
||||||
// cx.add_action(replace_command);
|
workspace.register_action(replace_command);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_to_next(workspace: &mut Workspace, action: &MoveToNext, cx: &mut ViewContext<Workspace>) {
|
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.
|
// 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());
|
Vim::update(cx, |vim, _| vim.workspace_state.search = Default::default());
|
||||||
cx.propagate();
|
cx.propagate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,31 @@
|
||||||
use editor::movement;
|
use editor::movement;
|
||||||
use gpui::{actions, AppContext, WindowContext};
|
use gpui::{actions, ViewContext, WindowContext};
|
||||||
use language::Point;
|
use language::Point;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::{motion::Motion, utils::copy_selections_content, Mode, Vim};
|
use crate::{motion::Motion, utils::copy_selections_content, Mode, Vim};
|
||||||
|
|
||||||
actions!(Substitute, SubstituteLine);
|
actions!(vim, [Substitute, SubstituteLine]);
|
||||||
|
|
||||||
pub(crate) fn init(cx: &mut AppContext) {
|
pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(|_: &mut Workspace, _: &Substitute, cx| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Substitute, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
// Vim::update(cx, |vim, cx| {
|
vim.start_recording(cx);
|
||||||
// vim.start_recording(cx);
|
let count = vim.take_count(cx);
|
||||||
// let count = vim.take_count(cx);
|
substitute(vim, count, vim.state().mode == Mode::VisualLine, cx);
|
||||||
// substitute(vim, count, vim.state().mode == Mode::VisualLine, cx);
|
})
|
||||||
// })
|
});
|
||||||
// });
|
|
||||||
|
|
||||||
// cx.add_action(|_: &mut Workspace, _: &SubstituteLine, cx| {
|
workspace.register_action(|_: &mut Workspace, _: &SubstituteLine, cx| {
|
||||||
// Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
// vim.start_recording(cx);
|
vim.start_recording(cx);
|
||||||
// if matches!(vim.state().mode, Mode::VisualBlock | Mode::Visual) {
|
if matches!(vim.state().mode, Mode::VisualBlock | Mode::Visual) {
|
||||||
// vim.switch_mode(Mode::VisualLine, false, cx)
|
vim.switch_mode(Mode::VisualLine, false, cx)
|
||||||
// }
|
}
|
||||||
// let count = vim.take_count(cx);
|
let count = vim.take_count(cx);
|
||||||
// substitute(vim, count, true, cx)
|
substitute(vim, count, true, cx)
|
||||||
// })
|
})
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn substitute(vim: &mut Vim, count: Option<usize>, line_mode: bool, cx: &mut WindowContext) {
|
pub fn substitute(vim: &mut Vim, count: Option<usize>, line_mode: bool, cx: &mut WindowContext) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use editor::{
|
||||||
movement::{self, FindRange},
|
movement::{self, FindRange},
|
||||||
Bias, CharKind, DisplayPoint,
|
Bias, CharKind, DisplayPoint,
|
||||||
};
|
};
|
||||||
use gpui::{actions, Action, AppContext, WindowContext};
|
use gpui::{actions, impl_actions, Action, AppContext, ViewContext, WindowContext};
|
||||||
use language::Selection;
|
use language::Selection;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -27,43 +27,59 @@ pub enum Object {
|
||||||
AngleBrackets,
|
AngleBrackets,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Word {
|
struct Word {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ignore_punctuation: bool,
|
ignore_punctuation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_actions!(vim, [Word]);
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
Sentence,
|
vim,
|
||||||
Quotes,
|
[
|
||||||
BackQuotes,
|
Sentence,
|
||||||
DoubleQuotes,
|
Quotes,
|
||||||
VerticalBars,
|
BackQuotes,
|
||||||
Parentheses,
|
DoubleQuotes,
|
||||||
SquareBrackets,
|
VerticalBars,
|
||||||
CurlyBrackets,
|
Parentheses,
|
||||||
AngleBrackets
|
SquareBrackets,
|
||||||
|
CurlyBrackets,
|
||||||
|
AngleBrackets
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(
|
||||||
// cx.add_action(
|
|_: &mut Workspace, &Word { ignore_punctuation }: &Word, cx: _| {
|
||||||
// |_: &mut Workspace, &Word { ignore_punctuation }: &Word, cx: _| {
|
object(Object::Word { ignore_punctuation }, cx)
|
||||||
// object(Object::Word { ignore_punctuation }, cx)
|
},
|
||||||
// },
|
);
|
||||||
// );
|
workspace
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Sentence, cx: _| object(Object::Sentence, cx));
|
.register_action(|_: &mut Workspace, _: &Sentence, cx: _| object(Object::Sentence, cx));
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Quotes, cx: _| object(Object::Quotes, cx));
|
workspace.register_action(|_: &mut Workspace, _: &Quotes, cx: _| object(Object::Quotes, cx));
|
||||||
// cx.add_action(|_: &mut Workspace, _: &BackQuotes, cx: _| object(Object::BackQuotes, cx));
|
workspace
|
||||||
// cx.add_action(|_: &mut Workspace, _: &DoubleQuotes, cx: _| object(Object::DoubleQuotes, cx));
|
.register_action(|_: &mut Workspace, _: &BackQuotes, cx: _| object(Object::BackQuotes, cx));
|
||||||
// cx.add_action(|_: &mut Workspace, _: &Parentheses, cx: _| object(Object::Parentheses, cx));
|
workspace.register_action(|_: &mut Workspace, _: &DoubleQuotes, cx: _| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &SquareBrackets, cx: _| {
|
object(Object::DoubleQuotes, cx)
|
||||||
// object(Object::SquareBrackets, cx)
|
});
|
||||||
// });
|
workspace.register_action(|_: &mut Workspace, _: &Parentheses, cx: _| {
|
||||||
// cx.add_action(|_: &mut Workspace, _: &CurlyBrackets, cx: _| object(Object::CurlyBrackets, cx));
|
object(Object::Parentheses, cx)
|
||||||
// cx.add_action(|_: &mut Workspace, _: &AngleBrackets, cx: _| object(Object::AngleBrackets, cx));
|
});
|
||||||
// cx.add_action(|_: &mut Workspace, _: &VerticalBars, cx: _| object(Object::VerticalBars, cx));
|
workspace.register_action(|_: &mut Workspace, _: &SquareBrackets, cx: _| {
|
||||||
|
object(Object::SquareBrackets, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &CurlyBrackets, cx: _| {
|
||||||
|
object(Object::CurlyBrackets, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &AngleBrackets, cx: _| {
|
||||||
|
object(Object::AngleBrackets, cx)
|
||||||
|
});
|
||||||
|
workspace.register_action(|_: &mut Workspace, _: &VerticalBars, cx: _| {
|
||||||
|
object(Object::VerticalBars, cx)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn object(object: Object, cx: &mut WindowContext) {
|
fn object(object: Object, cx: &mut WindowContext) {
|
||||||
|
|
|
@ -17,8 +17,8 @@ use collections::{CommandPaletteFilter, HashMap};
|
||||||
use command_palette::CommandPaletteInterceptor;
|
use command_palette::CommandPaletteInterceptor;
|
||||||
use editor::{movement, Editor, EditorEvent, EditorMode};
|
use editor::{movement, Editor, EditorEvent, EditorMode};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, Action, AppContext, EntityId, KeyContext, Subscription, View, ViewContext, WeakModel,
|
actions, impl_actions, Action, AppContext, EntityId, KeyContext, Subscription, View,
|
||||||
WeakView, WindowContext,
|
ViewContext, WeakModel, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use language::{CursorShape, Point, Selection, SelectionGoal};
|
use language::{CursorShape, Point, Selection, SelectionGoal};
|
||||||
pub use mode_indicator::ModeIndicator;
|
pub use mode_indicator::ModeIndicator;
|
||||||
|
@ -35,21 +35,23 @@ use crate::state::ReplayableAction;
|
||||||
|
|
||||||
pub struct VimModeSetting(pub bool);
|
pub struct VimModeSetting(pub bool);
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
pub struct SwitchMode(pub Mode);
|
pub struct SwitchMode(pub Mode);
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
pub struct PushOperator(pub Operator);
|
pub struct PushOperator(pub Operator);
|
||||||
|
|
||||||
#[derive(Action, Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
struct Number(usize);
|
struct Number(usize);
|
||||||
|
|
||||||
actions!(Tab, Enter, Object, InnerObject, FindForward, FindBackward,);
|
actions!(
|
||||||
|
vim,
|
||||||
|
[Tab, Enter, Object, InnerObject, FindForward, FindBackward]
|
||||||
|
);
|
||||||
|
// in the workspace namespace so it's not filtered out when vim is disabled.
|
||||||
|
actions!(workspace, [ToggleVimMode]);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
impl_actions!(vim, [SwitchMode, PushOperator, Number]);
|
||||||
enum VimEvent {
|
|
||||||
ModeChanged { mode: Mode },
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.set_global(Vim::default());
|
cx.set_global(Vim::default());
|
||||||
|
@ -60,12 +62,6 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.observe_new_views(|workspace: &mut Workspace, cx| register(workspace, cx))
|
cx.observe_new_views(|workspace: &mut Workspace, cx| register(workspace, cx))
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
visual::init(cx);
|
|
||||||
insert::init(cx);
|
|
||||||
object::init(cx);
|
|
||||||
motion::init(cx);
|
|
||||||
command::init(cx);
|
|
||||||
|
|
||||||
// Any time settings change, update vim mode to match. The Vim struct
|
// Any time settings change, update vim mode to match. The Vim struct
|
||||||
// will be initialized as disabled by default, so we filter its commands
|
// will be initialized as disabled by default, so we filter its commands
|
||||||
// out when starting up.
|
// out when starting up.
|
||||||
|
@ -104,17 +100,20 @@ fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
Vim::active_editor_input_ignored("\n".into(), cx)
|
Vim::active_editor_input_ignored("\n".into(), cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
workspace.register_action(
|
workspace.register_action(|workspace: &mut Workspace, _: &ToggleVimMode, cx| {
|
||||||
|workspace: &mut Workspace, _: &workspace::ToggleVimMode, cx| {
|
let fs = workspace.app_state().fs.clone();
|
||||||
let fs = workspace.app_state().fs.clone();
|
let currently_enabled = VimModeSetting::get_global(cx).0;
|
||||||
let currently_enabled = VimModeSetting::get_global(cx).0;
|
update_settings_file::<VimModeSetting>(fs, cx, move |setting| {
|
||||||
update_settings_file::<VimModeSetting>(fs, cx, move |setting| {
|
*setting = Some(!currently_enabled)
|
||||||
*setting = Some(!currently_enabled)
|
})
|
||||||
})
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
normal::register(workspace, cx)
|
normal::register(workspace, cx);
|
||||||
|
insert::register(workspace, cx);
|
||||||
|
motion::register(workspace, cx);
|
||||||
|
command::register(workspace, cx);
|
||||||
|
object::register(workspace, cx);
|
||||||
|
visual::register(workspace, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn observe_keystrokes(cx: &mut WindowContext) {
|
pub fn observe_keystrokes(cx: &mut WindowContext) {
|
||||||
|
|
|
@ -21,35 +21,41 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
ToggleVisual,
|
vim,
|
||||||
ToggleVisualLine,
|
[
|
||||||
ToggleVisualBlock,
|
ToggleVisual,
|
||||||
VisualDelete,
|
ToggleVisualLine,
|
||||||
VisualYank,
|
ToggleVisualBlock,
|
||||||
OtherEnd,
|
VisualDelete,
|
||||||
SelectNext,
|
VisualYank,
|
||||||
SelectPrevious,
|
OtherEnd,
|
||||||
|
SelectNext,
|
||||||
|
SelectPrevious,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
// todo!()
|
workspace.register_action(|_, _: &ToggleVisual, cx: &mut ViewContext<Workspace>| {
|
||||||
// cx.add_action(|_, _: &ToggleVisual, cx: &mut ViewContext<Workspace>| {
|
toggle_mode(Mode::Visual, cx)
|
||||||
// toggle_mode(Mode::Visual, cx)
|
});
|
||||||
// });
|
workspace.register_action(|_, _: &ToggleVisualLine, cx: &mut ViewContext<Workspace>| {
|
||||||
// cx.add_action(|_, _: &ToggleVisualLine, cx: &mut ViewContext<Workspace>| {
|
toggle_mode(Mode::VisualLine, cx)
|
||||||
// toggle_mode(Mode::VisualLine, cx)
|
});
|
||||||
// });
|
workspace.register_action(
|
||||||
// cx.add_action(
|
|_, _: &ToggleVisualBlock, cx: &mut ViewContext<Workspace>| {
|
||||||
// |_, _: &ToggleVisualBlock, cx: &mut ViewContext<Workspace>| {
|
toggle_mode(Mode::VisualBlock, cx)
|
||||||
// toggle_mode(Mode::VisualBlock, cx)
|
},
|
||||||
// },
|
);
|
||||||
// );
|
workspace.register_action(other_end);
|
||||||
// cx.add_action(other_end);
|
workspace.register_action(delete);
|
||||||
// cx.add_action(delete);
|
workspace.register_action(yank);
|
||||||
// cx.add_action(yank);
|
|
||||||
|
|
||||||
// cx.add_action(select_next);
|
workspace.register_action(|workspace, action, cx| {
|
||||||
// cx.add_action(select_previous);
|
select_next(workspace, action, cx).ok();
|
||||||
|
});
|
||||||
|
workspace.register_action(|workspace, action, cx| {
|
||||||
|
select_previous(workspace, action, cx).ok();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visual_motion(motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
|
pub fn visual_motion(motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue