From 2cf48c03f9977dd1c292957c7538d7bc12b40944 Mon Sep 17 00:00:00 2001 From: Kay Simmons Date: Thu, 8 Dec 2022 14:39:48 -0800 Subject: [PATCH] fix final failing tests --- assets/keymaps/vim.json | 38 ++++++++---------- crates/editor/src/editor.rs | 53 +++++++++++++++---------- crates/editor/src/items.rs | 2 +- crates/vim/src/normal/change.rs | 1 - crates/vim/src/test/vim_test_context.rs | 3 +- crates/vim/src/vim.rs | 6 +-- 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json index 5cdd4fc7d4..99c94798db 100644 --- a/assets/keymaps/vim.json +++ b/assets/keymaps/vim.json @@ -8,6 +8,22 @@ "Namespace": "G" } ], + "i": [ + "vim::PushOperator", + { + "Object": { + "around": false + } + } + ], + "a": [ + "vim::PushOperator", + { + "Object": { + "around": true + } + } + ], "h": "vim::Left", "backspace": "vim::Backspace", "j": "vim::Down", @@ -77,28 +93,6 @@ ] } }, - { - //Operators - "context": "Editor && VimControl && vim_operator == none", - "bindings": { - "i": [ - "vim::PushOperator", - { - "Object": { - "around": false - } - } - ], - "a": [ - "vim::PushOperator", - { - "Object": { - "around": true - } - } - ] - } - }, { "context": "Editor && vim_mode == normal && vim_operator == none", "bindings": { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 1aee1e246d..417b60bc5b 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3709,18 +3709,30 @@ impl Editor { }) } - pub fn move_page_up(&mut self, action: &MovePageUp, cx: &mut ViewContext) -> Option<()> { - self.take_rename(true, cx)?; - if self.context_menu.as_mut()?.select_first(cx) { - return None; + pub fn move_page_up(&mut self, action: &MovePageUp, cx: &mut ViewContext) { + if self.take_rename(true, cx).is_some() { + return; + } + + if self + .context_menu + .as_mut() + .map(|menu| menu.select_first(cx)) + .unwrap_or(false) + { + return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate_action(); - return None; + return; } - let row_count = self.visible_line_count()? as u32 - 1; + let row_count = if let Some(row_count) = self.visible_line_count() { + row_count as u32 - 1 + } else { + return; + }; let autoscroll = if action.center_cursor { Autoscroll::center() @@ -3739,8 +3751,6 @@ impl Editor { selection.collapse_to(cursor, goal); }); }); - - Some(()) } pub fn select_up(&mut self, _: &SelectUp, cx: &mut ViewContext) { @@ -3775,25 +3785,30 @@ impl Editor { }); } - pub fn move_page_down( - &mut self, - action: &MovePageDown, - cx: &mut ViewContext, - ) -> Option<()> { + pub fn move_page_down(&mut self, action: &MovePageDown, cx: &mut ViewContext) { if self.take_rename(true, cx).is_some() { - return None; + return; } - if self.context_menu.as_mut()?.select_last(cx) { - return None; + if self + .context_menu + .as_mut() + .map(|menu| menu.select_last(cx)) + .unwrap_or(false) + { + return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate_action(); - return None; + return; } - let row_count = self.visible_line_count()? as u32 - 1; + let row_count = if let Some(row_count) = self.visible_line_count() { + row_count as u32 - 1 + } else { + return; + }; let autoscroll = if action.center_cursor { Autoscroll::center() @@ -3812,8 +3827,6 @@ impl Editor { selection.collapse_to(cursor, goal); }); }); - - Some(()) } pub fn select_down(&mut self, _: &SelectDown, cx: &mut ViewContext) { diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 73008ca720..0efce57d5f 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -300,7 +300,7 @@ impl Item for Editor { false } else { let nav_history = self.nav_history.take(); - self.set_scroll_anchor(data.scroll_anchor, cx); + self.set_scroll_anchor(scroll_anchor, cx); self.change_selections(Some(Autoscroll::fit()), cx, |s| { s.select_ranges([offset..offset]) }); diff --git a/crates/vim/src/normal/change.rs b/crates/vim/src/normal/change.rs index a32888f59e..ca372801c7 100644 --- a/crates/vim/src/normal/change.rs +++ b/crates/vim/src/normal/change.rs @@ -200,7 +200,6 @@ mod test { Test test ˇtest"}) .await; - println!("Marker"); cx.assert(indoc! {" Test test ˇ diff --git a/crates/vim/src/test/vim_test_context.rs b/crates/vim/src/test/vim_test_context.rs index e0d972896f..723dac0581 100644 --- a/crates/vim/src/test/vim_test_context.rs +++ b/crates/vim/src/test/vim_test_context.rs @@ -51,8 +51,9 @@ impl<'a> VimTestContext<'a> { ) }); - // Setup search toolbars + // Setup search toolbars and keypress hook workspace.update(cx, |workspace, cx| { + observe_keypresses(window_id, cx); workspace.active_pane().update(cx, |pane, cx| { pane.toolbar().update(cx, |toolbar, cx| { let buffer_search_bar = cx.add_view(BufferSearchBar::new); diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 4121d6f4bb..898886714e 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -81,20 +81,20 @@ pub fn init(cx: &mut MutableAppContext) { .detach(); } -// Any keystrokes not mapped to vim should clar the active operator +// Any keystrokes not mapped to vim should clear the active operator pub fn observe_keypresses(window_id: usize, cx: &mut MutableAppContext) { cx.observe_keystrokes(window_id, |_keystroke, _result, handled_by, cx| { dbg!(_keystroke); - dbg!(_result); if let Some(handled_by) = handled_by { - dbg!(handled_by.name()); if handled_by.namespace() == "vim" { + println!("Vim action. Don't clear"); return true; } } Vim::update(cx, |vim, cx| { if vim.active_operator().is_some() { + println!("Clearing operator"); vim.clear_operator(cx); } });