refactor: Remove G/Z Namespace support
This previously enabled things like `d g g` to work, but we can fix that instead by not clearing out pending vim state on change. Either way, it is unnecessary and causes some user-confusion (zed-industries/community#176), so remove this code for now; and use comments to organize the file a bit instead.
This commit is contained in:
parent
35400d5797
commit
8ba69c15d1
5 changed files with 34 additions and 79 deletions
|
@ -2,12 +2,6 @@
|
||||||
{
|
{
|
||||||
"context": "Editor && VimControl && !VimWaiting && !menu",
|
"context": "Editor && VimControl && !VimWaiting && !menu",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"g": [
|
|
||||||
"vim::PushOperator",
|
|
||||||
{
|
|
||||||
"Namespace": "G"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"i": [
|
"i": [
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
{
|
{
|
||||||
|
@ -110,6 +104,30 @@
|
||||||
"*": "vim::MoveToNext",
|
"*": "vim::MoveToNext",
|
||||||
"#": "vim::MoveToPrev",
|
"#": "vim::MoveToPrev",
|
||||||
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
||||||
|
// "g" commands
|
||||||
|
"g g": "vim::StartOfDocument",
|
||||||
|
"g h": "editor::Hover",
|
||||||
|
"g t": "pane::ActivateNextItem",
|
||||||
|
"g shift-t": "pane::ActivatePrevItem",
|
||||||
|
"g d": "editor::GoToDefinition",
|
||||||
|
"g shift-d": "editor::GoToTypeDefinition",
|
||||||
|
"g *": [
|
||||||
|
"vim::MoveToNext",
|
||||||
|
{
|
||||||
|
"partialWord": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g #": [
|
||||||
|
"vim::MoveToPrev",
|
||||||
|
{
|
||||||
|
"partialWord": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// z commands
|
||||||
|
"z t": "editor::ScrollCursorTop",
|
||||||
|
"z z": "editor::ScrollCursorCenter",
|
||||||
|
"z b": "editor::ScrollCursorBottom",
|
||||||
|
// Count support
|
||||||
"1": [
|
"1": [
|
||||||
"vim::Number",
|
"vim::Number",
|
||||||
1
|
1
|
||||||
|
@ -234,12 +252,6 @@
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
"Yank"
|
"Yank"
|
||||||
],
|
],
|
||||||
"z": [
|
|
||||||
"vim::PushOperator",
|
|
||||||
{
|
|
||||||
"Namespace": "Z"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"i": [
|
"i": [
|
||||||
"vim::SwitchMode",
|
"vim::SwitchMode",
|
||||||
"Insert"
|
"Insert"
|
||||||
|
@ -306,29 +318,6 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"context": "Editor && vim_operator == g",
|
|
||||||
"bindings": {
|
|
||||||
"g": "vim::StartOfDocument",
|
|
||||||
"h": "editor::Hover",
|
|
||||||
"t": "pane::ActivateNextItem",
|
|
||||||
"shift-t": "pane::ActivatePrevItem",
|
|
||||||
"d": "editor::GoToDefinition",
|
|
||||||
"shift-d": "editor::GoToTypeDefinition",
|
|
||||||
"*": [
|
|
||||||
"vim::MoveToNext",
|
|
||||||
{
|
|
||||||
"partialWord": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"#": [
|
|
||||||
"vim::MoveToPrev",
|
|
||||||
{
|
|
||||||
"partialWord": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"context": "Editor && vim_operator == c",
|
"context": "Editor && vim_operator == c",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
@ -347,14 +336,6 @@
|
||||||
"y": "vim::CurrentLine"
|
"y": "vim::CurrentLine"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"context": "Editor && vim_operator == z",
|
|
||||||
"bindings": {
|
|
||||||
"t": "editor::ScrollCursorTop",
|
|
||||||
"z": "editor::ScrollCursorCenter",
|
|
||||||
"b": "editor::ScrollCursorBottom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"context": "Editor && VimObject",
|
"context": "Editor && VimObject",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
|
|
@ -127,9 +127,8 @@ pub fn init(cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
|
pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
|
||||||
if let Some(Operator::Namespace(_))
|
if let Some(Operator::FindForward { .. }) | Some(Operator::FindBackward { .. }) =
|
||||||
| Some(Operator::FindForward { .. })
|
Vim::read(cx).active_operator()
|
||||||
| Some(Operator::FindBackward { .. }) = Vim::read(cx).active_operator()
|
|
||||||
{
|
{
|
||||||
Vim::update(cx, |vim, cx| vim.pop_operator(cx));
|
Vim::update(cx, |vim, cx| vim.pop_operator(cx));
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub fn normal_motion(
|
||||||
Some(Operator::Delete) => delete_motion(vim, motion, times, cx),
|
Some(Operator::Delete) => delete_motion(vim, motion, times, cx),
|
||||||
Some(Operator::Yank) => yank_motion(vim, motion, times, cx),
|
Some(Operator::Yank) => yank_motion(vim, motion, times, cx),
|
||||||
Some(operator) => {
|
Some(operator) => {
|
||||||
// Can't do anything for text objects or namespace operators. Ignoring
|
// Can't do anything for text objects, Ignoring
|
||||||
error!("Unexpected normal mode motion operator: {:?}", operator)
|
error!("Unexpected normal mode motion operator: {:?}", operator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,11 +441,8 @@ mod test {
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
state::{
|
state::Mode::{self, *},
|
||||||
Mode::{self, *},
|
test::{ExemptionFeatures, NeovimBackedTestContext},
|
||||||
Namespace, Operator,
|
|
||||||
},
|
|
||||||
test::{ExemptionFeatures, NeovimBackedTestContext, VimTestContext},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
@ -610,22 +607,6 @@ mod test {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
async fn test_g_prefix_and_abort(cx: &mut gpui::TestAppContext) {
|
|
||||||
let mut cx = VimTestContext::new(cx, true).await;
|
|
||||||
|
|
||||||
// Can abort with escape to get back to normal mode
|
|
||||||
cx.simulate_keystroke("g");
|
|
||||||
assert_eq!(cx.mode(), Normal);
|
|
||||||
assert_eq!(
|
|
||||||
cx.active_operator(),
|
|
||||||
Some(Operator::Namespace(Namespace::G))
|
|
||||||
);
|
|
||||||
cx.simulate_keystroke("escape");
|
|
||||||
assert_eq!(cx.mode(), Normal);
|
|
||||||
assert_eq!(cx.active_operator(), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_gg(cx: &mut gpui::TestAppContext) {
|
async fn test_gg(cx: &mut gpui::TestAppContext) {
|
||||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
|
|
@ -16,16 +16,9 @@ impl Default for Mode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
|
|
||||||
pub enum Namespace {
|
|
||||||
G,
|
|
||||||
Z,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
|
||||||
pub enum Operator {
|
pub enum Operator {
|
||||||
Number(usize),
|
Number(usize),
|
||||||
Namespace(Namespace),
|
|
||||||
Change,
|
Change,
|
||||||
Delete,
|
Delete,
|
||||||
Yank,
|
Yank,
|
||||||
|
@ -126,8 +119,6 @@ impl Operator {
|
||||||
pub fn id(&self) -> &'static str {
|
pub fn id(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Operator::Number(_) => "n",
|
Operator::Number(_) => "n",
|
||||||
Operator::Namespace(Namespace::G) => "g",
|
|
||||||
Operator::Namespace(Namespace::Z) => "z",
|
|
||||||
Operator::Object { around: false } => "i",
|
Operator::Object { around: false } => "i",
|
||||||
Operator::Object { around: true } => "a",
|
Operator::Object { around: true } => "a",
|
||||||
Operator::Change => "c",
|
Operator::Change => "c",
|
||||||
|
|
|
@ -14,7 +14,7 @@ use anyhow::Result;
|
||||||
use collections::CommandPaletteFilter;
|
use collections::CommandPaletteFilter;
|
||||||
use editor::{Bias, Editor, EditorMode, Event};
|
use editor::{Bias, Editor, EditorMode, Event};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, impl_actions, keymap_matcher::KeymapContext, AppContext, Subscription, ViewContext,
|
actions, impl_actions,keymap_matcher::MatchResult, keymap_matcher::KeymapContext, AppContext, Subscription, ViewContext,
|
||||||
ViewHandle, WeakViewHandle, WindowContext,
|
ViewHandle, WeakViewHandle, WindowContext,
|
||||||
};
|
};
|
||||||
use language::CursorShape;
|
use language::CursorShape;
|
||||||
|
@ -90,7 +90,10 @@ pub fn init(cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn observe_keystrokes(cx: &mut WindowContext) {
|
pub fn observe_keystrokes(cx: &mut WindowContext) {
|
||||||
cx.observe_keystrokes(|_keystroke, _result, handled_by, cx| {
|
cx.observe_keystrokes(|_keystroke, result, handled_by, cx| {
|
||||||
|
if result == &MatchResult::Pending {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if let Some(handled_by) = handled_by {
|
if let Some(handled_by) = handled_by {
|
||||||
// Keystroke is handled by the vim system, so continue forward
|
// Keystroke is handled by the vim system, so continue forward
|
||||||
if handled_by.namespace() == "vim" {
|
if handled_by.namespace() == "vim" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue