copilot: Propagate action if suggest_next is not possible. (#3129)

Piotr Osiewicz created

One of our users ran into an issue where typing "true quote" characters
(option-[ for „ and option-] for ‚) was not possible; I've narrowed it
down to a collision with Copilot's NextSuggestion and PreviousSuggestion
action default keybinds. I explicitly did not want to alter the key
bindings, so I've went with a more neutral fix - one that propagates the
keystroke if there's no Copilot action to be taken (user is not using
Copilot etc). Note however that typing true quotes while using a Copilot
is still not possible, as for that we'd have to change a keybind.

Fixes zed-industries/community#2072


Release Notes:
- Fixed Copilot's "Suggest next" and "Suggest previous" actions
colliding with true quotes key bindings (`option-[` and `option-]`). The
keystrokes are now propagated if there's no Copilot action to be taken
at cursor's position.

Change summary

crates/editor/src/editor.rs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -4158,7 +4158,10 @@ impl Editor {
         if self.has_active_copilot_suggestion(cx) {
             self.cycle_copilot_suggestions(Direction::Next, cx);
         } else {
-            self.refresh_copilot_suggestions(false, cx);
+            let is_copilot_disabled = self.refresh_copilot_suggestions(false, cx).is_none();
+            if is_copilot_disabled {
+                cx.propagate_action();
+            }
         }
     }
 
@@ -4170,7 +4173,10 @@ impl Editor {
         if self.has_active_copilot_suggestion(cx) {
             self.cycle_copilot_suggestions(Direction::Prev, cx);
         } else {
-            self.refresh_copilot_suggestions(false, cx);
+            let is_copilot_disabled = self.refresh_copilot_suggestions(false, cx).is_none();
+            if is_copilot_disabled {
+                cx.propagate_action();
+            }
         }
     }