vim: Downgrade user config error from panic to log (#42070)

Lukas Wirth created

Fixes ZED-2W3

Release Notes:

- Fixed panic due to invalid vim keycap

Change summary

crates/vim/src/digraph.rs | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

Detailed changes

crates/vim/src/digraph.rs 🔗

@@ -63,18 +63,22 @@ impl Vim {
     }
 
     fn literal(&mut self, action: &Literal, window: &mut Window, cx: &mut Context<Self>) {
-        if let Some(Operator::Literal { prefix }) = self.active_operator()
-            && let Some(prefix) = prefix
-        {
-            if let Some(keystroke) = Keystroke::parse(&action.0).ok() {
-                window.defer(cx, |window, cx| {
-                    window.dispatch_keystroke(keystroke, cx);
-                });
+        match self.active_operator() {
+            Some(Operator::Literal {
+                prefix: Some(prefix),
+            }) => {
+                if let Some(keystroke) = Keystroke::parse(&action.0).ok() {
+                    window.defer(cx, |window, cx| {
+                        window.dispatch_keystroke(keystroke, cx);
+                    });
+                }
+                return self.handle_literal_input(prefix, "", window, cx);
             }
-            return self.handle_literal_input(prefix, "", window, cx);
+            Some(_) => self.insert_literal(Some(action.1), "", window, cx),
+            None => log::error!(
+                "Literal called when no operator was on the stack. This likely means there is an invalid keymap config"
+            ),
         }
-
-        self.insert_literal(Some(action.1), "", window, cx);
     }
 
     pub fn handle_literal_keystroke(